Bug 90025 - ClassCastException calling IType.resolveType()
Summary: ClassCastException calling IType.resolveType()
Status: RESOLVED WORKSFORME
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.1 RC1   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-04-01 15:20 EST by Tom Stamm CLA
Modified: 2005-05-17 13:21 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tom Stamm CLA 2005-04-01 15:20:59 EST
I'm getting an intermittant ClassCastException when I call resolveType() 
on an IType. It only happens occasionally, and I haven't been able to figure 
out what the cause is; but it seems to be internal to the JDT. I'm using 3.1M5.

I'm going through the AST primarily, because I need information about JDK5 
annotations; but in order to get the fully qualified type of a method 
argument, I'm getting the name of the type of the parameter, then passing 
that to resolveType on the IType of the primary type in the ICompilationUnit 
that I used to build the AST (by passing it to the ASTParser as the source). 
I prefer this to using resolveBindings on the AST because I've found that 
that getting bindings isn't very reliable if there are any source errors.


Essentially my code looks like this:

MethodDeclaration method; // the method I'm looking at
IType mainType; // the first type in the ICompilationUnit
...
// interested in the fourth param, already checked that it exists
SingleVariableDeclaration param = (SingleVariableDeclaration)params.get(3);
Type t = param.getType();
String typeName = ((SimpleType)t).getName().getFullyQualifiedName();
String[][] typeMatches = mainType.resolveType( typeName );


The code that it is looking at looks like this:

public class Controller extends PageFlowController {

    @Jpf.ExceptionHandler()
    protected Forward newExceptionHandler1(Exception ex, String actionName,
            String message, Object form)
    {
        getRequest().setAttribute("errorMessage", message);
        return new Forward("success");
    }
}


Right before getting the type, I have created the above method and its
annotations by using an ASTRewrite, and commiting the text edit to the
ICompilationUnit's buffer. Then I create a new AST, and use it, along with the
same ICompilationUnit, to try to resolve the type.

Most of the time this works, but occasionally I get a ClassCastException:

 java.lang.ClassCastException: 
org.eclipse.jdt.internal.compiler.ast.QualifiedNameReference at 
org.eclipse.jdt.internal.compiler.parser.SourceTypeConverter.convertAnnotations(SourceTypeConverter.java:559)

at 
org.eclipse.jdt.internal.compiler.parser.SourceTypeConverter.convert(SourceTypeConverter.java:340)

at 
org.eclipse.jdt.internal.compiler.parser.SourceTypeConverter.convert(SourceTypeConverter.java:533)

at 
org.eclipse.jdt.internal.compiler.parser.SourceTypeConverter.convert(SourceTypeConverter.java:161)

at 
org.eclipse.jdt.internal.compiler.parser.SourceTypeConverter.buildCompilationUnit(SourceTypeConverter.java:106)

at 
org.eclipse.jdt.internal.codeassist.SelectionEngine.selectType(SelectionEngine.java:1096)

at org.eclipse.jdt.internal.core.SourceType.resolveType(SourceType.java:819) 
at org.eclipse.jdt.internal.core.SourceType.resolveType(SourceType.java:753) 
at com.bea.wlw.netui.core.util.ClassUtil.resolveType(ClassUtil.java:883) at
[ ... ]
Comment 1 Olivier Thomann CLA 2005-04-04 22:42:33 EDT
Could you please try again with M6? I tried to reproduce, but unsuccessfully.
I will add your test case as test0167 in
org.eclipse.jdt.core.tests.dom.ASTConverter15Test. You can review this test to
see if it reproduces your test case.
Comment 2 Tom Stamm CLA 2005-04-05 17:08:10 EDT
(In reply to comment #1)
> Could you please try again with M6? I tried to reproduce, but unsuccessfully.
> I will add your test case as test0167 in
> org.eclipse.jdt.core.tests.dom.ASTConverter15Test. You can review this test to
> see if it reproduces your test case.

My team is still on M5, but I will try this on M6 as soon as I can. I also
wanted to mention that occasionally, instead of the ClassCastException, I get an
NPE from the same call:

java.lang.NullPointerException
	at
org.eclipse.jdt.internal.compiler.parser.SourceTypeConverter.parseMemberValue(SourceTypeConverter.java:806)
	at
org.eclipse.jdt.internal.compiler.parser.SourceTypeConverter.convertAnnotations(SourceTypeConverter.java:558)
	at
org.eclipse.jdt.internal.compiler.parser.SourceTypeConverter.convert(SourceTypeConverter.java:340)
	at
org.eclipse.jdt.internal.compiler.parser.SourceTypeConverter.convert(SourceTypeConverter.java:533)
	at
org.eclipse.jdt.internal.compiler.parser.SourceTypeConverter.convert(SourceTypeConverter.java:161)
	at
org.eclipse.jdt.internal.compiler.parser.SourceTypeConverter.buildCompilationUnit(SourceTypeConverter.java:106)
	at
org.eclipse.jdt.internal.codeassist.SelectionEngine.selectType(SelectionEngine.java:1096)
	at org.eclipse.jdt.internal.core.SourceType.resolveType(SourceType.java:819)
	at org.eclipse.jdt.internal.core.SourceType.resolveType(SourceType.java:753)
	at com.bea.wlw.netui.core.util.ClassUtil.resolveType(ClassUtil.java:887)
[...]
Comment 3 Olivier Thomann CLA 2005-04-05 21:45:04 EDT
If you could attach a test case that I could use to reproduce the problem, it
would be great. I could not reproduce the problem using M6 and the test case you
provided  so far.
Comment 4 Olivier Thomann CLA 2005-04-12 15:20:57 EDT
Could you please provide a test case if you want it fixed for M7?
Comment 5 Tom Stamm CLA 2005-04-20 10:21:23 EDT
Hi, I've been trying to create a smaller testcase (outside of our whole product)
but I can't get it to fail. Also we are stuck on M5 for now because we are
dependent on webtools, which is in the process of moving to M6. I will try to
verify that this is either fixed or still broken as soon as we can get onto M6.
Sorry for the slow response.
Comment 6 Tom Hofmann CLA 2005-04-22 07:03:47 EDT
I just had the excpetion from comment 2 in I20050420, no steps yet.
Comment 7 Olivier Thomann CLA 2005-05-17 13:10:05 EDT
Any news about a potential test case to solve this issue?
Comment 8 Tom Stamm CLA 2005-05-17 13:19:57 EDT
We finally moved our codebase onto M6 last week, and I haven't seen this happen
since then. For now I'm assuming that it has been fixed... (sorry, I'm not sure
of the appropriate status to use)
Comment 9 Olivier Thomann CLA 2005-05-17 13:21:20 EDT
I close it as WORKSFORME.
Please reopen if you get it again.