Skip to content

[java] Fix #6546: Consolidate the Vector replacement rules - #7199

Merged
adangel merged 4 commits into
pmd:mainfrom
Gabrieljr42:fix/6546-replace-vector-with-list
Oct 29, 2026
Merged

adangel merged 4 commits into
pmd:mainfrom
Gabrieljr42:fix/6546-replace-vector-with-list

Conversation

@Gabrieljr42

@Gabrieljr42 Gabrieljr42 commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Describe the PR

Adds ReplaceJavaUtilVector to consolidate the Vector replacement rules. It reports Vector v = new Vector() once, covers constructor-only uses and subclasses including Stack, and recommends ArrayList or Deque/ArrayDeque when thread safety is not required. Type matching uses the qualified java.util.Vector type and ignores unresolved, unqualified Vector types.

Both ReplaceVectorWithList and UseArrayListInsteadOfVector are deprecated aliases of the new rule. The regression cases cover duplicate declarations, constructor-only uses, subclasses, both legacy aliases and deprecation warnings. The Stack regression snippet also compiles on JDK 21.

Validation

  • All 75 focused Java tests pass on JDK 21.
  • Java reactor verification passes with Javadoc and Dokka generation skipped:
    ./mvnw -o -pl pmd-java -am -Dmaven.javadoc.skip=true -Ddokka.skip=true verify

Related issues

Fixes #6546.

Ready?

  • Added unit tests for fixed bug/feature
  • Passing all unit tests in the Java reactor
  • Complete build ./mvnw clean verify passes (checked automatically by GitHub Actions)
  • Added rule documentation and release note

I used AI assistance for the implementation and tests.

Consolidate UseArrayListInsteadOfVector into ReplaceVectorWithList and cover Vector subclasses.

Fixes pmd#6546
Use the standard alias declaration and assert its expected deprecation warning.
@Gabrieljr42

Copy link
Copy Markdown
Contributor Author

Thanks for the review, @zbynek! Fixed the test snippet and removed the unqualified Vector checks. I also added ReplaceJavaUtilVector and deprecated both old rules as you suggested. The updated tests are passing.

@pmd-actions-helper

pmd-actions-helper Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Documentation Preview

Compared to main:
This changeset changes 0 violations,
introduces 202 new violations, 0 new errors and 0 new configuration errors,
removes 267 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-25 19:48:06+00:00 for f82ab25)

@adangel adangel changed the title [java] Consolidate the Vector replacement rules [java] Fix #6546: Consolidate the Vector replacement rules Oct 29, 2026
@adangel adangel added a:new-rule Proposal to add a new built-in rule is:deprecation The main focus is deprecating public APIs or rules, eg to make them internal, or removing them labels Oct 29, 2026
@adangel adangel added this to the 7.29.0 milestone Oct 29, 2026

@adangel adangel 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!

@adangel
adangel merged commit 95a777a into pmd:main Oct 29, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a:new-rule Proposal to add a new built-in rule 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] New Rule: ReplaceJavaUtilVector to consolidate ReplaceVectorWithList / UseArrayListInsteadOfVector

3 participants