8

PMD and SonarQube a nice tools but I have problems trying to suppress PMD warnings.

We use Lombok a lot in our project, so many of the model classes have a: @SuppressWarnings("PMD.UnusedPrivateField") as an class-level annotations.

This works fine.

The problem is, that if I wan't to ignore one more rule, I would expect the following syntax: @SuppressWarnings(value = { "PMD.UnusedPrivateField", "PMD.SingularField" }) This looks like the correct syntax, also reading the implementation of the PMD annotation.

However, this seems not to works: None of the rules are now suppressed.

Rob
  • 11,492
  • 14
  • 59
  • 94
Morten Frank
  • 219
  • 1
  • 3
  • 10
  • Are you using `java.lang.SuppressWarnings`? Maybe you accidentally imported the annotation from a different package. – barfuin Apr 04 '14 at 07:24
  • I use the correct one. I also use the one for findbugs, then its like: @edu.umd.cs.findbugs.annotations.SuppressWarnings(value = { "EI_EXPOSE_REP2" }, justification = "Verified") – Morten Frank Apr 04 '14 at 08:14
  • The FindBugs annotation will not work for PMD. Can you post a simplified example file to reproduce the problem? – barfuin Apr 04 '14 at 14:51

2 Answers2

13

I would have expected this format (without the "value ="):

@SuppressWarnings({"PMD.UnusedPrivateField", "PMD.SingularField"})

Similar format is working for me in PMD 5.1.3 (although Eclipse complains about them not being supported).

stkent
  • 19,772
  • 14
  • 85
  • 111
colbadhombre
  • 803
  • 8
  • 11
  • This is exactly the case, thanks :-) I worked this out myself, but forgot to update my question. – Morten Frank Sep 19 '14 at 07:13
  • In my case I was using a constant to save the description then it will not works because PMD analyse the source file I can't interpret the a constant reference for example – deFreitas Feb 20 '19 at 22:20
2

As @colbadhombre writes:

@SuppressWarnings({"PMD.UnusedPrivateField", "PMD.SingularField"})

does the trick.

Regarding Eclipse:
Open Window->Preferences->Java->Compiler->Errors/Warnings

  • "Unhandled token in '@SuppressWarnings':" can be set to Ignore
  • Likewise the "Unused '@SuppressWarnings' token" if the warnings are enabled
stkent
  • 19,772
  • 14
  • 85
  • 111
Morten Frank
  • 219
  • 1
  • 3
  • 10