Community
Participate
Working Groups
Configuration: - Eclipse 3.1.1 - AJDT 1.3.0.20051129155513 Problem Description: Project A defines an interface with static aspect to provide a default implementation: public interface Attributable { void setAttribute(String name, Object attribute); Object getAttribute(String name); static aspect DefImpl { private Map<String,Object> Attributable.attributes = new HashMap<String,Object>(); public void Attributable.setAttribute(String name, Object attribute) { this.attributes.put(name, attribute); } public Object Attributable.getAttribute(String name) { return this.attributes.get(name); } } } Project A generates a JAR that gets used in Project B on both the Java Build Path and the AspectJ Aspect Path. Project B contains the following implementing class: public class AnAttributedClass implements Attributable { public void doSomething() { this.setAttribute("foo", "bar"); } } This results in the compile error "The method setAttribute(String,Object) is ambiguous for the type AnAttributedClass". Please note that using the aspected interface within Project A when implementing classes does not cause said compiler error. With best regards, Christoph Cenowa
Passing over to the compiler
Recreated on the command line: C:\aspectj1.5.0-dev\pr118599>ajc -1.5 -d output Attributable.java C:\aspectj1.5.0-dev\pr118599>ajc -1.5 -aspectpath output AnAttributedClass.java C:\aspectj1.5.0-dev\pr118599\AnAttributedClass.java:4 [error] The method setAttribute(String, Object) is ambiguous for the type AnAttributedClass this.setAttribute("foo", "bar"); ^^^^^^^ 1 error
Some progress. The difference when binary weaving is that we find two method bindings for setAttributes() on the Attributable class. We find the one declared in the interface directly and another is returned from the inter type member finder.
In the 'working' case when everything is compiled together, we go into the 'getMethods()' for the intertypememberfinder attached to the binarytypebinding for the Attributable interface - this asks the sourcetypebinding for 'getMethodsBase("setAttribute")' and gets back null (the methods aren't resolved yet...). (in the failing case there is a method returned). The finder then discovers the ITD and returns it - so only one 'answer' and therefore not reported as ambiguous.
I've just committed a fix for this - the problem was comparing an unresolved method binding with a resolved method binding and discovering that 'Unresolved type String' didnt match 'String'. If the matching fails in the inter type member finder then we don't sort out duplicates correctly in the member finder and so you can end up with two entries for the same method. Fix will be in next AspectJ build and AJDT in a few days.
fix available now in AspectJ.