Have you tried to analyse your project with the last version of SonarJava ?
I did so and could not trigger the rule with your code (i checked that the rule is active in my QP).
The FP was originally triggered on sonarcloud.io - I can’t check the version there as I don’t have the rights; instead I ran it against our local Sonar installation (SonarJava 5.4 build 14284 installed) , and that doesn’t seem to report it as a problem, so it does sound like it was a False-False-Positive
SonarCloud is always running the latest and greatest features we’ve developed here. If you catch a false-positive in SonarCloud, then it likely needs to further looked into (independently of past behaviour). Provided you’ve executed the analysis as recommended of course, for example making sure that code is built and bytecode available to analysis (make sure there’s no related warning in your logs).
If you’ve got a minimal reproducer, then an ideal course of action would be to analyse it in a public project in SonarCloud, so that we can access/review the code/issue directly in SonarCloud.
Ah, apologies again. My reproduction was wrong, taking a look at the original issue refreshed my mind. A proper reproducer is as follow:
final Optional<String> possibleLong = Optional.empty();
try {
possibleLong.map(Long::valueOf).ifPresent(number -> System.out.println("The value is " + number));
} catch (final NumberFormatException ignored) {
System.out.println(possibleLong.get() + " is not a valid number");
}
(Aside; FWIW, IntelliJ does the “right thing” and does not report the call to possibleLong.get() as being possibly invalid)