Reputation: 163
I have a controller class and sonar is saying i should add a private constructor that throws an error but the class is used in a test class so doing this would cause the tests to fail. So should I add a public constructor to the class just so sonar doesn't pick it up?
Upvotes: 1
Views: 1353
Reputation: 3127
You can always customize Sonar so that it won't show such unuseful errors. Many of the checks may be valid only in specific cases. You can either disable this config for your whole project or put // NOSONAR
at the end of the line so that Sonar ignores that. Also you can ask Sonar to ignore a file by putting the following annotation on top of your class:
@java.lang.SuppressWarnings("squid:S00112")
in which the value after squid:
is the rule code corresponding to the rule that you're talking about.
Upvotes: 4