First of all I’m using SonarLint plugin v4.0.2.3009 with IntelliJ Ultimate and I have this tiny snippet of code:
if (!exampleOpt.isPresent()) {
// do something useful
return;
}
Example example = exampleOpt.get();
SonarLint creates an issue for not simplifying the if-condition to “exampleOpt.isEmpty()”. If I change this, the call to Optional.get() afterwards creates an issue for calling get() without a preceeding call to isPresent(). So either way, if at runtime the get() call is reached, one can be sure the Optional is not Empty so it’s safe to call get(). How can I get SonarLint to recognize this and not creating false-positive issues out of this?