Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[java] UnusedPrivateMethod false-positive used in lambda #4817

Closed
blacelle opened this issue Feb 12, 2024 · 2 comments · Fixed by #4841
Closed

[java] UnusedPrivateMethod false-positive used in lambda #4817

blacelle opened this issue Feb 12, 2024 · 2 comments · Fixed by #4841
Labels
a:false-positive PMD flags a piece of code that is not problematic has:pr The issue is already tackled in a PR
Milestone

Comments

@blacelle
Copy link

blacelle commented Feb 12, 2024

Affects PMD Version:
7.0.0-rc4

Rule: UnusedPrivateMethod

Description:

False-positive as notCachedGetAllDps is used

[INFO] --- maven-pmd-plugin:3.21.2:check (default-cli) @ web-test ---
[INFO] PMD version: 7.0.0-rc4
[INFO] PMD Failure: io.mitrust.backoffice.NotUsedPrivateMethodFalsePositive:15 Rule:UnusedPrivateMethod Priority:3 Avoid unused private methods such as 'notCachedGetAllDps(String)'

Code Sample demonstrating the issue:

package io.mitrust.backoffice;

import java.util.Collections;
import java.util.List;

import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;

public class NotUsedPrivateMethodFalsePositive {

    private final LoadingCache<String, List<? extends String>> clientIdsToDps = CacheBuilder.newBuilder()
            .build(CacheLoader.from(clientId -> notCachedGetAllDps(clientId)));

    private List<? extends String> notCachedGetAllDps(String clientId) {
        return Collections.singletonList(clientId);
    }

    public List<?> getClientIdsToDps() {
        return clientIdsToDps.getUnchecked("");
    }

}

Expected outcome:

PMD reports a violation at line ..., but that's wrong. That's a false positive.

Running PMD through: [CLI | Ant | Maven | Gradle | Designer | Other]

@blacelle blacelle added the a:false-positive PMD flags a piece of code that is not problematic label Feb 12, 2024
@adangel adangel changed the title [java] 7.0.0-rc4 UnusedPrivateMethod false-positive (on Lambda?) [java] UnusedPrivateMethod false-positive (on Lambda?) (7.0.0-rc4) Feb 13, 2024
@adangel adangel changed the title [java] UnusedPrivateMethod false-positive (on Lambda?) (7.0.0-rc4) [java] UnusedPrivateMethod false-positive used in lambda Feb 29, 2024
@adangel adangel added this to the 7.0.0 milestone Feb 29, 2024
@danjee
Copy link

danjee commented Mar 4, 2024

I've found the issue is non lambda calls as-well.

@danjee
Copy link

danjee commented Mar 4, 2024

Also this happens in imports. If you use an import like Enum.valueOf in a lambda rule="UnnecessaryImport" kicks in.

@jsotuyod jsotuyod added has:pr The issue is already tackled in a PR needs:pmd7-revalidation The issue hasn't yet been retested vs PMD 7 and may be stale and removed needs:pmd7-revalidation The issue hasn't yet been retested vs PMD 7 and may be stale labels Mar 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:false-positive PMD flags a piece of code that is not problematic has:pr The issue is already tackled in a PR
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants