Make sure to read this post before raising a thread here:
Environment
SonarQube Server: Data Center Edition, v2026.5.2 (132813)
SonarQube for IntelliJ: 13.0.0
IntelliJ IDEA: 2026.1.2
JDK: Amazon Corretto 25 (sonar.java.source=25)
Rule:
javabugs:S3655 — Optional value should only be accessed after calling isPresent()
Problem Optional.get() on an instance field, with no isPresent()/isEmpty() check, is not raised as S3655. IntelliJ’s built-in inspection (“Optional.get() is called without isPresent() check”) does flag the field case.
In our code the field is a JPA entity attribute populated through an AttributeConverter that returns Optional.empty() for null/zero column values, so this throws NoSuchElementException in production paths.
Snippet:
import java.math.BigDecimal;
import java.util.Optional;
public class S3655Reproducer {
private Optional<BigDecimal> value;
// Not Raised
public long notRaised() {
return value.get().longValue();
}
// Raised
public long raised() {
Optional<BigDecimal> o = Optional.empty();
return o.get().longValue();
}
}
Expected:
Both raise a S3655. IntelliJ shows both as “Optional.get() without isPresent() check”
Actual:
Only raised() has the S3655 attached.
If this is intended behavior, please consider this a request for a rule or option that reports unchecked .get()'s on Optionals like IntelliJ does.
In SonarQube Server 2026.5.2 we changed the behaviour of rule S3655.
Specifically, our previous version was raising an issue every time get is
called without a previous check for presence of a value (with isPresent); this
was noisy, thus we moved to an approach where the issue is only raised if the
analyzer has collected enough evidence that the optional has no value inside.
In your example, inside the body of raised, o is definitely empty, thus
the analyzer can conclude that o.get() will fail. On the contrary, in notRaised it is not known whether value is empty or not, thus the analyzer
will not raise to avoid reporting a false positive.
For example, if notRaised were called on a path where value is certainly
empty it would raise an issue. You can see this by adding the function forceEmptyAndCall which calls notRaised after setting value to empty:
public void forceEmptyAndCall() {
this.value = Optional.empty();
long x = notRaised();
}
However it is not entirely possible to judge your case as caller(s) of notRaised are not present in your reproducer. If indeed you are in a situation
like forceEmptyAndCall where value is certainly empty then the issue should
be raised.
In our situation, the analyzer doesn’t have enough context because they are Optional values being mapped to JPA models (reasoning is sound). The analyzer will never know if those columns in the database are null, so it’ll never show for S3655.
This is fine, if that’s the intended purpose. My ask then becomes an option for a louder and more aggressive check that we can turn on that would mimic the old behavior.