java:S2259 A "NullPointerException" could be thrown; False Positive

Language: Java 17
Rule: java:S2259 A “NullPointerException” could be thrown;
False positive (it is checked for not null in the same line of code)
Product: SonarQube 10.1

public void method1(Boolean isDemo) {
  if (isDemo != null && isDemo) {
       //do something here

The rule assumes correctly that isDemo is nullable(from first condition inside if), but then it complaints that it is dereferenced in the second condition.

Hello Sebastian,

Thank you for your report.

Unfortunately, I have not been able to reproduce this issue with the information you have provided so far. This rule uses symbolic execution to perform a data flow analysis and can be affected by seemingly unrelated code close by.

Could you provide a reproducer that includes the entire file’s code and where you can trigger the issue on your side? You can provide this here, or, even better, you can provide the link to a project on e.g. GitHub.

In the meantime, if the rule causes too much noise, you can opt to disable it until the problem has been fixed.