Repository navigation
[java] Fix #4576: UseShortArrayInitializer false positive with arrays of parameterized types - #7203
Merged
adangel merged 3 commits intoOct 29, 2026
Conversation
…ric arrays The short initializer is a generic array creation error when a component type argument is not an unbounded wildcard. Skip those declarations. List<?>[] and Map<?, ?>[] are still reported. Fixes pmd#4576 Co-authored-by: markxu <[email protected]>
zbynek
reviewed
Oct 20, 2026
zbynek
reviewed
Oct 20, 2026
…cation
C-style declarations such as Set<Integer> a[] = new Set[] { ... } put the
component type on the statement, so the generic-array skip missed them.
Report ArrayAllocation instead of the whole VariableDeclarator.
Fixes pmd#4576
Co-authored-by: markxu <[email protected]>
Contributor
|
Compared to main: (comment created at 2026-10-21 01:53:47+00:00 for e864eca) |
zbynek
approved these changes
Oct 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Describe the PR
UseShortArrayInitializersuggested replacingnew Set[]{...}with a short array initializer for declarations likeSet<Integer>[] a = new Set[]{...}. The short form is a generic array creation error there and does not compile.Following the guidance from the discussion in #6310, the rule now skips a declaration when some type argument of the array component type is not an unbounded wildcard.
Set<?>[]andMap<?, ?>[]are still reported, since the short form is legal for them.Added test cases for
Set<Integer>[],Map<?, String>[],Map<?, ? extends String>[](not reported) andSet<?>[],Map<?, ?>[](still reported).Known limitation: type arguments on a qualifying type (for example
Outer<String>.Inner[]) are not considered; that case is not part of the issue.Related issues
Ready?
./mvnw clean verifypasses (checked automatically by github actions)