Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 120471

Summary: ITypeBinding.isAssignable(ITypeBinding) does not work if types came from different universe
Product: [Eclipse Project] JDT Reporter: Theodora Yeung <tyeung>
Component: CoreAssignee: JDT-Core-Inbox <jdt-core-inbox>
Status: CLOSED DUPLICATE QA Contact:
Severity: normal    
Priority: P3 CC: aalves, jgarms, markus.kell.r, thanson
Version: 3.1.1   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description Theodora Yeung CLA 2005-12-12 19:12:36 EST
public ITypeBinding getTypeBinding(final String bindingKey){
   final ASTParser parser = ASTParser.newParser(AST.JLS3);
   parser.setResolveBindings(true);
   parser.setProject(<java project>);
   parser.createASTs(new ICompilationUnit[]{}, new String[]{bindingKey}, <some non-null requestor>, null);
}

public boolean isAssignableTest(){
   final String collectionKey = 
BindingKey.createTypeBindingKey("java.util.Collection");
   final ITypeBinding type0 = getTypeBinding(collectionKey); 
   final ITypeBinding type1 = getTypeBinding(collectionKey);
			System.err.println("t0 assignable to t1 ? " + type0.isAssignmentCompatible(type1));
			System.err.println("t1 assignable to t2 ? " + type1.isAssignmentCompatible(type0));
}
Comment 1 Theodora Yeung CLA 2005-12-12 19:17:38 EST
(sorry hit the commit key too early by mistake)

public ITypeBinding getTypeBinding(final String bindingKey){
   final ASTParser parser = ASTParser.newParser(AST.JLS3);
   parser.setResolveBindings(true);
   parser.setProject(<java project>);
   parser.createASTs(new ICompilationUnit[]{}, new String[]{bindingKey}, <some
non-null requestor>, null);
}

public boolean isAssignableTest(){
   final String collectionKey = 
      BindingKey.createTypeBindingKey("java.util.Collection");
   final ITypeBinding type0 = getTypeBinding(collectionKey); 
   final ITypeBinding type1 = getTypeBinding(collectionKey);
   return type0.isAssignmentCompatible(type1);
}

The call to isAssignableTest() will always return false even though the type theoretically is the same type (both being java.util.Collection). The problem here being type0 and type1 came from two completely different type binding universe and == comparison as well .equals() will always return false.

This presents a huge problem to user since the binding universe is an implementation detail that is not exposed and not documented in the API. To a user, this just looks like a bug.
Comment 2 Markus Keller CLA 2010-08-11 06:15:12 EDT

*** This bug has been marked as a duplicate of bug 80715 ***