A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/pmd/pmd/issues/5621 below:

[java] UnusedPrivateMethod with method ref · Issue #5621 · pmd/pmd · GitHub

Affects PMD Version: 7.7.0

Rule: UnusedPrivateMethod

Description:

Code Sample demonstrating the issue:

    private String foo(final Object foo, final String bar) {
        final String abc = Optional.ofNullable(foo.toString()).map(Foo::getNormalizedAddress).orElse(null);
        return abc;
    }

private static String getNormalizedAddress(final String encoded) {
        try (var objectInputStream = new ObjectInputStream(new ByteArrayInputStream(Base64.getDecoder().decode(encoded)))) {
            final var inetSocketAddress = (InetSocketAddress) objectInputStream.readObject();
            return inetSocketAddress.toString().substring(1);
        } catch (IOException | ClassNotFoundException | IllegalArgumentException e) {
            return null;
        }
    }

Expected outcome:

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

The method is clearly being used

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

Maven

 <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-pmd-plugin</artifactId>
                <version>3.26.0</version>
            </plugin>

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4