GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

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

New issue
Copy link
New issue
Copy link
Closed
#6638
Closed
[java] UseUtilityClass: False negative for constant only classes#559
#6638
Copy link
Labels
a:false-negativePMD doesn't flag a problematic piece of code
Milestone
7.25.0

Description

@jsotuyod
jsotuyod
opened on Aug 14, 2017
Issue body actions

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

  1. jsotuyod
    added
    a:new-ruleProposal to add a new built-in rule
    on Aug 14, 2017
  2. jsotuyod
    changed the title [-][java] Mark constant-only interfaces / classes that are instantiable[/-] [+][java] Mark constant-only classes that are instantiable[/+] on Aug 14, 2017
  3. oowekyala commented on Aug 14, 2017

    @oowekyala
    oowekyala
    on Aug 14, 2017
    Member
    More actions

    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!

  4. jennyBu commented on Nov 16, 2017

    @jennyBu
    jennyBu
    on Nov 16, 2017
    More actions

    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?

  5. jsotuyod commented on Nov 16, 2017

    @jsotuyod
    jsotuyod
    on Nov 16, 2017
    MemberAuthor
    More actions

    @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.

  6. jennyBu
    added a commit that references this issue on Nov 23, 2017

    Implements pmd#559

    6c5848a
  7. jsotuyod
    changed the title [-][java] Mark constant-only classes that are instantiable[/-] [+][java] Flag constant-only classes that are instantiable[/+] on Jan 8, 2018
  8. jsotuyod commented on Jan 8, 2018

    @jsotuyod
    jsotuyod
    on Jan 8, 2018
    MemberAuthor
    More actions

    @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.

  9. UncleOwen
    changed the title [-][java] Flag constant-only classes that are instantiable[/-] [+][java] UseUtilityClass: False negative for constant only classes[/+] on May 14, 2026
  10. adangel
    added
    a:false-negativePMD doesn't flag a problematic piece of code
    and removed
    a:new-ruleProposal to add a new built-in rule
    on May 14, 2026
  11. adangel
    added this to the 7.25.0 milestone on May 14, 2026
  12. adangel
    added a commit that references this issue on May 14, 2026

    [doc] Update release notes (#6638, #559)

    ba0d793
  13. adangel
    closed this as completedin f85fb5aon May 14, 2026
  14. adangel
    added a commit that references this issue on May 14, 2026

    [java] Fix pmd#559: Improve UseUtilityClassRule to trigger also on st…

    This issue will close once commit f85fb5a is merged into the 'main' branch.
    f85fb5a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Type

    No type

    Projects

    No projects

      Milestone

      • 7.25.0

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.