S2259 - FP with Java Enums

SonarQube :
SonarLint : (connected to our SonarQube server)
Intellij IDEA : 2023.2.3

Language: Java 11

Rule: java:S2259 Null pointers should not be dereferenced

When I have Java Method in which I test with β€œ==”, if a local variable of an Java Enum type, which can be null, is of a certain Enum value and if this is not the case and I then call the name() function of the static Enum value I used in the test before, the rule java:S2259 raises an issue.

Minimal code to reproduce:

public class TestS2559
   enum MyEnum

   public String someMethod()
      MyEnum myEnum = null;
      if (myEnum == MyEnum.DEV)
         return  MyEnum.DEV.name();
      return "";


In Intellij the SonarLint plugin shows the following Issue:

Obviously there is a flaw which leads to the assumption that β€œMyEnum.DEV” can be null, which is definitely not the case.

This might be related to another False-Positive report I published here:

S2259 - FP with static fields in an interface

Within the answer to that topic, there is a reference to SonarJava Issue (https://sonarsource.atlassian.net/browse/SONARJAVA-3691) which is obviously not resolved.

Hi @tschindler,

Thank you for reporting.

As soon as we can work on it, we will. From your side, you can mark this as FP and track progress in the ticket you referenced.
In the meantime, you can Try Now Developer Edition with the Sonar Dataflow Bug Detection analyzer.

All the best,


Hi @irina.batinic

thank you for your quick response!

Best regards

1 Like