All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sonar.l10n.java.rules.squid.S2637.html Maven / Gradle / Ivy

There is a newer version: 8.6.0.37351
Show newest version

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 NullPointerExceptions 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