Skip to content

[java] UseUtilityClass: False negative for constant only classes #559

@jsotuyod

Description

@jsotuyod

Update on 2026-05-14: Rather than creating a new rule to address this, this case is now considered as a false-negative for UseUtilityClass.

Rule: UseUtilityClass


Equivalent rule to java-design/UseUtilityClass but for classes that just have public constants.

These types have no behavior and should not be instantiable.

If the class extends another / implements interfaces, no warning should be added (behavior may be present on parent class / default methods on interface).

Code Sample demonstrating the issue:

public class Constants {
    public static final String MAILING_FROM = "noreply@mycompany.com";
    public static final String USER_AGENT = "mycompany/spider 1.0"
}

Notice we only mark classes. For interfaces there is already a rule java-design/ConstantsInInterface

Metadata

Metadata

Assignees

No one assigned

    Labels

    a:false-negativePMD doesn't flag a problematic piece of code

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions