Menu

#1385 @Nullable gives false positive "method tightens nullness annotation on parameter"

3.x
closed-rejected
nobody
None
1
2017-10-22
2015-05-21
No

For the following code:

import javax.annotation.Nullable;

class Foo {
  public boolean equals(@Nullable Object o) {
    return this == o;
  }
}

FindBugs gives the error:

NP_METHOD_PARAMETER_TIGHTENS_ANNOTATION
Method tightens nullness annotation on parameter

If I understand @Nullable correctly, it should never be a tightening annotation, as unannotated parameters are implicitly nullable.

This is particularly an issue when the @Nullable annotation is there to undo a @ParametersAreNonnullByDefault annotation.

Discussion

  • Aaron Sheldon

    Aaron Sheldon - 2015-10-14

    This bug interacts with https://sourceforge.net/p/findbugs/feature-requests/191/

    Code auto-generators, like the Java Immutables project (http://immutables.github.io/), generate equals() annotated with @Nullable which is a false positive in Findbugs.

     
  • Scott Kennedy

    Scott Kennedy - 2016-12-10

    This is causing me some issues.

    First of all, it's wrong. It's loosening the annotation, not tightening it. Second, loosening a method parameter annotation is perfectly acceptable.

    On the other hand, loosening a return value is not (but tightening is).

     
  • Andrey Loskutov

    Andrey Loskutov - 2017-10-22
    • Status: open --> closed-rejected
     

Log in to post a comment.