A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/pmd/pmd/issues/5070 below:

[java] ConfusingArgumentToVarargsMethod FP when types are unresolved · Issue #5070 · pmd/pmd · GitHub

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.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4