- Language: Java 25
- Rule: javabugs:S2259 - A NULL object should not be accessed
- Version: SonarQube Server, Developer Edition, v2026.5 (132435)
- Cannot reproduce with SonarQube for IDE
- Why is it a False-Positive: Because from looking at the code, the object cannot be null. Additionally, other tools don’t report it as an error nor did SQ report it in the past either.
Hello, similar to False positive javabugs:S2259 — null checks performed by methods from external libraries are ignored , but instead of the method originating from an external library, it originates from the same project.
public class MyClass1 {
private Object object;
public final Object getLazyObject() {
if (object == null) {
object = new Object();
}
return object;
}
}
public class MyClass2 {
private final MyClass1 class1;
public MyClass2(final MyClass1 class1) {
this.class1 = class1;
}
static void main() {
new MyClass2(new MyClass1()).test();
}
private void test() {
final String string = class1.getLazyObject().toString(); // reports: javabugs:S2259 - Fix this access that will throw a NullPointerException when executed.
System.out.println(string);
}
}
I will try to trim the example down even further. I will edit/post updates if I reproduce it with a more trimmed down version.


