-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
[java] Fix UnnecessaryCast false-negative in method calls #6029
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
Conversation
|
Compared to main: (comment created at 2025-09-17 22:17:46+00:00 for b7456fe) |
pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/codestyle/UnnecessaryCastRule.java
Show resolved
Hide resolved
|
Note that this is in principle the same problem as #5948, you need to check that the selected overload is the same. I would like the logic to be shared if possible. |
...java/src/test/resources/net/sourceforge/pmd/lang/java/rule/codestyle/xml/UnnecessaryCast.xml
Outdated
Show resolved
Hide resolved
...java/src/test/resources/net/sourceforge/pmd/lang/java/rule/codestyle/xml/UnnecessaryCast.xml
Outdated
Show resolved
Hide resolved
adangel
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Describe the PR
There is a false negative in the UnnecessaryCast rule when an object is cast just to call a method that's available on its declared type. Example:
We can simply call
arg.getX()without casting it toB.Related issues
This is somewhat similar to #3219, but in this PR I focused on the case when the cast is on methods's receiver, not its arguments.
Ready?
./mvnw clean verifypasses (checked automatically by github actions)