- SonarQube Community Build v25.10.0.114319
- Java Code using JSpecify
I’m not sure which rule would be responsible to detect this issue. Maybe “java:S4449 Nullness of parameters should be guaranteed”?
If a NullMarked class overrides a method of a class that does not specify nullness, then method parameters cannot considered to be non-null. They should be annotated as Nullable or maybe NullUnmarked, IIUC.
The following code does not generate an issue:
package org.example;
import org.jspecify.annotations.NullMarked;
@NullMarked
public class OverrideEqualsNonNullParameter {
@Override
public boolean equals(Object obj) { // FN: parameter must be annotated as Nullable
return super.equals(obj);
}
@Override
public int hashCode() {
return super.hashCode();
}
}
I’ve attached the above source as minimal maven project:
test.zip (1.9 KB)
Note, that the JSpecify’s Reference Checker detects this and outputs an error like
error: [nullness] Incompatible parameter type for object.
public boolean equals(Object object) {
^
found : Object
required: Object?
Cheers
Andreas