NullPointerException warning

Please provide

  • Operating system: Zorin OS 18.04
  • SonarLint plugin version:
  • Is connected mode used: no

And a thorough description of the problem / question:

public class RestException extends Exception {
  public static RestException invalidRefNumber() throws RestException {
    throw new RestException(1, "Invalid Reference number");
public class Service{
  public void func(){
    if (agent == null)

    if (!agent.getStatus().equals(AppUserStatus.ACTIVE))

Agent object will not be null because if it is null, throws exception before running it

Hello @Muhammadyoqub,

Thanks for the report. Indeed this is a false positive. Currently, this rule does not support tracking the execution across different files (as invalidRefNumber() is not in the same file as func()).

We are aware of this shortcoming, however, unfortunately, I cannot currently give you an ETA as to when we may be able to address it.

If you were using SonarQube or SonarCloud to back SonarLint in connected mode, you could mark this issue as ‘false positive’, making it disappear. However, you write that you are not using SonarLint in connected mode, in which case you could use annotations instead (see Java | SonarQube Docs, section “Turning issues off”). If you have a lot of false positives due to this rule you could disable it in the SonarLint settings, however, that obviously also means you will not be getting legitimate findings thanks to this rule.

Hope that helps!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.