Details
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
- implements
-
RSPEC-109 Magic numbers should not be used
- Active
- is related to
-
SONARJAVA-1079 S109 - Magic Numbers: add an "authorized numbers" parameter
-
- Closed
-