Skip to content

[java] Fix #7009: ReplaceJavaUtilDate/Calendar miss pattern variables and record components - #7010

Merged
UncleOwen merged 3 commits into
pmd:mainfrom
renechoi:fix/issue-7009-pattern-variable
Aug 30, 2026
Merged

UncleOwen merged 3 commits into
pmd:mainfrom
renechoi:fix/issue-7009-pattern-variable

Conversation

@renechoi

@renechoi renechoi commented Aug 30, 2026 •

Copy link
Copy Markdown
Contributor

Describe the PR

Both rules match only LocalVariableDeclaration, FormalParameter, FieldDeclaration and ConstructorCall, so neither a pattern variable nor a record component is reported.

TypePattern covers instanceof patterns, switch case labels and the components of a record deconstruction pattern. RecordComponent covers record component declarations.

With only the new test cases applied they report 0 problems and fail; with the XPath change all 21 pass in the two rule tests.

Related issues

Ready?

  • 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)

Both rules matched only LocalVariableDeclaration, FormalParameter,
FieldDeclaration and ConstructorCall, so a variable introduced by a
pattern was never reported. Add TypePattern to both XPath expressions,
which covers instanceof patterns, switch case labels and the component
patterns of a record deconstruction.
@pmd-actions-helper

pmd-actions-helper Bot commented Aug 30, 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 0 violations, 16 errors and 9 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-08-30 17:24:40+00:00 for 82afe35)

@UncleOwen

Copy link
Copy Markdown
Member

Record components themselves are still not reported (a separate gap).

Feel free to add those as well.

Follow-up to the review on pmd#7010.

Add RecordComponent to both XPath expressions, so a record component
declared as java.util.Date or java.util.Calendar is reported. Varargs
components parse as an array type and stay unreported, which matches
how Date[] parameters behave today.

Replace the java.sql.Timestamp test case with a fully qualified
java.util.Date one, so nothing added here depends on the java.sql
behaviour discussed in pmd#6025.

Let the record deconstruction test declare record Box(Object value),
so it keeps covering only the nested type pattern now that the record
component itself is reported too.
…ern-variable

# Conflicts:
#	docs/pages/release_notes.md

@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 added this to the 7.28.0 milestone Aug 30, 2026
@UncleOwen
UncleOwen merged commit 9c1fe8f into pmd:main Aug 30, 2026
13 checks passed
@renechoi renechoi changed the title [java] Fix #7009: ReplaceJavaUtilDate/Calendar miss pattern variables [java] Fix #7009: ReplaceJavaUtilDate/Calendar miss pattern variables and record components Sep 9, 2026
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] ReplaceJavaUtilDate: False negative when using pattern matching

2 participants