FP java:S2259 reports possible NPE for unboxing a Boolean that is not null

  • SonarQube Community Build v25.10.0.114319
  • Java Code
  • Rule S2259 Null pointers should not be dereferenced

S2259 reports an issue for the the following Java code:

package org.example;
import edu.umd.cs.findbugs.annotations.Nullable;

public class S2259BooleanNullability {
  boolean test(@Nullable Boolean value) {
    return value != null && value;
  }
}

It reports ‘A “NullPointerException” could be thrown; “value” is nullable here.’ for the right-hand side of the expression, even though it has been checked before with value != null.

I’ve attached the above source as minimal maven project.

test.zip (1.9 KB)

Best
Andreas

Hi Andreas,

Welcome to the community and thanks for this report!

It looks like you’re hitting

SONARJAVA-5361 FP on S2259 due to previous condition

I’ll let the team know we have another example.

 
Ann

1 Like