Bug 10679 - ClassCastException when calling resolveTypeBinding() with an error
Summary: ClassCastException when calling resolveTypeBinding() with an error
Status: RESOLVED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 2.0   Edit
Hardware: PC Windows NT
: P3 normal (vote)
Target Milestone: 2.0 M4   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-03-04 10:36 EST by Luc Bourlier CLA
Modified: 2021-02-13 02:54 EST (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 Luc Bourlier CLA 2002-03-04 10:36:40 EST
When an Expression is passed into DefaultBindingResolver.resolveTypeBinding()
that contains an error, a ClassCastException is thrown from this code:
else if (expression instanceof Name) {
  IBinding binding = this.resolveName((Name) expression);
  if (binding == null) {
    return null;
  }
  switch(binding.getKind()) {
    case IBinding.TYPE :
      return (ITypeBinding) binding;
    case IBinding.VARIABLE :
      return ((IVariableBinding) binding).getType();
  }

The problem is that the binding returned is a ProblemBinding, which returns
IBinding.VARIABLE as its kind (when queried via getKind()). However,
ProblemBinding cannot be cast to an IVariableBinding.

An example of code that would cause this problem is:
public class A {
  public int foo(int variable) {
    return varble; // <-- Unable to resolve binding here
  }
}
Comment 1 Olivier Thomann CLA 2002-03-04 12:20:47 EST
Ok, this is a bug, but you should not resolve any binding if you have errors 
reported on the CompilationUnit. In this case, the method getMessages() on 
CompilationUnit returns a list of messages which is not empty.
If you have errors during the resolution, the resolution of ast node can fail. 
However I will fix this. We should fail returning null and not an uncaught 
exception.
Comment 2 Olivier Thomann CLA 2002-03-04 12:44:36 EST
Fixed.