Detect usage of null parameter in Java?

Hi Jason, and welcome to our community,

Raising possible NPE issues on all method calls not having an explicit null check would be super annoying and noisy. A lot of code in Java implicitly assume method parameters are not null.

SonarLint will only report an issue when it has good enough indication that the de-referenced variable can be null.

Try:

  String someFunction(String value) {
    if (value == null) {
      return value.trim();
    }
    return value;
  }

or (using JSR 305 annotations)

  String someFunction(@Nullable String value) {
    return value.trim();
  }

You should then see issue reported.