SonarLint for Eclipse 7.7 standalone, Language Java gives a false positive for S2259:
public enum S2259Enum {
ENUM_A,
ENUM_B;
public String getOptionString(S2259Enum select) {
StringBuilder res = new StringBuilder();
for (S2259Enum typ : S2259Enum.values()) {
if (select == typ || (typ == ENUM_A && select == null)) {
res.append("<option value=\"")
.append(typ.name()) // S2259 occurs here
.append("\" selected>")
.append(typ.toString())
.append("</option>");
} else {
res.append("<option value=\"")
.append(typ.name())
.append("\">")
.append(typ.toString())
.append("</option>");
}
}
return res.toString();
}
}
The parameter typ cannot be null, because it is always an instance of the enum S2259Enum. The analyzer might think it can be null because the two OR-cases in the if-Clause imply that select might be null and therefore, typ might also be null. But: If select ist null then typ cannot be null (has to be ENUM_A) and the first OR-Clause does not evaluate to true.