After Optional.orElseThrow(),"userInfo" is not nullable

Please provide

  • Operating system:
  • SonarLint plugin version:
  • Programming language you’re coding in: Java 8
  • Is connected mode used:
    • Connected to SonarCloud or SonarQube (and which version):

And a thorough description of the problem / question:

cusFeedback.setPhoneNumber(Optional.ofNullable(userInfo).orElseThrow(() -> new FsnException(Result.USER_NOT_EXISTS)).getPhone());


rule id :java:S2259


I believe that the first line has already checked whether userInfo is null , and if it is null , an exception will be thrown. Therefore, the subsequent userInfo.getName() should not throw an exception.

Hey there.

I’ve moved your post to the section on reporting a false-positive.

Please review this post and add additional information, particularly a text-based reproducer, not a screenshot.

Okay, I have added the text code snippet。