powered by Jive Software

False FindBugs positive JCIP_FIELD_ISNT_FINAL_IN_IMMUTABLE_CLASS ?


#1

Hello,

In the last few months, I’ve repeatedly attempted to sent the message below to the FindBugs mailinglist. For some reason, it doesn’t appear to arrive there. I’m not seeing the message pop up in the message archive, nor do I get a bounce. I do notice other activity on the mailinglist, which does appear in the archive. Something must be off - I’m not sure what, but perhaps a spam filter doesn’t quite like me. Alternatively, I’ve posted my text here on IgniteRealtime, to which I will link in another, short email I will (attempt to) send to the maillinglist.

FindBugs reports something that I believe to be a false positive. I am using the Eclipse plugin of FindBugs. It’s version is 1.3.9.20090821. Eclipse’s version is 3.4.2. My platform is Windows XP, running the JRE provided by Suns jdk1.6.0_11.

My code uses the annotations defined by Goetz in “Java Concurrency In Practice.” One of my classes (called JID) has the @Immutable annotation. FindBugs reports a problem in this class.

The class uses a map (several, actually), that is using generics:

private static final ConcurrentMap<String, ValueWrapper<String>> NODEPREP_CACHE = // etc...

The ValueWrapper class (which also has @Immutable) contains an enum definition, like this:

@Immutable
public class ValueWrapper<V> implements Serializable {     public enum Representation { /*..*/ };     /*..*/
}

FindBugs (through the Eclipse plugin) reports this problem (It reports this bug on the first line of the JID class):

JID.$SWITCH_TABLE$org$xmpp$util$ValueWrapper$Representation should be final since org.xmpp.packet.JID is marked as Immutable.

FindBugs details state:

Bug: JID.$SWITCH_TABLE$org$xmpp$util$ValueWrapper$Representation should be final since org.xmpp.packet.JID is marked as Immutable.

Pattern id: JCIP_FIELD_ISNT_FINAL_IN_IMMUTABLE_CLASS, type: JCIP, category: BAD_PRACTICE

The class is annotated with net.jcip.annotations.Immutable, and the rules for that annotation require that all fields are final.

Representation is not a field of the ValueWrapper class. Making it final to improve immutability makes not a lot of sense to me, which is why I suspect a bug in the pattern detection.

The complete code of the project is publicly available through a subversion repository. It can be accessed via http://svn.igniterealtime.org/svn/repos/tinder/ (alternatively, there is a nicer webviewer available at http://www.igniterealtime.org/fisheye/viewrep/svn-org/tinder). I currently have checked out revision 11328, in which FindBugs reports the problem.

Regards,

Guus


#2

Success! An email linking to this discussion has come through on the mailinglist!

https://mailman.cs.umd.edu/pipermail/findbugs-discuss/2010-January/003006.html


#3

After some nosing around in the repository browser, I suspect that the problem that I described earlier is caused by the enum definition being passed as a field to the visit() method of the CheckImmutableAnnotation class. The enum cannot be final (it implicitly is), which causes the check to fail.