False positive NPC java:S2259

  • Operating system: Windows 11
  • SonarLint plugin version:
  • Programming language you’re coding in: Java
  • Is connected mode used: False
    • Connected to SonarCloud or SonarQube (and which version):

And a thorough description of the problem / question:

SonarLint: ‘senderTeam’ is dereferenced.
SonarLint: A “NullPointerException” could be thrown; “senderTeam” is nullable here.

‘senderTeam’ cannot be null, as I am already checking its nullity with ‘warningKey’. If it is null, ‘warningKey’ is set, leading to the return statement before any operations on ‘senderTeam’ are executed.


Welcome to the community and thanks for this report!

The way I read this code, if game.getMode() == GameMode.SOLO then that’s the branch in the if-tree that gets taken, and you’ll never check senderTeam’s nullability.


But then warningKey is set, and the code won’t reach senderTeam.getPlayers() without checking if it’s null first.

Zrzut ekranu 2024-02-21 191931


Yeah. Okay. :sweat_smile:

Flagging this for the language experts.


Hi @xeRicker,

Thank you for reporting.

I tried reproducing the problem, but it seems the issue is not raising.
Can you please provide me with a minimal reproducer so I can investigate where is the problem?

All the best,