Uploaded image for project: 'SonarJava'
  1. SonarJava
  2. SONARJAVA-4172

S6206 should not report on non-final classes

    XMLWordPrintable

    Details

    • Type: False-Positive
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 7.12
    • Component/s: Rules

      Description

      As records cannot be extended, suggesting changing a class to a record might break the build. 

      public class A { // Compliant as it is inherited from
          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);
          }
      }
      

      Because it is difficult for the analyzer to determine that a class is never inherited from, S6206 should only report on classes that are marked explicitly as final.

      public class NonFinal { // Compliant as it could potentially be inherited from
          private final int i;
      
          public NonFinal(final int i) {
              this.i = i;
          }
      
          public int getI() {
              return i;
          }
      }
      
      public final class DefinitelyFinal { // Noncompliant
          private final int i;
      
          public DefinitelyFinal(final int i) {
              this.i = i;
          }
      
          public int getI() {
              return i;
          }
      }
      
      

        Attachments

          Activity

            People

            Assignee:
            chrislain.razafimahefa Chrislain Razafimahefa
            Reporter:
            dorian.burihabwa Dorian Burihabwa
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: