Detect usage of null parameter in Java?

Total newbie question here. I’m evaluating SonarLint v1.20.1 using Java and the VS Code extension. I was expecting that it would flag this as a possible null deference on value, but no warning is given.

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

I am getting warnings about other issues so SL is running and finding useful things, Am I expecting too much here or is this just a misconfiguration or misunderstanding on my part?

Thanks!

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.