Branch: refs/heads/main
Home: https://github.com/pmd/pmd
Commit: f722cfb38218468559a9b0598625a7baed23fd87
https://github.com/pmd/pmd/commit/f722cfb38218468559a9b0598625a7baed23fd87
Author: fudian <[email protected]>
Date: 2026-08-14 (Fri, 14 Aug 2026)
Changed paths:
M docs/pages/release_notes.md
M
pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/UnnecessaryVarargsArrayCreationRule.java
M
pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/bestpractices/xml/UnnecessaryVarargsArrayCreation.xml
Log Message:
-----------
[java] Fix #6611: UnnecessaryVarargsArrayCreation ignores overload ambiguity
(#6949)
* [java] UnnecessaryVarargsArrayCreation: suppress when removing array creates
overload ambiguity
When an explicit array creation (e.g. new String[]{...}) is passed to a
varargs parameter, the rule suggested removing it. But when the callee
has another overload that is also applicable to the expanded varargs
argument list, removing the array would make the call ambiguous (or
select a different overload), so the explicit array is required for
overload resolution and the suggested fix does not compile.
Before reporting, check the sibling overloads of the selected executable:
if any of them is applicable (fixed- or variable-arity) to the argument
list obtained by expanding the array initializer into varargs elements,
suppress the violation. Constructors are enumerated from the selected
executable's own class (exhaustive, since constructors are not inherited);
methods are streamed from the declaring type via
JTypeMirror.streamMethods, which includes overloads inherited from
supertypes.
The applicability check is a conservative approximation of JLS
15.12.2.2-4 based on subtyping, treating generic parameter types by
their upper bound.
Fixes #6611
Signed-off-by: 付典 <[email protected]>
* import order
---------
Signed-off-by: 付典 <[email protected]>
Co-authored-by: Sören Glimm <[email protected]>
To unsubscribe from these emails, change your notification settings at
https://github.com/pmd/pmd/settings/notifications
_______________________________________________
Pmd-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/pmd-commits