squid:S3655 (Optional value should only be accessed after calling isPresent()) being fired even though control will never reach the optional.get() call

We’re using SonarQube server Version 6.7.5 (build 38563). With default settings & the sonar-way quality profile.

We have a lot of code like this:

Optional<SomeClass> optional = ...

if (optional.isEmpty()) {
     throw new Exception("Error");

var value = optional.get();

This triggers S3655 every time & we have to mark it as a false positive. From this topic I see that this PR was supposed to fix this issue. But from the examples in the PR I think that the case where control flow is interrupted due to the isEmpty() check is missed.

Is there any workaround for this? Or a planned fix?



What is the sonarjava version used to reproduce this issue ?
This is likely to have been fixed by : https://jira.sonarsource.com/browse/SONARJAVA-3087 since version 5.12.1

Hi @Nicolas_Peru,

I found that this case is still happening in our Sonarqube even we updated the version higher to 5.12.1. So i have created a “help” ticket recently. Can you reproduce this problem too?

SonarQube & relevant plugin version:

  • SonarQube Developer edition, the version is
  • SonarJava version is 5.14 (build 18788)

Since an other thread for a similar issue was created, I’m closing this one, please continue the discussion there if you still face issue.