java:S3400 False positive

The following method triggers an S3400:

	 * Default priority is 6.
	 * @return the priority of the renderer if it is applicable
	protected int getPriority() {
		return 6;  //NOSONAR: protected method in abstract class = meant to be overwritten or extended.

As stated in our NOSONAR comment, we really don’t expect it there, for the reason mentioned.

Hello Alain,

I assume this code fragment is in Java, which IDE are you using ?

I tried to reproduce on IntelliJ, but I was not able to. Using the NOSONAR comment prevents the issue.

Are you connected to SonarQube or SonarCloud ?

This is SonarLint for Eclipse, standalone

I know that the NOSONAR quiets the issue, but IMHO this is a false positive.

Ok sorry I misunderstood.

I think it can be considered as a false positive for methods that are overridden. I will forward this to the team in charge that will decide.

I can also advise 2 things that would get rid of the issue:

  • extract the literal value to a constant and give it a meaningful name
  • if it’s a fixed value in every subclass, you could make it a constructor parameter

A last question: do you also observe the false positive in SonarQube (or SonarCloud) ?

This is used stand-alone.

1 Like

Hi @Alain_Picard,
I think we can consider your code sample as a false-positive. So I created SONARJAVA-3995 to improve the rule.
Thanks for your contribution,