Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Suppressing Java Findbugs error (EI_EXPOSE_REP)

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

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

and Findbugs reports that this exposes a mutable object: "May expose internal representation by returning reference to mutable object". I changed the code to this:

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

but Findbug still reports the same vulnerability. What more can I do to suppress/fix this problem? I am running Findbugs 1.3.9 in the IntellJ 10 Findbugs plugin.

like image 896
Ralph Avatar asked Mar 29 '11 12:03

Ralph


1 Answers

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

like image 61
Ralph Avatar answered Sep 21 '22 09:09

Ralph