Do not report 'convert to record'for classes that are extended from

False positive: Records should be used instead of ordinary classes when representing immutable data structure (S6206)

SonarLint plugin for IntelliJ 6.4.3.42541 connected to SonarCloud.io project

A Java class cannot extend a record, as records are final classes. Sonar still reports that the superclass should be converted to a record.

minimal example:

public class A {
    private final int i;

    public A(final int i) {
        this.i = i;
    }

    public int getI() {
        return i;
    }
}

public class B extends A {
    public B(final int j) {
        super(j);
    }
}

SonarLint reports a major Code Smell about converting class A to a record, which would be valid if class B did not extend A.

1 Like

Hey @kistlers ,
Thank you for reporting this. While it is easy for our analyzer to find the classes A inherits from, it is not possible, at acceptable cost, to get all child classes.

As a lot of developers moving to more recent versions of Java are likely to hit the same issue, I created a ticket to limit the scope to classes that are marked as final.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.