Monday, August 24, 2009

Eclipse: ClassFile cannot be cast to ICompilationUnit

Today, checking out from the repository, I got this error message from Eclipse:

org.eclipse.jdt.internal.core.ClassFile cannot be cast to org.eclipse.jdt.core.ICompilationUnit

To save anybody getting the same message from wondering and poking around what it means, here is the simple reason. A colleague had accidentally checked in a .class file in a source folder, causing my Eclipse to try and process (compile) this presumed Java source file.

Deleting it from disk made the problem go away. Thinking about installing a pre-commit hook on the repository server to prevent this from happening again.


Anonymous said...

Or delete the Manifest folder that gets created if you bring in files using a jar file.

Jon said...

I had this same problem with Mylyn. I deleted the jar files (which shouldn't have been there since I uninstalled it) and everything was functioning again.