From 87856659869b9dbf72e1b329986fb2d727cfad18 Mon Sep 17 00:00:00 2001 From: Andy Clement Date: Fri, 29 Jul 2016 10:05:50 -0700 Subject: Fix ambiguous binding problem on anonymous types If an anonymous class calls a method ITD'd onto one of its own supertypes (e.g. new A() { xx(null); }) then it can be reported as an ambiguous method invocation on Java8. There is different handling for Java8 that is revealing an issue. The intertype method declarations are recorded in a member finder attached to the target type (A in this case). When the local type binding is built it gets all the methods from supertypes added to it - this unfortunately includes the ITD method. Then later when something asks for all 'xx' methods on A, it finds the ITD method from when A was constructed and an additional copy from the member finder. The quick fix is for the member finder to use a set rather than list when answering 'what are the xx methods'. If this proves a problem down the line the deeper fix would be to avoid including ITDs when the local type binding is built. --- .../internal/compiler/lookup/InterTypeMemberFinder.java | 4 +++- tests/bugs1810/ambig/Code.java | 8 ++++++++ tests/bugs1810/ambig/X.java | 13 +++++++++++++ tests/src/org/aspectj/systemtest/ajc1810/Ajc1810Tests.java | 8 ++++++++ tests/src/org/aspectj/systemtest/ajc1810/ajc1810.xml | 7 +++++++ 5 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 tests/bugs1810/ambig/Code.java create mode 100644 tests/bugs1810/ambig/X.java diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/InterTypeMemberFinder.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/InterTypeMemberFinder.java index 97221b2aa..9784710f4 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/InterTypeMemberFinder.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/InterTypeMemberFinder.java @@ -16,8 +16,10 @@ package org.aspectj.ajdt.internal.compiler.lookup; import java.lang.reflect.Modifier; import java.util.ArrayList; import java.util.Arrays; +import java.util.HashSet; import java.util.Iterator; import java.util.List; +import java.util.Set; import org.aspectj.org.eclipse.jdt.core.compiler.CharOperation; import org.aspectj.org.eclipse.jdt.core.compiler.IProblem; @@ -298,7 +300,7 @@ public class InterTypeMemberFinder implements IMemberFinder { return orig; } - List ret = new ArrayList(Arrays.asList(orig)); + Set ret = new HashSet(Arrays.asList(orig)); // System.err.println("declared method: " + ret + " inters = " + interTypeMethods); for (int i = 0, len = interTypeMethods.size(); i < len; i++) { diff --git a/tests/bugs1810/ambig/Code.java b/tests/bugs1810/ambig/Code.java new file mode 100644 index 000000000..dab8d6f09 --- /dev/null +++ b/tests/bugs1810/ambig/Code.java @@ -0,0 +1,8 @@ +import java.util.List; + +aspect F { void A.xx(List x) { xx(null);this.xx(null);};} +class A {} +class B extends A { void xx(List x) { xx(null); this.xx(null); super.xx(null); }} +class C implements D { public void xx(List x) { xx(null); new A().xx(null); new B().xx(null); }} +interface D { void xx(List x); } +class E { void foo() { new B().xx(null); new A() {}.xx(null); } } diff --git a/tests/bugs1810/ambig/X.java b/tests/bugs1810/ambig/X.java new file mode 100644 index 000000000..6f0a73d97 --- /dev/null +++ b/tests/bugs1810/ambig/X.java @@ -0,0 +1,13 @@ +import java.util.List; + +aspect F { + void A.xx(List x) { } +} +class A { + //void xx(List x) {} +} +class E { + void foo() { + new A() {}.xx(null); + } +} diff --git a/tests/src/org/aspectj/systemtest/ajc1810/Ajc1810Tests.java b/tests/src/org/aspectj/systemtest/ajc1810/Ajc1810Tests.java index cff7a3b7b..3af4bb79c 100644 --- a/tests/src/org/aspectj/systemtest/ajc1810/Ajc1810Tests.java +++ b/tests/src/org/aspectj/systemtest/ajc1810/Ajc1810Tests.java @@ -34,6 +34,14 @@ public class Ajc1810Tests extends org.aspectj.testing.XMLBasedAjcTestCase { runTest("indy"); } + public void testAmbigMessage17() throws Exception { + runTest("ambiguous message - 17"); + } + + public void testAmbigMessage18() throws Exception { + runTest("ambiguous message - 18"); + } + // http://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.7.6 public void testInnerClassesAttributeStructure_493554() throws Exception { runTest("pertarget"); diff --git a/tests/src/org/aspectj/systemtest/ajc1810/ajc1810.xml b/tests/src/org/aspectj/systemtest/ajc1810/ajc1810.xml index dd4237d22..e53b8aabe 100644 --- a/tests/src/org/aspectj/systemtest/ajc1810/ajc1810.xml +++ b/tests/src/org/aspectj/systemtest/ajc1810/ajc1810.xml @@ -11,5 +11,12 @@ + + + + + + + -- cgit v1.2.3