False Positive S6207 on overridden getter of record

  • What language is this for?
    • Java
  • Which rule?
    • S6207
  • Why do you believe it’s a false-positive?
    • Description does not match my code.
  • Are you using
    • SonarQube Community Build - 9.9.4
  • 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.

Hi,

Welcome to the community!

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.

Your update path is:

9.9.4 → 24.12 → 26.1

You may find these resources helpful:

If you have questions about upgrading, feel free to open a new thread for that here.

If your error persists after update, please come back to us.

 
Ann

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.

1 Like

Hi,

Thanks for reproducing on a current system! I’ve flagged this for the language experts.

 
Ann

Hey there, we have an existing ticket for relaxing this rule in record constructors like the one you shared. Here is the ticket

I’ve added a mention to this thread and bumped the priority, hopefully we will get to work on it soon, thanks for the report!