Skip to content

Conversation

@UncleOwen
Copy link
Member

@UncleOwen UncleOwen commented Aug 18, 2025

Describe the PR

Treat public constructors the exact same way as public methods.

Related issues

Ready?

I could use some help here. The problem is this line. If it's present, dogfood tells me to remove it. If it's not present, verify tells me to add it. How do I get around this?

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

@zbynek
Copy link
Contributor

zbynek commented Aug 18, 2025

If it's present, dogfood tells me to remove it. If it's not present, verify tells me to add it. How do I get around this?

Instead of suppressing the warning, why not just remove the formal parameter? The constructor is called from one place only.

@UncleOwen
Copy link
Member Author

Because the code says

        // topNode is unused, but we'll need it if we want to discount lambdas
        // if we add it later, we break binary compatibility

@UncleOwen
Copy link
Member Author

On the other hand, the file is in a package called internal. Does that mean, breaking binary compatibility isn't a concern?

@UncleOwen UncleOwen force-pushed the issue-4770-UnusedFormalParameter-should-ignore-public-constructor-as-same-as-method branch from 105455e to ad73e08 Compare August 19, 2025 11:10
@pmd-actions-helper
Copy link
Contributor

Documentation Preview

Compared to main:
This changeset changes 0 violations,
introduces 1 new violations, 0 new errors and 0 new configuration errors,
removes 602 violations, 0 errors and 0 configuration errors.

Regression Tester Report

(comment created at 2025-08-19 11:27:25+00:00 for ad73e08)

@UncleOwen UncleOwen changed the title [WIP] Fix #4770: UnusedFormalParameter should ignore public constructor as same as method Fix #4770: UnusedFormalParameter should ignore public constructor as same as method Aug 19, 2025
@UncleOwen
Copy link
Member Author

Found the answer myself: If the variable name begins with ignore or unused, there is no violation.

@UncleOwen UncleOwen changed the title Fix #4770: UnusedFormalParameter should ignore public constructor as same as method Fix #4770: [java] UnusedFormalParameter should ignore public constructor as same as method Aug 19, 2025
@oowekyala oowekyala self-assigned this Sep 6, 2025
@oowekyala oowekyala added this to the 7.17.0 milestone Sep 6, 2025
oowekyala added a commit that referenced this pull request Sep 6, 2025
@oowekyala oowekyala merged commit 3317403 into pmd:main Sep 6, 2025
12 checks passed
oowekyala added a commit that referenced this pull request Sep 6, 2025
…tor as same as method (#5994)

Merge branch 'issue-4770-UnusedFormalParameter-should-ignore-public-constructor-as-same-as-method'
@UncleOwen UncleOwen deleted the issue-4770-UnusedFormalParameter-should-ignore-public-constructor-as-same-as-method branch September 6, 2025 12:45
@adangel
Copy link
Member

adangel commented Sep 8, 2025

On the other hand, the file is in a package called internal. Does that mean, breaking binary compatibility isn't a concern?

Yes, that's what internal means - we could basically remove the parameter. Not sure, what this comment about binary compatibility is about here.

The API compatibility is described here: https://docs.pmd-code.org/latest/pmd_projectdocs_decisions_adr_3.html

@adangel adangel changed the title Fix #4770: [java] UnusedFormalParameter should ignore public constructor as same as method [java] Fix #4770: UnusedFormalParameter should ignore public constructor as same as method Sep 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[java] UnusedFormalParameter should ignore public constructor as same as method

4 participants