Invalid "NullPointerException" rule S2259

Version: SonarLint for Eclipse

Here is the culprit

dblClickAction can be null, but if it is and rec.getNodeDblclikActionType() != null then it will be assigned a value.

The next block checks that rec.getNodeDblclikActionType() != null, which was the condition that guaranteed that dblClickAction would be assigned a value.

I understand that the 2nd if block could have used dblClickAction instead, but AFAICT we still have a false positive.

Hi @Alain_Picard

When you read this code I guess you assume the result of rec.getNodeDblclickActionType() will be the same at line 592 and 596. But if the object is mutable, and in a multi-threaded context, this might not be correct.
If you want to make your code multi-threaded safe, you should store the result of rec.getNodeDblclickActionType() in a local variable and use it in the two locations.

1 Like


You’re right, even though here it is not multi-threaded. Maybe instead of “Will be null” message should read “Could be null”.

@alban.auzeill is it something we could improve on the Java analyzer side?