Community
Participate
Working Groups
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 [ ... ]
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.
(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) [...]
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.
Could you please provide a test case if you want it fixed for M7?
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.
I just had the excpetion from comment 2 in I20050420, no steps yet.
Any news about a potential test case to solve this issue?
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)
I close it as WORKSFORME. Please reopen if you get it again.