How can we reproduce the problem? Give us a self-contained snippet of code
@ConfigurationProperties(prefix = "feature")
public record IceCreamToggle(boolean enabled, String flavor) {
@Override
public String flavor() {
Validate.validState(enabled, "Flavor can only be used when feature is enabled");
return flavor;
}
}
Context: My Spring Boot app has a feature toggle whose value is loaded into a record. For convenience, a related value is loaded into the record as well, but it should only be used when the feature is active. To provide a concise error message, instead of an NPE somewhere, I override the “getter” of the flavor property. Sonarqube falsely flags this as a redundant method. The method is not redundant however, as removing it would change the behavior.
Only the latest version of SonarQube Community Build is considered active, so you’ll need to update and see if the situation is still replicable before we can help you.
I’m afraid I cannot update that server, but I can reproduce my finding with “SonarQube for IDE” (on Android Studio Otter 3 Feature Drop | 2025.2.3) connected with SonarQube Cloud.