Bug 227822 - [select] ClassCastException thrown if unable to resolve core Java types
Summary: [select] ClassCastException thrown if unable to resolve core Java types
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.4   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.4 M7   Edit
Assignee: David Audel CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-04-18 15:21 EDT by Andrew Mak CLA
Modified: 2008-04-29 07:25 EDT (History)
3 users (show)

See Also:


Attachments
Test plugin with popup action (5.12 KB, application/x-zip-compressed)
2008-04-18 15:21 EDT, Andrew Mak CLA
no flags Details
JavaProject (887 bytes, application/x-zip-compressed)
2008-04-18 15:21 EDT, Andrew Mak CLA
no flags Details
Proposed fix (9.90 KB, patch)
2008-04-23 04:29 EDT, David Audel CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Andrew Mak CLA 2008-04-18 15:21:28 EDT
Created attachment 96645 [details]
Test plugin with popup action

I was trying to resolve a core Java type (e.g. java.util.ArrayList) in a project whose classpath is broken because the project was imported into the workspace.  I was surprised to see a ClassCastException instead of getting null or empty array back from the IType.resolveType(String) call.

I've attached a simple TestPlugin (w/ source) that illustrates this problem.  I'll also attach a test project next.

Steps:
1. Launch eclipse with the TestPlugin.
2. Import the JavaProject into workspace, but don't fix the classpath errors.
3. Right-click foo.Bar java file and run the New Submenu > New Action popup.
4. See the following ClassCastException:

java.lang.ClassCastException: org.eclipse.jdt.internal.compiler.lookup.PackageBinding incompatible with org.eclipse.jdt.internal.compiler.lookup.TypeBinding
	at org.eclipse.jdt.internal.codeassist.select.SelectionOnQualifiedTypeReference.getTypeBinding(SelectionOnQualifiedTypeReference.java:49)
	at org.eclipse.jdt.internal.compiler.ast.TypeReference.internalResolveType(TypeReference.java:130)
	at org.eclipse.jdt.internal.compiler.ast.TypeReference.resolveType(TypeReference.java:197)
	at org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding.resolveTypeFor(SourceTypeBinding.java:1280)
	at org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding.fields(SourceTypeBinding.java:610)
	at org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding.faultInTypesForFieldsAndMethods(SourceTypeBinding.java:588)
	at org.eclipse.jdt.internal.compiler.lookup.CompilationUnitScope.faultInTypes(CompilationUnitScope.java:438)
	at org.eclipse.jdt.internal.codeassist.SelectionEngine.selectType(SelectionEngine.java:1177)
	at org.eclipse.jdt.internal.core.NamedMember.resolveType(NamedMember.java:292)
	at org.eclipse.jdt.internal.core.NamedMember.resolveType(NamedMember.java:245)
	at testplugin.popup.actions.NewAction.run(NewAction.java:53)
        ...
Comment 1 Andrew Mak CLA 2008-04-18 15:21:49 EDT
Created attachment 96646 [details]
JavaProject
Comment 2 David Audel CLA 2008-04-22 05:58:53 EDT
Another way to reproduce the bug:

1) create the java project P
2) remore the JRE from the classpath
3) create Test.java
public class Test {
	java.util.ArrayList v;
}
4) select 'java.util.ArrayList'
5) do F3 (code select)
This cause the same exception.
Comment 3 David Audel CLA 2008-04-23 04:29:27 EDT
Created attachment 97172 [details]
Proposed fix
Comment 4 David Audel CLA 2008-04-23 04:30:47 EDT
Released for 3.4M7.

Tests added
  ResolveTests2#testBug227822a() -> testBug227822d()
Comment 5 Eric Jodet CLA 2008-04-29 07:25:25 EDT
Verified for 3.4M7 using I20080427-2000.