Suppressing Java Findbugs error (EI_EXPOSE_REP)

前端 未结 2 737
忘掉有多难
忘掉有多难 2021-01-18 07:44

I have a Java gettor method that looks like the following:

import java.util.Date;
//...
public Date getSomeDate() {
  return someDate;
}

an

相关标签:
2条回答
  • 2021-01-18 08:30

    No,we need to clone that object using below code :

    public Date getSomeDate() {
      return new Date(someDate.getTime()).clone();
    }
    
    0 讨论(0)
  • 2021-01-18 08:45

    I just realized that Findbugs analyzes compiled code (.class files), not source code. After rebuilding and re-running Findbugs, the problem went away.

    0 讨论(0)
提交回复
热议问题