Ternary seems to trick up SonarQube's optional.isPresent() check

java
false-positive

(Charlie Hayes) #1

This Java code:
return value.isPresent() ? Maybe.just(value.get()) : fetchAndReturn();
results in:
Optional value should only be accessed after calling isPresent()

It should not.

Version 6.7.3 (build 38370)


(Nicolas Peru) #2

Hi @Charlie_Hayes, could you let us know which version of SonarJava is installed on your sonarqube instance ?


(Charlie Hayes) #3

SonarJava version 5.10.1 (build 16922)


(Elena Vilchik) #4

@Charlie_Hayes I can not reproduce. Could you provide a full code reproducer? (with declarations)