You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The UnusedPrivateMethod rule correctly recognises private factory methods referenced from JUnit 5's @MethodSource when the simple form (@MethodSource("foo")) is used. However, when the same factory method is referenced through the equivalent fully-qualified form documented by JUnit (@MethodSource("fqcn#methodName")), PMD fails to follow the reference and reports the private method as unused.
This is a false positive: per the JUnit 5 docs for @MethodSource, the value may be a simple method name or a fully-qualified fully.qualified.ClassName#methodName reference, and both resolve to the same factory method.
Code Sample demonstrating the issue:
packagedemo.after;
importjava.util.stream.Stream;
importorg.junit.jupiter.params.ParameterizedTest;
importorg.junit.jupiter.params.provider.Arguments;
importorg.junit.jupiter.params.provider.MethodSource;
importorg.junit.jupiter.api.Assertions;
publicclassStringUtilsTest {
// Used as the factory method for testTrimAndUpperCase below.privatestaticStream<Arguments> trimAndUpperCaseArguments() {
returnStream.of(
Arguments.of("foo"),
Arguments.of("bar"),
Arguments.of("baz")
);
}
// Fully-qualified form — PMD does NOT recognise this as a usage.@MethodSource("demo.after.StringUtilsTest#trimAndUpperCaseArguments")
@ParameterizedTestvoidtestTrimAndUpperCase(Stringinput) {
Assertions.assertNotNull(input);
}
}
PMD output:
StringUtilsTest.java:13: UnusedPrivateMethod: Avoid unused private methods such as 'trimAndUpperCaseArguments()'.
Replacing the annotation with the simple form @MethodSource("trimAndUpperCaseArguments") makes the warning disappear, although both forms refer to the same method.
Expected outcome: PMD should treat the fully-qualified Class#method form in @MethodSource the same way as the simple form and not flag the referenced private static method as unused.
changed the title [-][java] UnusedPrivateMethod: false positive when @MethodSource uses a fully-qualified Class#method reference[/-][+][java] UnusedPrivateMethod / UnusedPrivateField: false positives for fully-qualified @MethodSource / @FieldSource references[/+]on Oct 29, 2026
Activity
[-][java] UnusedPrivateMethod: false positive when @MethodSource uses a fully-qualified Class#method reference[/-][+][java] UnusedPrivateMethod / UnusedPrivateField: false positives for fully-qualified @MethodSource / @FieldSource references[/+][-][java] UnusedPrivateMethod / UnusedPrivateField: false positives for fully-qualified @MethodSource / @FieldSource references[/-][+][java] UnusedPrivateMethod / UnusedPrivateField: False positives for fully-qualified @MethodSource / @FieldSource references[/+][-][java] UnusedPrivateMethod / UnusedPrivateField: False positives for fully-qualified @MethodSource / @FieldSource references[/-][+][java] UnusedPrivateMethod / UnusedPrivateField: False positives for fully qualified @MethodSource / @FieldSource references[/+][java] Fix pmd#7213: UnusedPrivateMethod/UnusedPrivateField with qual…