GeezerVison is showing github.com — [java] UseUtilityClass: False negative for constant only classes · Issue #559 · pmd/pmd
[java] UseUtilityClass: False negative for constant only classes #559
Description
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 = "[email protected]";
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
Activity
changed the title
[-][java] Mark constant-only interfaces / classes that are instantiable[/-] [+][java] Mark constant-only classes that are instantiable[/+] on Aug 14, 2017oowekyala commented on Aug 14, 2017
Really interesting! We could do that painlessly using signature matching (cf metrics). It could even allow us to look upwards in the hierarchy to see whether the superclasses / -interfaces define some behaviour or not
I'm working on making signature matching available to rules and not just metrics atm. I hope it can be available by the end of the week
Edit: actually xpath is enough if we don't need to go up the hierarchy. As you like it!
jennyBu commented on Nov 16, 2017
I think about implementing this rule. Is it important to do it similar to the ConstantsInInterface rule which is done the xpath way or could I also do the java approach?
jsotuyod commented on Nov 16, 2017
@jennyBu welcomed! All PRs are highly appreciated. There is no constraint as to how to build this, the rule should be achievable using both Java and XPath expressions, so whichever you are more comfortable with should be ok.
changed the title
[-][java] Mark constant-only classes that are instantiable[/-] [+][java] Flag constant-only classes that are instantiable[/+] on Jan 8, 2018jsotuyod commented on Jan 8, 2018
@jennyBu I've noticed you already seem to have branches on your fork with both, this rule and #595. Is there anything missing? Any reason for not submitting those PRs? Let us know if we can help you in any way.
changed the title
[-][java] Flag constant-only classes that are instantiable[/-] [+][java] UseUtilityClass: False negative for constant only classes[/+] on May 14, 2026added a commit that references this issue
on May 14, 2026This issue will close once commit f85fb5a is merged into the 'main' branch.f85fb5a
Metadata
Metadata
Development
No branches or pull requestsIssue actions