Affects PMD Version:
6.29.0
Description:
Rules UnusedAssignment and UnusedFormalParameter flag the args parameter in the main method when it is unreferenced.
It should be ignorable via a parameter.
@oowekyala:
With UnusedAssignment you can also rename your parameter to ignored. We can make #2838 apply to UnusedFormalParameter too. Then there would be a simple way to ignore the warning, and the fact that the parameter is ignored on purpose is explicit (this is the same kind of issue as #2893).
@Fernal73:
That's fine by me. I'd like to be able to retain the semantics of the parameter by prefixing the parameter name with underscore or argsIgnored or argsUnused.
Code Sample demonstrating the issue:
package jls;
import java.util.Objects;
public final class UnsafeVarargs<T> {
private UnsafeVarargs() {
throw new IllegalStateException("Private constructor.");
}
public static <T> T[] unsafe(T... elements) {
// unsafe! don't ever return a parameterized varargs array
return elements;
}
public static <T> T[] broken(T seed) {
// broken! This will be an Object[] no matter what T is
T[] plant = unsafe(seed, seed, seed);
return plant;
}
public static String[] plant() {
// ClassCastException
String[] plants = broken("seed");
return plants;
}
@SuppressWarnings("PMD.SystemPrintln")
public static void main(String... args) {
System.out.println(Objects.toString(plant()));
}
}
Running PMD through: [CLI | Ant | Maven | Gradle | Designer | Other]
Affects PMD Version:
6.29.0
Description:
Rules UnusedAssignment and UnusedFormalParameter flag the
argsparameter in themainmethod when it is unreferenced.It should be ignorable via a parameter.
@oowekyala:
With UnusedAssignment you can also rename your parameter to ignored. We can make #2838 apply to UnusedFormalParameter too. Then there would be a simple way to ignore the warning, and the fact that the parameter is ignored on purpose is explicit (this is the same kind of issue as #2893).
@Fernal73:
That's fine by me. I'd like to be able to retain the semantics of the parameter by prefixing the parameter name with underscore or
argsIgnoredorargsUnused.Code Sample demonstrating the issue:
Running PMD through: [CLI | Ant | Maven | Gradle | Designer | Other]