Skip to content
Advertisement

How to suppress violations in PMD?

When I run a PMD analysis I receive violation:

Each class should declare at least one constructor

This violation is on a Spring controller. This controller is instantiated by Spring, so I shouldn’t need to invoke this class.

What is recommended way of ignoring this violation?

According to this doc can use //NOPMD but I just want to ignore specific violation.

Advertisement

Answer

PMD also supports the @SuppressWarnings annotations:

// This will suppress all the PMD warnings in this class
@SuppressWarnings("PMD")
public class Bar {
 void bar() {
  int foo;
 }
}

Or just one type of warning:

// This will suppress UnusedLocalVariable warnings in this class
@SuppressWarnings("PMD.UnusedLocalVariable")
public class Bar {
 void bar() {
  int foo;
 }
}

And what you might also want to look into are creating rulesets and suppressing warnings. Maybe you want to disable a certain rule, or exclude certain files and folders from PMD checking.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement