Search code examples
javaenumssonarqubemagic-numbers

SonarQube: Should magic numbers be allowed in java constructor enums


Concerning rule squid: S109 Magic numbers should not be used

Shouldn't it be allowed to have numbers in the constructor of an enum in java? The code below shouldn't violate the rule in my opinion.

public enum Color{
   RED(42),
   GREEN(123456),
   BLUE(666);

   public final int code;

   Color(int colorCode){
      this.code=colorCode;
   }    
}

I'm using Sonar java plugin version 3.3


Solution

  • It will be fixed in version 3.4

    See this issue on SonarSource : http://jira.sonarsource.com/browse/SONARJAVA-1117