Bug 204652

Summary: "Open Type": ClassCastException in conjunction with a class folder
Product: [Eclipse Project] JDT Reporter: Tobias Jenkner <tobias.jenkner>
Component: CoreAssignee: Jerome Lanneluc <jerome_lanneluc>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: david_audel, eric_jodet, jerome_lanneluc, philippe_mulet
Version: 3.3Flags: philippe_mulet: pmc_approved+
Target Milestone: 3.3.2   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
eclipse log file containing the complete exception stacktrace
none
eclipse java project to reproduce the ClassCastException
none
Proposed fix and regression test
none
Proposed fix for 3.3 maintenance
none
Proposed regression test for 3.3 maintenance none

Description Tobias Jenkner CLA 2007-09-26 03:45:25 EDT
Created attachment 79189 [details]
eclipse log file containing the complete exception stacktrace

When using the "Open Type" dialog (CTRL+SHIFT+T) to open a class file from a class folder a ClassCastException occurs. The UI does not react to the request to open the type and an exception is logged:

java.lang.ClassCastException: org.eclipse.core.internal.resources.Folder cannot be cast to org.eclipse.core.resources.IFile
	at org.eclipse.jdt.internal.core.ClassFile.buildStructure(ClassFile.java:87)
	at org.eclipse.jdt.internal.core.Openable.generateInfos(Openable.java:229)
Comment 1 Jerome Lanneluc CLA 2007-09-26 04:20:09 EDT
What Eclipse build are you using ?
Comment 2 Tobias Jenkner CLA 2007-09-26 05:02:53 EDT
Version: 3.3.0
Build id: I20070621-1340
Comment 3 Jerome Lanneluc CLA 2007-09-26 07:10:58 EDT
Looking at the code, I don't see how this can happen. Do you have detailed steps to reproduce this problem ? A small workspace reproducing the problem would be ideal.
Comment 4 Tobias Jenkner CLA 2007-09-26 10:58:30 EDT
Created attachment 79211 [details]
eclipse java project to reproduce the ClassCastException

In order to reproduce the ClassCastException do the following steps:
1. create a new empty workspace
2. unzip this attachment to your filesystem
3. import the contents through File/Import/"Existing Projects into Workspace"
4. open the "Open Type" dialog (CTRL-SHIFT-T) and open the type "TestCCE"
-> the logfile is written to your workspace, nothing else happens
Comment 5 Tobias Jenkner CLA 2007-09-26 11:04:01 EDT
If you restart your workbench after importing the project the exception does not happen again, but the following error message is displayed in a dialog: "Type 'TestCCE' could not be found in 'P2/lib2.jar'. Make sure all workspaces and resources are refreshed."

In order to reproduce the ClassCastException again you have to create a new workspace and import the project into that workspace. 
Comment 6 Jerome Lanneluc CLA 2007-09-26 11:55:42 EDT
(In reply to comment #4)
Thanks for the test case Tobias. I cannot reproduce the ClassCastException but I'm always getting the Type "'TestCCE' could not be found in 'P2/lib2.jar'" dialog.

Investigating...
Comment 7 Jerome Lanneluc CLA 2007-09-26 12:11:53 EDT
Note that in 3.4 M2, the problem doesn't exist any longer as it was fixed in bug 138184.
Comment 8 Jerome Lanneluc CLA 2007-09-26 12:21:10 EDT
However looking more at the code, I now found a path that can lead to this ClassCastException. I'm writing a JUnit test to prove that.
Comment 9 Jerome Lanneluc CLA 2007-09-26 12:41:20 EDT
Actually it is possible to reproduce the ClassCastException consistently by following these steps:
1. create a new empty workspace
2. unzip the attachment from comment 4 to your filesystem
3. import the contents through File/Import/"Existing Projects into Workspace"
4. expand P2, then Referenced Libraries (but don't expand further)
5. open the "Open Type" dialog (CTRL-SHIFT-T) and open the type "TestCCE"
-> the logfile is written to your workspace, nothing else happens
Even if you restart and follow steps 4 then 5, then ClassCastException still occurs
Comment 10 Jerome Lanneluc CLA 2007-09-26 12:42:01 EDT
(In reply to comment #9)
This is using 3.3 of course.

Comment 11 Jerome Lanneluc CLA 2007-09-26 12:51:06 EDT
Created attachment 79221 [details]
Proposed fix and regression test
Comment 12 Jerome Lanneluc CLA 2007-09-27 07:11:01 EDT
Fix and test released for 3.4M3 in HEAD.
Comment 13 Philipe Mulet CLA 2007-09-27 09:13:27 EDT
Pls backport to 3.3.x
Comment 14 Jerome Lanneluc CLA 2007-09-27 10:05:42 EDT
Created attachment 79284 [details]
Proposed fix for 3.3 maintenance

Since the 3.4 M3 fix is too complicated and too risky for a backporting, this fix takes a different approach: it ensures that a PackageFragmentRoot is created during 'search all type names' (and not a JarPackageFragmentRoot as it would do in 3.3).
Comment 15 Jerome Lanneluc CLA 2007-09-28 07:40:05 EDT
Created attachment 79376 [details]
Proposed regression test for 3.3 maintenance
Comment 16 Jerome Lanneluc CLA 2007-10-08 06:57:09 EDT
Fix and test released for 3.3.2 in R3_3_maintenance
Comment 17 David Audel CLA 2007-10-30 10:22:06 EDT
Verified for 3.4M3 using I20071029-0010 build.
Comment 18 Jerome Lanneluc CLA 2007-11-21 04:49:30 EST
Since there is no workaround, this fix needs to be included in 3.3.2. Philippe please approve.
Comment 19 Eric Jodet CLA 2008-01-24 04:41:31 EST
Verified for 3.3.2 using M20080123-0800 build