Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

@SuppressWarnings more than one rule not working

Tags:

sonarqube

pmd

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.

like image 434
Morten Frank Avatar asked Apr 04 '14 07:04

Morten Frank


People also ask

How can you avoid PMD violations?

In my organization I use the PMD ignore option in POM file to suppress all warnings that are generated for client stubs (and kept in separate module) that we auto-generate, as those are third party client-stubs we don't tend to touch them thought there are any warnings or violations and I am assuming the same thing for ...

What is @SuppressWarnings unlikely ARG type?

This implies that the compiler may show "unwanted" warnings, or filter out invocations that are in fact bugs. For the former case, @SuppressWarnings("unlikely-arg-type") will document the exception both for the user and for the compiler.

What does @SuppressWarnings unused mean?

The @SuppressWarnings annotation disables certain compiler warnings. In this case, the warning about deprecated code ( "deprecation" ) and unused local variables or unused private methods ( "unused" ).

What does @SuppressWarnings unchecked do?

An unchecked warning tells a programmer that a cast may cause a program to throw an exception somewhere else. Suppressing the warning with @SuppressWarnings("unchecked") tells the compiler that the programmer believes the code to be safe and won't cause unexpected exceptions.


1 Answers

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).

like image 92
colbadhombre Avatar answered Oct 03 '22 17:10

colbadhombre