Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 341695 - IMethodBinding#getJavaElement() returns incorrect result in case of method overloading and type shadowing
Summary: IMethodBinding#getJavaElement() returns incorrect result in case of method ov...
Status: CLOSED DUPLICATE of bug 275853
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.7   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-04-02 08:15 EDT by Andreas Thies CLA
Modified: 2011-04-02 14:39 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 Andreas Thies CLA 2011-04-02 08:15:41 EDT
Build Identifier: M20100909-0800

In case of two methods with same name and equally named (but different) parameter types IMethodBinding#getJavaElement returns incorrectly the same IJavaElement for both methods.

Reproducible: Always

Steps to Reproduce:
1. Create a java project with the following classes:

package a;
public class A {}

package b;
public class A {}

package y;
import b.A;
public class Y {
	public void m(a.A a) {}
	public void m(A a) {}
}

2. Run the following code within an eclipse plugin

ICompilationUnit icu = (ICompilationUnit) JavaCore.create("=TestProject/src<y{Y.java");

ASTParser parser = ASTParser.newParser(AST.JLS3);
parser.setKind(ASTParser.K_COMPILATION_UNIT);
parser.setSource(icu); 
parser.setResolveBindings(true);
CompilationUnit cu = (CompilationUnit) parser.createAST(null);

final List<MethodDeclaration> mds = new ArrayList<MethodDeclaration>(2);

cu.accept(new ASTVisitor() {
  @Override
  public boolean visit(MethodDeclaration methodDeclaration) {
    mds.add(methodDeclaration);
    return super.visit(methodDeclaration);
  }
});

MethodDeclaration md1 = mds.get(0);
MethodDeclaration md2 = mds.get(1);

IMethodBinding binding1 = md1.resolveBinding();
IMethodBinding binding2 = md2.resolveBinding();

IJavaElement javaElement1 = binding1.getJavaElement();
IJavaElement javaElement2 = binding2.getJavaElement();

System.out.println(md1.equals(md2)); // false
System.out.println(binding1.equals(binding2)); // false

// should be false, but is true
System.out.println(javaElement1.equals(javaElement2));
    
// is =TestProject/src<y{B.java[B~m~Qa.A;
System.out.println(javaElement1.getHandleIdentifier()); // =TestProject/src<y{B.java[B~m~Qa.A;

// is =TestProject/src<y{B.java[B~m~Qa.A; but should be =TestProject/src<y{Y.java[Y~m~QA;
System.out.println(javaElement2.getHandleIdentifier()); // =TestProject/src<y{B.java[B~m~Qa.A;
Comment 1 Olivier Thomann CLA 2011-04-02 14:39:42 EDT

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