#1105 @DefaultAnnotation(NonNull.class) now affects primitives


We rely heavily on DefaultAnnotation (mainly for non-null defaults) in our code, which was perfectly acceptable in the 1.3.9 version of FB that we were using. Now, however, I realize it is deprecated, but in upgrading to 2.0.1 we noticed that it is behaving differently.

Our specific case is that it now seems to apply the Nonnull-ness to primitive class members, and reports NP_NONNULL_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR if we leave the primitive uninitialized. This is typical of Java code where you do not want to set your boolean class members to false or ints to 0 (zero) because that is redundant.

Primitives cannot be null anyway, so this is a bit of a misapplication. If we wanted to flag uninitialized primitive class members it would probably be better to have a separate detector (and thus category) for this.

I realize that a work-around is to stop using the DefaultAnnotation. However, this means that for every class member, method and method parameter where we want to enforce a non-null rule, we now have to annotate each one individually (right???). That is really a harsh penalty, and besides, deprecation should mean "still working but going away soon".

Test case below (which actually shows 2 bugs - this one and the static initializer bug #3547559:

import edu.umd.cs.findbugs.annotations.DefaultAnnotation;
import edu.umd.cs.findbugs.annotations.NonNull;

public class FBTest {
public static final String constant = "constant";

public static final Integer constantInt = Integer.valueOf\(5\);

private boolean x;

public boolean isX\(\) \{
    return x;

public void setX\(boolean x\) \{
    this.x = x;



  • William Pugh

    William Pugh - 2012-09-27

    fixed. thank you.

  • William Pugh

    William Pugh - 2012-09-27
    • status: open --> closed-fixed

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks