views:

12091

answers:

17

I was hoping someone could help me out with a problem I'm having using the java search function in Eclipse on a particular project.

When using the java search on one particular project, I get an error message saying 'Class file name must end with .class' (see stack trace below). This does not seem to be happening on all projects, just one particular one, so perhaps there's something I should try to get rebuilt?

I have already tried Project -> Clean... and Closing Eclipse, deleting all the built class files and restarting Eclipse to no avail.

The only reference I've been able to find on Google for the problem is at http://www.crazysquirrel.com/computing/java/eclipse/error-during-java-search.jspx, but unfortunately his solution (closing, deleting class files, restarting) did not work for me.

If anyone can suggest something to try, or there's any more info I can gather which might help track it's down, I'd greatly appreciate the pointers.

Version: 3.4.0 Build id: I20080617-2000

Also just found this thread - http://www.myeclipseide.com/PNphpBB2-viewtopic-t-20067.html - which indicates the same problem may occur when the project name contains a period. Unfortunately, that's not the case in my setup, so I'm still stuck.

Caused by: java.lang.IllegalArgumentException: Class file name must end with .class
at org.eclipse.jdt.internal.core.PackageFragment.getClassFile(PackageFragment.java:182)
at org.eclipse.jdt.internal.core.util.HandleFactory.createOpenable(HandleFactory.java:109)
at org.eclipse.jdt.internal.core.search.matching.MatchLocator.locateMatches(MatchLocator.java:1177)
at org.eclipse.jdt.internal.core.search.JavaSearchParticipant.locateMatches(JavaSearchParticipant.java:94)
at org.eclipse.jdt.internal.core.search.BasicSearchEngine.findMatches(BasicSearchEngine.java:223)
at org.eclipse.jdt.internal.core.search.BasicSearchEngine.search(BasicSearchEngine.java:506)
at org.eclipse.jdt.core.search.SearchEngine.search(SearchEngine.java:551)
at org.eclipse.jdt.internal.corext.refactoring.RefactoringSearchEngine.internalSearch(RefactoringSearchEngine.java:142)
at org.eclipse.jdt.internal.corext.refactoring.RefactoringSearchEngine.search(RefactoringSearchEngine.java:129)
at org.eclipse.jdt.internal.corext.refactoring.rename.RenameTypeProcessor.initializeReferences(RenameTypeProcessor.java:594)
at org.eclipse.jdt.internal.corext.refactoring.rename.RenameTypeProcessor.doCheckFinalConditions(RenameTypeProcessor.java:522)
at org.eclipse.jdt.internal.corext.refactoring.rename.JavaRenameProcessor.checkFinalConditions(JavaRenameProcessor.java:45)
at org.eclipse.ltk.core.refactoring.participants.ProcessorBasedRefactoring.checkFinalConditions(ProcessorBasedRefactoring.java:225)
at org.eclipse.ltk.core.refactoring.Refactoring.checkAllConditions(Refactoring.java:160)
at org.eclipse.jdt.internal.ui.refactoring.RefactoringExecutionHelper$Operation.run(RefactoringExecutionHelper.java:77)
at org.eclipse.jdt.internal.core.BatchOperation.executeOperation(BatchOperation.java:39)
at org.eclipse.jdt.internal.core.JavaModelOperation.run(JavaModelOperation.java:709)
at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:1800)
at org.eclipse.jdt.core.JavaCore.run(JavaCore.java:4650)
at org.eclipse.jdt.internal.ui.actions.WorkbenchRunnableAdapter.run(WorkbenchRunnableAdapter.java:92)
at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:121)

Thanks McDowell, closing and opening the project seems to have fixed it (at least for now).

A: 

Perhaps there is an issue with the classpath? Does your project reference any other projects or have an external classes or jars you are depending on?

Sam Merrell
+27  A: 

Two more general-purpose mechanisms for fixing some of Eclipse's idiosyncrasies:

  • Close and open the project
  • Delete the project (but not from disk!) and reimport it as an existing project

Failing that, bugs.eclipse.org might provide the answer.

If the workspace is caching something broken, you may be able to delete it by poking around in workspace/.metadata/.plugins. Most of that stuff is fairly transient (though backup and watch for deleted preferences).

McDowell
Peter
panschk
Zsolt Török
Closing and reopening my projects didn't help me :-( It seems like closing and reopening helps for some, but if it doesn't, you need to follow the advice by Olivier Dagenais
Roel Spilker
Worked like a charm. Thanks for the question and answer.
Noam Gal
+6  A: 

Got this error to the other day. Tried deleting the all .class-files and resources from my output folder manually. Didn't work. Restarted my computer (WinXP). Didn't work. Closed my project in Eclipse and opened it again. Worked!!! Hopes this solves someones problem out there. The search facilities and truly essential to Eclipse.

+1  A: 

The main problem is that this is a bug in newer versions of Eclipse. I had never seen this before in older versions. Is there a plan to fix this?

+41  A: 

Comment #9 to bug 269820 explains how to delete the search index, which appears to be the solution to a corrupt index whose symptoms are the dreaded

An internal error occurred during: "Items filtering".
Class file name must end with .class

message box.

How to delete the search index:

  1. Close Eclipse
  2. Delete <workspace>/.metadata/.plugins/org.eclipse.jdt.core/*.index
  3. Delete <workspace>/.metadata/.plugins/org.eclipse.jdt.core/savedIndexNames.txt
  4. Start Eclipse again
Olivier Dagenais
This worked for me to fix the error while searching (CtrlShiftT)
JodaStephen
Minor typo.2. Delete <workspace>.metadata.plugins\org.eclipse.jdt.core\*.index
Jon Strayer
This worked for me too. Found it here: http://u.nu/3aqy3 But it's the same procedure. ~Chris
cimnine
thanks, this worked for me
ksclarke
+3  A: 

Hi, I also encountered this issue recently, the below scenario worked for me.

  1. Close Eclipse
  2. Delete <workspace>/.metadata/.plugins/org.eclipse.jdt.core/*.index
  3. Delete <workspace>/.metadata/.plugins/org.eclipse.jdt.core/savedIndexNames.txt
  4. Start Eclipse again
+1  A: 

Closing the projects didn't do the trick for me. I started eclipse with the -clean flag and that worked for some reason.

-Rick

Rick
+1  A: 

Hi, I also encountered this issue recently, the below scenario worked for me.

Close Eclipse Delete /.metadata/.plugins/org.eclipse.jdt.core/*.index Delete /.metadata/.plugins/org.eclipse.jdt.core/savedIndexNames.txt Start Eclipse again

Gajanand
A: 

Closing and opening project solves the problem

Nilay
A: 

Closing and reopening project worked for me too...thanks :)

Reddy
A: 

-clean option also didn't work for me but closing and reopening the project did.

cool

Sanjeev Dhiman
A: 

I tried all of the above solutions. The one that finally did the trick was starting with the -clean option on the eclipse command line.

Thanks.

Sean Overby
A: 

Close Eclipse Delete /.metadata/.plugins/org.eclipse.jdt.core/*.index Delete /.metadata/.plugins/org.eclipse.jdt.core/savedIndexNames.txt Start Eclipse again

worked for me. thanks Oliver

victor
A: 

This solution worked for me too... Thanks so much.... Close Eclipse Delete /.metadata/.plugins/org.eclipse.jdt.core/*.index Delete /.metadata/.plugins/org.eclipse.jdt.core/savedIndexNames.txt Start Eclipse again

Ramya
A: 

Adding -clean in the eeclips.ini file and a project clean solved the problem for me.

Polluxian
A: 

worked for me:

Close Eclipse
Delete /.metadata/.plugins/org.eclipse.jdt.core/*.index
Delete /.metadata/.plugins/org.eclipse.jdt.core/savedIndexNames.txt
Start Eclipse again

stormy
A: 

Thanks for the solution. worked for me

Mutahi