Bug 118599 - Ambiguous method error when weaving in binary aspects
Summary: Ambiguous method error when weaving in binary aspects
Status: RESOLVED FIXED
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: DEVELOPMENT   Edit
Hardware: PC Windows XP
: P3 major (vote)
Target Milestone: 1.5.0RC1   Edit
Assignee: Andrew Clement CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-11-30 03:55 EST by Christoph Cenowa CLA
Modified: 2005-12-01 10:15 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Christoph Cenowa CLA 2005-11-30 03:55:48 EST
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
Comment 1 Matt Chapman CLA 2005-11-30 09:08:27 EST
Passing over to the compiler
Comment 2 Andrew Clement CLA 2005-11-30 09:26:16 EST
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
Comment 3 Andrew Clement CLA 2005-12-01 05:53:39 EST
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.
Comment 4 Andrew Clement CLA 2005-12-01 05:59:47 EST
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.

Comment 5 Andrew Clement CLA 2005-12-01 07:06:36 EST
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.
Comment 6 Andrew Clement CLA 2005-12-01 10:15:08 EST
fix available now in AspectJ.