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

S109 should not consider as magic number final (but not static) fields with initialization

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 3.6
    • Component/s: Rules
    • Labels:
      None

      Description

      The rule should not consider as magic number the final fields and variables having an initialization. As they are final, they are technically constants and therefore not magic. However, such fields will always raise an issue for rule S1170 (Public constants and fields initialized at declaration should be "static final" rather than merely "final").

      class A {
        final int myConst = 0; // Compliant for S109, but Noncompliant for S1170
      
        void method() {
          final int foo = 42; // Compliant for S109, but Noncompliant for S1170
        }
      }
      

      Original thread from SQ google group: https://groups.google.com/d/msgid/sonarqube/80cc068b-c412-43ba-8a87-f5d08cb6203e%40googlegroups.com

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              michael.gumowski Michael Gumowski
              Reporter:
              michael.gumowski Michael Gumowski
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Due:
                Created:
                Updated:
                Resolved: