Java - Visibility of an attribute in an enum

95 views
Skip to first unread message

antoine....@gmail.com

unread,
Oct 23, 2017, 9:08:40 AM10/23/17
to SonarQube
Hi,
is it the way to report an issue?

Simple code quality bug that just occured to me :

public enum A {
   
private final String value;
}

public enum B {
   
final String value;
}

On enum A, Sonar will raise a : MINOR "private" is redundant in this context.
On enum B, Sonar will raise a : MAJOR Explicitly declare the visibility for "value".

Following the language specifications, the first one should not raise any comment from Sonar.

Antoine.

Nicolas Peru

unread,
Oct 24, 2017, 5:48:54 AM10/24/17
to antoine....@gmail.com, SonarQube
Hi Antoine, 

Which version of SonarJava are you using ? 
I can't reproduce the issue which (if I understand correctly) should be that the rule squid:S2333 about redudant modifiers should not raise an issue on private enum fields (it raises an issue on enum constructors though which is correct because they are implicitely private). 

Cheers, 


--
You received this message because you are subscribed to the Google Groups "SonarQube" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonarqube+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sonarqube/1fd30c2c-f70f-41cf-8ddf-0cf04640e019%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
Nicolas Peru | SonarSource

antoine....@gmail.com

unread,
Oct 24, 2017, 8:54:03 AM10/24/17
to SonarQube
Hello Nicola, thanks for your answer. We are using SonarQube v6.6 (build 32724), our Java analyzer is the last one (I don't have admin rights and can't tell you the exact version number, but it is updated regularly, so the latest stable release it should be)

antoine....@gmail.com

unread,
Oct 24, 2017, 8:56:58 AM10/24/17
to SonarQube
To be exact, this is the part of our code that raised both Sonar remarks :

public enum MyEnum{
   
A("a"),
   
B("b");

   
private final String value;

   
MyEnum(String value){
       
this.value = value;
   
}

    public String getValue(){
       
return value;
   
}
}

The warnings were raised on the "private final String value;" line.

Nicolas Peru

unread,
Oct 24, 2017, 8:57:14 AM10/24/17
to antoine....@gmail.com, SonarQube
Hi, 

So what is the problem ? I don't understand your issue.


For more options, visit https://groups.google.com/d/optout.

antoine....@gmail.com

unread,
Oct 24, 2017, 8:59:01 AM10/24/17
to SonarQube
Why did Sonar raised a warning for both syntaxes on the "value" attribute (with and without the "private" modifier)?
Reply all
Reply to author
Forward
0 new messages