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
Impossible downcast of toArray() result to org.eclipse.jdt.internal.corext.refactoring.typeconstraints.ITypeConstraint[] in create(SingleVariableDeclaration) in FullConstraintCreator.java
#25
Bug report generated from FindBugs
Impossible downcast of toArray() result to
org.eclipse.jdt.internal.corext.refactoring.typeconstraints.ITypeConstraint[]
in create(SingleVariableDeclaration)
In class
org.eclipse.jdt.internal.corext.refactoring.typeconstraints.FullConstraintCreato
r
In method create(SingleVariableDeclaration)
Actual type Object[]
Expected org.eclipse.jdt.internal.corext.refactoring.typeconstraints.ITypeConstraint[]
Return value of java.util.List.toArray()
At FullConstraintCreator.java:[line 393]
Classified as: MOSTLY_HARMLESS
test evaluation
Bug pattern explanation:
This code is casting the result of calling toArray() on a collection to a type
more specific than Object[], as in:
String[] getAsArray(Collection<String> c) {
return (String[]) c.toArray();
}
This will usually fail by throwing a ClassCastException. The toArray() of
almost all collections return an Object[]. They can't really do anything else,
since the Collection object has no reference to the declared generic type of
the collection.
The correct way to do get an array of a specific type from a collection is to
use c.toArray(new String[]); or c.toArray(new String[c.size()]); (the latter
is slightly more efficient).
There is one common/known exception exception to this. The toArray() method of
lists returned by Arrays.asList(...) will return a covariantly typed array.
For example, Arrays.asArray(new String[] { "a" }).toArray() will return a
String
[]. FindBugs attempts to detect and suppress such cases, but may miss some.
FindBugs issue identifier (do not modify or remove):
2c503602f300bdff0bb2465d0b3c7f2a
Original issue reported on code.google.com by keithl on 11 Feb 2010 at 12:17
The text was updated successfully, but these errors were encountered:
Original issue reported on code.google.com by
keithl
on 11 Feb 2010 at 12:17The text was updated successfully, but these errors were encountered: