A "NullPointerException" could be thrown; "context" is nullable here

12,317

SonarQube claims that context may be null here. If you know this is incorrect, you could just suppress this warning as a false positive. Otherwise, you should explicitly check if context is not null:

if (result instanceof AsyncResult && context != null) {
    // Here -------------------------^

    // Make sure handle async has been called
    context.handleAsync();
    Result newResult = context.controllerReturned();
    if (newResult != null) {
        result = newResult;
    }
}
Share:
12,317
P. Lisi
Author by

P. Lisi

Updated on June 04, 2022

Comments

  • P. Lisi
    P. Lisi almost 2 years

    So I have an issue with SonarQube that I can not solve.

    if (result instanceof AsyncResult) {
        // Make sure handle async has been called
        context.handleAsync();
        Result newResult = context.controllerReturned();
        if (newResult != null) {
            result = newResult;
        }
     }
    
    • zerocewl
      zerocewl over 5 years
      Where is the context variable initialized?
    • akash
      akash over 5 years
      SonarQube is saying that it's possible that context can be null because it couldn't find any initialization to it. Do you want to ignore such errors?
  • P. Lisi
    P. Lisi over 5 years
    I solved by inserting Objects before context. Is it correct this way? Can you tell me the meaning?