Skip to main content



      Home
Home » Language IDEs » Java Development Tools (JDT) » ClassCastException calling IType.resolveType()
ClassCastException calling IType.resolveType() [message #199994] Fri, 01 April 2005 10:27 Go to next message
Eclipse UserFriend
Hi, 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; if it's a bug or if I'm doing something wrong.

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 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 first param, already checked that it exists
SingleVariableDeclaration param = (SingleVariableDeclaration)params.get(0);
Type t = param.getType();
String typeName = ((SimpleType)t).getName().getFullyQualifiedName();
String[][] typeMatches = mainType.resolveType( typeName );


Most of the time this works, but occasionally I get a ClassCastException
(pasted below). Any ideas? Could this be a timing issue, where the AST was
built, and while I'm using it, the ICompilationUnit model changed for some
reason? I'm not holding onto the AST's that I build, so I don't think this
should be happening.

here's the exception stacktrace:

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.selectTy pe(SelectionEngine.java:1096)
at org.eclipse.jdt.internal.core.SourceType.resolveType(SourceT ype.java:819)
at org.eclipse.jdt.internal.core.SourceType.resolveType(SourceT ype.java:753)
at com.bea.wlw.netui.core.util.ClassUtil.resolveType(ClassUtil. java:883) at
[ ... ]
Re: ClassCastException calling IType.resolveType() [message #200001 is a reply to message #199994] Fri, 01 April 2005 10:29 Go to previous messageGo to next message
Eclipse UserFriend
Sorry, I meant to add that I'm using eclipse 3.1M5, with compiler compliance
set to JDK5.

thanks,
-Tom

"Tom Stamm" <stammt@bea.com> wrote in message
news:d2jpcr$hpa$1@news.eclipse.org...
> Hi, 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; if it's a bug or if I'm doing
> something wrong.
>
> 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 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 first param, already checked that it exists
> SingleVariableDeclaration param =
> (SingleVariableDeclaration)params.get(0);
> Type t = param.getType();
> String typeName = ((SimpleType)t).getName().getFullyQualifiedName();
> String[][] typeMatches = mainType.resolveType( typeName );
>
>
> Most of the time this works, but occasionally I get a ClassCastException
> (pasted below). Any ideas? Could this be a timing issue, where the AST was
> built, and while I'm using it, the ICompilationUnit model changed for some
> reason? I'm not holding onto the AST's that I build, so I don't think this
> should be happening.
>
> here's the exception stacktrace:
>
> 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.selectTy pe(SelectionEngine.java:1096)
> at
> org.eclipse.jdt.internal.core.SourceType.resolveType(SourceT ype.java:819)
> at
> org.eclipse.jdt.internal.core.SourceType.resolveType(SourceT ype.java:753)
> at com.bea.wlw.netui.core.util.ClassUtil.resolveType(ClassUtil. java:883)
> at
> [ ... ]
>
Re: ClassCastException calling IType.resolveType() [message #200017 is a reply to message #200001] Fri, 01 April 2005 12:38 Go to previous message
Eclipse UserFriend
Hi Tom, please use bugzilla to file bugs:
https://bugs.eclipse.org/bugs/

This one would go to JDT/Core. Try to include as much context as you can
(i.e. what code do you process when this happens).

Thanks,
Markus

Tom Stamm wrote:

> Sorry, I meant to add that I'm using eclipse 3.1M5, with compiler compliance
> set to JDK5.
>
> thanks,
> -Tom
>
> "Tom Stamm" <stammt@bea.com> wrote in message
> news:d2jpcr$hpa$1@news.eclipse.org...
>
>>Hi, 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; if it's a bug or if I'm doing
>>something wrong.
>>
>>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 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 first param, already checked that it exists
>>SingleVariableDeclaration param =
>>(SingleVariableDeclaration)params.get(0);
>>Type t = param.getType();
>>String typeName = ((SimpleType)t).getName().getFullyQualifiedName();
>>String[][] typeMatches = mainType.resolveType( typeName );
>>
>>
>>Most of the time this works, but occasionally I get a ClassCastException
>>(pasted below). Any ideas? Could this be a timing issue, where the AST was
>>built, and while I'm using it, the ICompilationUnit model changed for some
>>reason? I'm not holding onto the AST's that I build, so I don't think this
>>should be happening.
>>
>>here's the exception stacktrace:
>>
>>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.selectTy pe(SelectionEngine.java:1096)
>>at
>> org.eclipse.jdt.internal.core.SourceType.resolveType(SourceT ype.java:819)
>>at
>> org.eclipse.jdt.internal.core.SourceType.resolveType(SourceT ype.java:753)
>>at com.bea.wlw.netui.core.util.ClassUtil.resolveType(ClassUtil. java:883)
>>at
>>[ ... ]
>>
>
>
>
Previous Topic:Compiling non .java source files
Next Topic:Repost: Listening to changes in JDT java model - IJavaElementDelta
Goto Forum:
  


Current Time: Wed Sep 17 04:07:16 EDT 2025

Powered by FUDForum. Page generated in 0.03487 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top