org.sonar.l10n.java.rules.squid.S2637.html Maven / Gradle / Ivy
Fields, parameters and return values marked @NotNull
, @NonNull
, or @Nonnull
are assumed to have
non-null values and are not typically null-checked before use. Therefore setting one of these values to null, or failing to set
such a class field in a constructor, could cause NullPointerException
s at runtime.
It is quite likely that the code does not match the programmer's intent.
Noncompliant Code Examples
public class Fruit {
@NotNull
private Season ripe;
private String color;
public Fruit() { // Noncompliant; ripe is left null
}
public void setColor(@NotNull String color) {
this.color = color;
}
public @NotNull Integer getProtein() {
return null; // Noncompliant
}
}
public class MyClass {
public void doSomething() {
Fruit fruit = new Fruit();
fruit.setColor(null); // Noncompliant
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy