Menu

#1181 Potential problems with null not analyzed using @Nullable annotations

2.0.3
closed-rejected
nobody
5
2013-05-28
2013-05-10
No

Hi,

I am trying to use findbugs for analysis of potential problems with null values. I am using the javax.annotation.Nullable annotation and I am annotating methods that are allowed to return null. I am also annotating method parameters that take null values.
Methods and method parameters are @Nonnull by default (using annotations on the package).
I've put together a test project which shows where I would expect findbugs to issue warnings.
In essence, I think that findbugs should consider the @Nullable annotation for a method and issue a warning when the caller uses the result to call a method on it since it might dereference null.
I am also expecting a warning when a potential null value will be passed as a parameter to a method that is @Nonnull.

Is the current behavior a bug or just not implemented?

I am running eclipe 3.6 with JRE 6 an findbugs 2.0.2.20121204

Thank, Thomas

1 Attachments

Discussion

  • William Pugh

    William Pugh - 2013-05-28

    The problem is the distinction between @Nullable and @CheckForNull.

    @Nullable means the value could be null under some circumstances, but that warnings shouldn't be generated for dereferences not proceeded by a null check.

    @CheckForNull means that the value could be null and should be null checked before being dereferenced. A dereference without a null check will generate a warning.

    If the method return values are annotated with @CheckForNull, it will work as you are expecting. I added a test case: sfBugsNew/Bug1181, to demonstrate this.

     
  • William Pugh

    William Pugh - 2013-05-28
    • labels: --> false negative
    • status: open --> closed-rejected
     
  • Thomas Hofmann

    Thomas Hofmann - 2013-05-28

    Thanks William, I changed to @CheckForNull in the test case. It works like I expected (at least at first glance). I will check some real code the next days. One thing to mention is that the @Nullable annotation needs to be removed for the checks to take effect. Having both will not trigger a warning.
    I will post back here in case I have some follow on questions. Thanks again.

    Thomas

     

Log in to post a comment.

MongoDB Logo MongoDB