False positive for rule 1144 on method referred by JUnit's @MethodSource

Hi,

as someone else already stated here: SonarQube marks function refered by MethodSource as Unused "private" method per rule 1144 - #20 by RPluizberto

Sonarqube falsely marks a method as false positive if it is a method source for a JUnit Test which uses @MethodSource without a value (which means that the method has the same name as the test method).

We’re using SonarQube 10.5.1.90531.

2 Likes

Hey there.

If you’re facing the same issue as in that other thread, you can expect the fix to come in SonarQube 10.6.

Hi,

if I understood the other thread correctly, only the case where a private method is referenced by name in annotations was getting fixed ([SONARJAVA-4943] - Jira) - that’s why I created this separate thread as was suggested by Irina Batinic in the last comment.

But if there is already a fix for the case where there is no method name inside the annotation in the making then never mind :slightly_smiling_face:

Aw, sorry. I should have read closer.

Can you provide a code sample of some code using @MethodSource that raises this false-positive?

Oh I’m sorry - in Sonarqube we don’t yet see the problem as it still uses sonar-java 7.33. We’re seeing the problem with the Sonarlint Plugin which already uses sonar-java 7.34.
I guess we would see the same effect in Sonarqube after the next upgrade.

Here’s a code sample:

@ParameterizedTest
@MethodSource
void generateAndDownloadApi(Target language) {
    doSomeSetup(language);
    makeSomeAssertions(language);
}

private static Stream<Arguments> generateAndDownloadApi() {
    return Stream.of(
            Arguments.of(Target.JAVA),
            Arguments.of(Target.PYTHON),
            Arguments.of(Target.RUBY)
    );
}

This leads to the issue “Unused “private” methods should be removed” for the second method.

1 Like

We are facing the same problem in Eclipse with SonarLint for Eclipse 10.2.0.81875 .

Hi @kim.martin and @Bastian_Kanaan , we can confirm the issue. While the FP was fixed for @MethodSource and other annotations when a method is referenced by its name, the special case of using @MethodReference without parameters was not considered in the implementation.

I created a ticket here.

Cheers,
Marco