Skip to content

[java] Fix #3741: Deprecate UseObjectForClearerApi - #6779

Merged
adangel merged 6 commits into
pmd:mainfrom
UncleOwen:issue-3741-deprecate-UseObjectForClearerAPI
Jun 23, 2026
Merged

adangel merged 6 commits into
pmd:mainfrom
UncleOwen:issue-3741-deprecate-UseObjectForClearerAPI

Conversation

@UncleOwen

@UncleOwen UncleOwen commented Jun 13, 2026 •

Copy link
Copy Markdown
Member

Describe the PR

Enhance description of ExcessiveParameterList and deprecate UseObjectForClearerAPI

Related issues

Ready?

  • [n/a] Added unit tests for fixed bug/feature
  • Passing all unit tests
  • Complete build ./mvnw clean verify passes (checked automatically by github actions)
  • [n/a] Added (in-code) documentation (if needed)

@UncleOwen UncleOwen added the is:deprecation The main focus is deprecating public APIs or rules, eg to make them internal, or removing them label Jun 13, 2026
@UncleOwen
UncleOwen force-pushed the issue-3741-deprecate-UseObjectForClearerAPI branch from aa02848 to 30e1c6f Compare June 13, 2026 18:12
@pmd-actions-helper

pmd-actions-helper Bot commented Jun 13, 2026 •

Copy link
Copy Markdown
Contributor

Documentation Preview

Compared to main:
This changeset changes 0 violations,
introduces 0 new violations, 0 new errors and 0 new configuration errors,
removes 24 violations, 0 errors and 0 configuration errors.
There are 0 changed duplications, 0 new duplications and 0 removed duplications.
There are 0 changed CPD errors, 0 new CPD errors and 0 removed CPD errors.

Regression Tester Report

(comment created at 2026-06-19 17:11:00+00:00 for 61c26e9)

@UncleOwen
UncleOwen force-pushed the issue-3741-deprecate-UseObjectForClearerAPI branch from 30e1c6f to fcbb514 Compare June 13, 2026 18:42
@UncleOwen
UncleOwen force-pushed the issue-3741-deprecate-UseObjectForClearerAPI branch from fcbb514 to 0bb23cd Compare June 13, 2026 19:20
@UncleOwen
UncleOwen force-pushed the issue-3741-deprecate-UseObjectForClearerAPI branch from 0bb23cd to 29440bf Compare June 13, 2026 19:36
@zbynek

zbynek commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Would it make sense to add a second threshold perType to the rule?

A syntax with enums like new CssStyle(Float.RIGHT, Clear.LEFT, TextAlign.RIGHT, JustifyItems.LEFT, JustifyContent.RIGHT) is quite readable, whereas new CssStyle("right", "left", "right", "left", "right") is very confusing. The same applies to a large number of double or boolean args.

To emulate the current UseObjectForClearApi rule, one has to reduce the threshold of ExcessiveParameterList to 4, which may not be desirable.

@UncleOwen

Copy link
Copy Markdown
Member Author

Ehh... I don't like it.

  • ExcessiveParameterListRule is a AbstractJavaCounterCheckRule, and those all follow the same very simple pattern: One metric, one threshold. I don't want to change that.
  • The interface (a map from typename to threshold) feels complicated.

Do you just want to be able to replicate the old behavior exactly, or do you see a real need for a rule like this?

@zbynek

zbynek commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Do you just want to be able to replicate the old behavior exactly,

Personally I'm not using either of these rules 🙈 , but both "number of all parameters" and "number of parameters of the same type" are things I'd consider in a code review and I would use different threshold for pointing them out as issues.

@adangel adangel changed the title [java] Fix 3741: deprecate UseObjectForClearerApi [java] Fix 3741: Deprecate UseObjectForClearerApi Jun 18, 2026
@adangel adangel changed the title [java] Fix 3741: Deprecate UseObjectForClearerApi [java] Fix #3741: Deprecate UseObjectForClearerApi Jun 18, 2026
@adangel

adangel commented Jun 18, 2026

Copy link
Copy Markdown
Member

but both "number of all parameters" and "number of parameters of the same type" are things I'd consider in a code review and I would use different threshold for pointing them out as issues.

This could be a future improvement (aka different PR). Ideally, one could enable a single rule twice with different configurations in PMD (which currently isn't possible, but maybe when overriding the rule name? didn't try this), e.g.:

<rule ref="category/apex/design.xml/ExcessiveParameterList" name="ExcessiveParameterListSameType">
    <properties>
        <property name="minimum" value="4" />
        <property name="sameType" value="true" />
    </properties>
</rule>

<rule ref="category/apex/design.xml/ExcessiveParameterList">
    <properties>
        <property name="minimum" value="10" />
        <property name="sameType" value="false" />
    </properties>
</rule>

@adangel

adangel commented Jun 18, 2026

Copy link
Copy Markdown
Member

Did you check the comment on #1867? E.g. will ExcessiveParameterList report a violation for a method declaration, that implements a method declared in a interface? From the code, it probably does, because we don't ignore overridden methods. This might actually be an issue on its own (False positive when implementing inherited method) and probably should be solved separately.

@UncleOwen

Copy link
Copy Markdown
Member Author

I've removed "- Close #1867 " from the opening post, since ExcessiveParameterList suffers from the same problem.

@adangel adangel added this to the 7.26.0 milestone Jun 23, 2026
adangel added a commit that referenced this pull request Jun 23, 2026
@adangel
adangel merged commit 61c26e9 into pmd:main Jun 23, 2026
13 checks passed
@UncleOwen
UncleOwen deleted the issue-3741-deprecate-UseObjectForClearerAPI branch July 15, 2026 15:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[java] Deprecate UseObjectForClearerAPI

3 participants