Skip to content
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

Impossible downcast of toArray() result to org.eclipse.jdt.internal.corext.refactoring.typeconstraints.ITypeConstraint[] in create(SingleVariableDeclaration) in FullConstraintCreator.java #25

Closed
GoogleCodeExporter opened this issue Jul 20, 2015 · 1 comment

Comments

@GoogleCodeExporter
Copy link

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

@GoogleCodeExporter
Copy link
Author

Original comment by keithl on 11 Feb 2010 at 12:17

  • Changed state: Invalid

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant