Skip to content

[java] Drop AtLeastOneConstructor #1609

@mcandre

Description

@mcandre

Affects PMD Version:

1.04+

Rule:

AtLeastOneConstructor

Description:

PMD complains when no explicit constructor is declared for a class. Including JUnit tests.

Note that JUnit expects tests to feature a public, 0-ary constructor, or else it throws an initialization error. So treating JUnit tests as utility classes with private constructors is not an option.

One could explicitly declare an empty constructor for each JUnit test, but that's wasteful. In any case, Java automatically creates an implicit constructor, so there's really no need for PMD to generate noise about this.

As a workaround, I am disabling the AtLeastOneConstructor rule entirely, in my rulesets.xml:

<rule ref="category/java/codestyle.xml">
    <exclude name="AtLeastOneConstructor" />
</rule>

Running PMD through: [CLI | Ant | Maven | Gradle | Designer | Other]

Gradle

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions