@SuppressWarnings does not work with a constant

Please provide

  • Operating system: Linux (Fedora)
  • IDE name and flavor/env: IntelliJ IDEA 2021.3.2 (Community Edition)
  • SonarLint plugin version:
  • Is connected mode used: N/A

And a thorough description of the problem / question:

The plugin can’t process @SuppressWarnings annotation with a constant.


@SuppressWarnings(“java:S1168”) // works
@SuppressWarnings(Sonar.RETURN_EMPTY_COLLECTION) // does not work

The latter does not suppress the warning in IDE.

Hello @armandino and welcome to the Sonar Community!

The use case you are describing should be supported, with a small trick:

We are relying on “.class” for resolving the constants. It means that if you just added a constant in another file, we will not be able to find it. If you build the project, the issue should disappear as expected.

Hope it helps,

Hi @Quentin, thanks for suggestion. Unfortunately it still doesn’t work for me. I did a full build, but I still see an unsuppressed warning when I replace a String literal with a constant.

Could you share more information concerning the issue? Ideally, a minimal code sample reproducing the issue? In addition, it would help to have the constant definition and its exact location.

Hi Quentin, happy to report, the problem was on my end. As I was creating a sample project I realised that it is working, just slow to reflect in the IDE. The warning stays on for some time after the build, then eventually disappears. It disappeared much faster in an empty project :slight_smile:

Thanks for your help!

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.