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] Deprecate UseObjectForClearerAPI · Issue #3741 · pmd/pmd

[java] Deprecate UseObjectForClearerAPI #3741

New issue
Copy link
New issue
Copy link
Closed
#6779
Closed
[java] Deprecate UseObjectForClearerAPI#3741
#6779
Copy link
Labels
is:deprecationThe main focus is deprecating public APIs or rules, eg to make them internal, or removing them
Milestone
7.26.0

Description

@oowekyala
oowekyala
opened on Jan 15, 2022
Issue body actions

The rule UseObjectForClearerAPI reports methods that take more than 3 String parameters. I think the justification is ok, but it's bizarre to single out strings. OTOH, generalizing this to any type of argument just gives ExcessiveParameterList. Although it's less thoroughly justified, ExcessiveParameterList also recommends using an object to wrap parameters.

Another problem with UseObjectForClearerAPI is that it doesn't care about constructors. Clearly,

callFun("a", "b", "c", "d")

is no less readable than

callFun(new FunArguments("a", "b", "c", "d"))

So to stay true to its goal of increasing readability, the rule should flag constructors, and also not simply recommend using an object, but also maybe the builder pattern. Since this is burned into the rule name we can't really change that (the rule name doesn't match our guidelines).


I think UseObjectForClearerAPI should be deprecated and its description used to enrich the description of ExcessiveParameterList.

Reacted by Dan Ziemba and Sören Glimm

Activity

  1. oowekyala
    added
    an:enhancementAn improvement on existing features / rules
    on Jan 15, 2022
  2. adangel
    added
    is:deprecationThe main focus is deprecating public APIs or rules, eg to make them internal, or removing them
    and removed
    an:enhancementAn improvement on existing features / rules
    on Jan 17, 2022
  3. adangel
    added this to the 7.x milestone on Jan 23, 2023
  4. zman0900 commented on Apr 24, 2025

    @zman0900
    zman0900
    on Apr 24, 2025
    More actions

    +1 This rule also doesn't seem to account for overriding of library / JDK methods. For example, rule is violated by overriding org.xml.sax.ext.DefaultHandler2#resolveEntity(java.lang.String, java.lang.String, java.lang.String, java.lang.String) when implementing a custom handler.

  5. adangel
    modified the milestones: 7.x, 7.26.0 on Jun 23, 2026
  6. adangel
    added a commit that references this issue on Jun 23, 2026

    [doc] Update release notes (#3741, #6779)

    9e25b20
  7. adangel
    closed this as completedin 404920bon Jun 23, 2026
  8. adangel
    added a commit that references this issue on Jun 23, 2026

    [java] Fix pmd#3741: Deprecate UseObjectForClearerApi (pmd#6779)

    This issue will close once commit 404920b is merged into the 'main' branch.
    404920b
  9. jtotht commented on Jul 7, 2026

    @jtotht
    jtotht
    on Jul 7, 2026
    More actions

    I just noticed this in the release notes.

    [I]t's bizarre to single out strings.

    I think it did make sense to single out strings – one may be tempted to use strings for everything (especially if the data comes from an untyped source like a properties file or a servlet request), which highly increases the risk of swapping parameters without causing compile-time errors. Consider the following signature:

    void banUser(String uuid, String duration, String reason, String notify);
    
    banUser("00000000-0000-0000-0000-000000000000", "bad behavior", "1 day", "true"); // Whoops, duration and reason swapped, but the compiler doesn’t notice this

    with the following one:

    void banUser(java.util.UUID uuid, java.time.Duration duration, String reason, boolean notify);
    
    banUser(new UUID(0, 0), "bad behavior", Duration.ofDays(1), true); // Compilation failure due to the signature mismatch

    Four parameters are not that excessive that I’d want to configure ExcessiveParameterList to report that regardless of the type, but four strings in a row are confusing and should be avoided if possible.

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

    is:deprecationThe main focus is deprecating public APIs or rules, eg to make them internal, or removing them

    Type

    No type

    Projects

    No projects

      Milestone

      • 7.26.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.