-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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] UnnecessaryCast false positive with unchecked cast #2748
Comments
That cast See the PMD rule |
For reference, the cast is unchecked because T is erased to Object. So Iterator<String> iter = Arrays.asList("a").iterator();
String[] array = asArray(iter); // boom |
This has been fixed with PMD 7.0.0-rc1. |
Affects PMD Version: 6.26.0
Description:
The rule UnnecessaryCast tells me that I'm doing a cast that is not necessary, but omitting it results in a compiler error.
This refers to the cast of
(T[])list.toArray()
from the example below. ThetoArray()
methods returns anObject[]
, not aT[]
. There is an alternative method available that takes an array as argument and uses the type of that for its return value, but in a case like this, whereT
is a type parameter instead of a concrete type for which an array can be initialized, that alternative method can't be used either.Code Sample demonstrating the issue:
Running PMD through: CLI
The text was updated successfully, but these errors were encountered: