Skip to content

[java] Reset CPD constructor detection for each file - #7138

Merged
UncleOwen merged 1 commit into
pmd:mainfrom
noor-ahmadi:fix_cpd_constructor_state
Oct 4, 2026
Merged

UncleOwen merged 1 commit into
pmd:mainfrom
noor-ahmadi:fix_cpd_constructor_state

Conversation

@noor-ahmadi

Copy link
Copy Markdown
Contributor

Describe the PR

The constructor detector was kept around when CPD moved to another file so its old state could affect the next one. It now starts fresh for each file which fixes the crash with --ignore-identifiers.

Added tests for the three file case in the issue and a case where an identifier in a later file was being treated as a constructor. Both compare the reused lexer with a fresh lexer.

This touches the detector setup that #6215 also changes so that part may need adjusting if it lands first.

ran ./mvnw -B -ntp -pl pmd-java -am clean verify with Java 21. 16,774 tests with 32 skipped and no failures or errors. Both new tests failed before the fix.

Related issues

Ready?

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

@pmd-actions-helper

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 0 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-10-03 08:58:33+00:00 for ec0c7c3)

@UncleOwen UncleOwen added this to the 7.29.0 milestone Oct 4, 2026

@UncleOwen UncleOwen left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@UncleOwen
UncleOwen merged commit 6d2e23a into pmd:main Oct 4, 2026
13 checks passed
turbospaces added a commit to codiqo/codiqo that referenced this pull request Oct 5, 2026
…retry workaround

pmd/pmd#7138 (merged for 7.29.0) makes JavaCpdLexer start a fresh ConstructorDetector for every
file. Before it, the detector leaked state across files, and a large enough file set (micronaut-core,
spring-framework) crashed CPD with an NPE that named no file.

- pmd.version is 7.29.0-SNAPSHOT, resolved from the Central snapshots repository, which is added to
  both <repositories> and <pluginRepositories> (maven-pmd-plugin is pinned to ${pmd.version}). Both
  blocks are temporary and go once PMD 7.29.0 is released (milestone due 2026-10-30).
- The CPD batch retry existed only for that crash and is removed together with CpdBatchRetryTest.
  CPD again runs once over every file of a language, so clones spanning what used to be two retry
  batches are no longer lost.

Consumers need no change: codiqo itself is published to the same snapshots repository, which they
already list as both a repository and a plugin repository.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
turbospaces added a commit to codiqo/codiqo that referenced this pull request Oct 30, 2026
…stable releases

PMD 7.29.0 carries pmd/pmd#7138, the CPD lexer fix the floating
7.29.0-SNAPSHOT was used for, so the temporary central-snapshots
repository and plugin repository are removed with it.

JaCoCo 0.8.16 adds official Java 27 support. It is also the agent version
codiqo attaches to the builds it analyses.

openai-java moves from 4.91.0 to 4.94.0, with no breaking changes listed.
ClassGraph stays on 4.8.199, the latest 4.x: 6.0.1 is JDK 25 bytecode.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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] CPD: Constructor detection state leaks between files with --ignore-identifiers

2 participants