Repository navigation
[java] Fix UnnecessaryCast false-negative in method calls - #6029
Merged
Merged
Conversation
zbynek
marked this pull request as draft
August 31, 2025 16:05
Contributor
|
Compared to main: (comment created at 2025-09-17 22:17:46+00:00 for b7456fe) |
oowekyala
reviewed
Sep 1, 2025
Member
|
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. |
zbynek
marked this pull request as ready for review
September 6, 2025 11:28
UncleOwen
requested changes
Sep 17, 2025
adangel
added a commit
that referenced
this pull request
Sep 19, 2025
adangel
added a commit
to adangel/pmd
that referenced
this pull request
Sep 19, 2025
3 of 4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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)