Skip to content

How can I supress the checkstyle message “Utility classes should not have a public of default constructor” when using Spring

In a Spring Java project I have the following class:

@SuppressWarnings({"PMD", "Checkstyle"})
public class ToolBoxApplication {

    public static void main(final String[] args) {, args);

Building using Jenkins tells me that I should not have a public or default constructor in a utility class.

In my checkstyle.xml withing Treewalker file I have

<!-- Make the @SuppressWarnings annotations available to Checkstyle -->
<module name="SuppressWarningsHolder" />

And the module

I tried to supress the specific check using

@SuppressWarnings({“PMD”, “checkstyle:HideUtilityClassConstructor”})

but this did not work either. The “PMD” supression does work (it effectively reports the same error).



You need to specify checkstyle name in lower case when supressing. This will do

@SuppressWarnings({"PMD", "checkstyle:hideutilityclassconstructor"})