Menu

#1422 [java] UselessQualifiedThis: False positive with Java 8 Function

PMD-5.4.1
closed
java (55)
PMD
3-Major
Bug
2016-06-25
2015-10-07
Rei Angelus
No

Hello,

There is a false positive with this Java 8 code, when we call (ApiExceptionCtrlAdvice::toApiError) :

:::xml
<test-code>
<description>
<![CDATA
False positive with Java 8 Function
]>
</description>
<expected-problems>0</expected-problems>

<![CDATA[
public class ApiExceptionCtrlAdvice {

public final List<ApiError> handleApiAggregateException(final ApiAggregateException e) {
    return e.getCauses().stream().map(ApiExceptionCtrlAdvice::toApiError).collect(Collectors.toList());
}

private static ApiError toApiError(final Throwable e) {
    return new ApiError()
            .withException(e.getClass().getName())
            .withCause(Optional.ofNullable(e.getCause()).map(Throwable::getClass).map(Class::getName).orElse(EMPTY))
            .withMessage(Optional.ofNullable(e.getMessage()).orElse(EMPTY));
}

}
]]>

</test-code>

Thanks,

Discussion

  • Rob Worsnop

    Rob Worsnop - 2015-10-08

    Here's a simpler test case:

    public class PMDTest {
    
        void foo() {
            Runnable runnable = PMDTest::bar;
        }
    
        static void bar() {
        }
    }
    
     

    Last edit: Rob Worsnop 2015-10-08
  • Andreas Dangel

    Andreas Dangel - 2015-11-20
    • status: open --> closed
    • assigned_to: Andreas Dangel
    • Milestone: New Tickets --> PMD-5.4.1
     
  • Andreas Dangel

    Andreas Dangel - 2016-06-25
    • labels: --> java
    • summary: UselessQualifiedThis: False positive with Java 8 Function --> [java] UselessQualifiedThis: False positive with Java 8 Function
     

Log in to post a comment.