Showing content from https://github.com/pmd/pmd/issues/4861 below:
[java] UnusedPrivateMethod - false positive with static methods in core JDK classes · Issue #4861 · pmd/pmd · GitHub
Skip to content Navigation Menu
Saved searches Use saved searches to filter your results more quickly
Sign up 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 Additional navigation options
[java] UnusedPrivateMethod - false positive with static methods in core JDK classes #4861
Description
Affects PMD Version: 7.0.0
Rule: UnusedPrivateMethod
Description:
The regression tester shows, that the rule finds the following allegedly unused private methods:
- https://github.com/openjdk/jdk/tree/jdk-11+28/src/java.base/share/classes/java/lang/Integer.java#L170 'toStringUTF16(int, int)'
- https://github.com/openjdk/jdk/tree/jdk-11+28/src/java.base/share/classes/java/lang/Integer.java#L338 'toUnsignedString0(int, int)'
- https://github.com/openjdk/jdk/tree/jdk-11+28/src/java.base/share/classes/java/lang/Integer.java#L389 'formatUnsignedIntUTF16(int, int, byte[], int, int)'
- https://github.com/openjdk/jdk/tree/jdk-11+28/src/java.base/share/classes/java/lang/Long.java#L154 'toStringUTF16(long, int)'
- https://github.com/openjdk/jdk/tree/jdk-11+28/src/java.base/share/classes/java/lang/Long.java#L241 'toUnsignedBigInteger(long)'
- https://github.com/openjdk/jdk/tree/jdk-11+28/src/java.base/share/classes/java/lang/Long.java#L417 'formatUnsignedLong0UTF16(long, int, byte[], int, int)'
- https://github.com/openjdk/jdk/tree/jdk-11+28/src/java.base/share/classes/java/lang/Object.java#L41 'registerNatives()'
Expected outcome:
All these private static methods are indeed in use. So, none of them should be reported.
Additional context:
- [java] UnusedPrivateMethod - fix false positive with lambdas #4841 (comment)
- [java] UnusedPrivateMethod - fix false positive with lambdas #4841 (comment)
A very preliminar look into the FP on openjdk shows that the node is null not because inference failed, but because, as those classes (ie: java.lang.Integer
) are part of the auxclasspath, they resolve to an ASM-backed symbol instead of an AST-backed symbol… and ASM-backed symbols can't reference the AST, so tryGetNode()
returns null
.
3 possible ways around this would be:
- Understand why ASM is prefered over AST-backed and see if it makes sense to switch over (probably there are performance issues at play, and ASM is objectively more reliable with things such as extending a class in a library).
- Change the rule to compare matches by
JMethodSig
instead of by node (this is in practice similar to what this PR tried, but without reimplementing arg-matching manually).
DashwoodIce9, mihalyr-prospect, AlexisJehan and axthosarouris
You can’t perform that action at this time.
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