Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[java] ConfusingArgumentToVarargsMethod FP when types are unresolved #5070

Closed
SaschaRiemer opened this issue Jun 14, 2024 · 0 comments · Fixed by #5374
Closed

[java] ConfusingArgumentToVarargsMethod FP when types are unresolved #5070

SaschaRiemer opened this issue Jun 14, 2024 · 0 comments · Fixed by #5374
Labels
a:false-positive PMD flags a piece of code that is not problematic
Milestone

Comments

@SaschaRiemer
Copy link

Affects PMD Version:
7.2.0

Rule:
ConfusingArgumentToVarargsMethod
https://docs.pmd-code.org/latest/pmd_rules_java_errorprone.html#confusingargumenttovarargsmethod

Description:
Under certain circumstances (could not find a clear pattern yet, might be caused by the varargs parameter being a field in a different class), the ConfusingArgumentToVarargsMethod rule triggers even though it should not. This can happen for different varargs methods, when called with a single parameter of the same type, such as:
MessageFormat,format(PATTERN, ARG)
List.of(SomeEnum.CONSTANT)

Code Sample demonstrating the issue:
Two classes, in separate files
Messages.java:

public class Messages {
    public static String PATTERN = "Hello {0}";
    public static String SUBJECT = "World";
}

PmdExample.java

public class PmdExample {
    public void run() {
        MessageFormat.format(Messages.PATTERN, Messages.SUBJECT);
    }
}

Expected outcome:
PMD reports a violation at line PmdExample.java:3, but that's wrong. That's a false positive.

Running PMD through: CLI
I was unable to reproduce this example with gradle.
In a more complex codebase, this also happens with gradle, but I could not get that working with a simple example.

@SaschaRiemer SaschaRiemer added the a:false-positive PMD flags a piece of code that is not problematic label Jun 14, 2024
tpage-alfresco added a commit to Alfresco/pmd-ruleset that referenced this issue Jul 22, 2024
@oowekyala oowekyala changed the title [java] Incorrect identification of varargs calls [java] ConfusingArgumentToVarargsMethod FP when types are unresolved Nov 28, 2024
@adangel adangel added this to the 7.8.0 milestone Nov 29, 2024
adangel added a commit that referenced this issue Nov 29, 2024
… are unknown (#5374)

Merge pull request #5374 from oowekyala:issue5070-confusingArgToVarargs-unresolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:false-positive PMD flags a piece of code that is not problematic
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants