]> source.dussan.org Git - aspectj.git/commitdiff
307147: missing joinpoints for itds invoking private methods
authorAndy Clement <aclement@pivotal.io>
Thu, 3 Sep 2015 21:19:10 +0000 (14:19 -0700)
committerAndy Clement <aclement@pivotal.io>
Thu, 3 Sep 2015 21:19:10 +0000 (14:19 -0700)
tests/bugs187/307147/ITDAspect.aj [new file with mode: 0644]
tests/bugs187/307147/Test.java [new file with mode: 0644]
tests/bugs187/307147/TestAspect.aj [new file with mode: 0644]
tests/bugs187/307147_2/ITDAspect.aj [new file with mode: 0644]
tests/bugs187/307147_2/Test.java [new file with mode: 0644]
tests/bugs187/307147_2/TestAspect.aj [new file with mode: 0644]
tests/src/org/aspectj/systemtest/ajc187/Ajc187Tests.java
tests/src/org/aspectj/systemtest/ajc187/ajc187.xml
weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java
weaver/src/org/aspectj/weaver/bcel/BcelTypeMunger.java
weaver/src/org/aspectj/weaver/bcel/BcelWorld.java

diff --git a/tests/bugs187/307147/ITDAspect.aj b/tests/bugs187/307147/ITDAspect.aj
new file mode 100644 (file)
index 0000000..5442a58
--- /dev/null
@@ -0,0 +1,11 @@
+package test;
+
+import test.Test;
+
+public privileged aspect ITDAspect {
+       public void Test.itdFunction() {
+               System.out.println("ITD function");
+               privateMethod();
+               publicMethod();
+       }
+}
diff --git a/tests/bugs187/307147/Test.java b/tests/bugs187/307147/Test.java
new file mode 100644 (file)
index 0000000..25b4eef
--- /dev/null
@@ -0,0 +1,28 @@
+package test;
+
+public class Test {
+
+       public Test() {
+       }
+       
+       public static void main(String[] args) {
+               Test t = new Test();
+               t.function();
+               t.itdFunction();
+       }
+       
+       public void function() {
+               System.out.println("Normal function");
+               privateMethod();
+               publicMethod();
+       }
+       
+       private void privateMethod() {
+               System.out.println("private method");
+       }
+       
+       public void publicMethod() {
+               System.out.println("public method");
+       }
+
+}
diff --git a/tests/bugs187/307147/TestAspect.aj b/tests/bugs187/307147/TestAspect.aj
new file mode 100644 (file)
index 0000000..cf53868
--- /dev/null
@@ -0,0 +1,8 @@
+package test;
+
+public aspect TestAspect {
+       Object around(): call(* Test.*(..)) {
+               System.out.println("Around " + thisJoinPoint.toString());
+               return proceed();
+       }
+}
diff --git a/tests/bugs187/307147_2/ITDAspect.aj b/tests/bugs187/307147_2/ITDAspect.aj
new file mode 100644 (file)
index 0000000..c3e22ee
--- /dev/null
@@ -0,0 +1,10 @@
+package test;
+
+import test.Test;
+
+public privileged aspect ITDAspect {
+       public void Test.itdFunction() {
+               System.out.println("ITD function");
+               privateMethod("Foo");
+       }
+}
diff --git a/tests/bugs187/307147_2/Test.java b/tests/bugs187/307147_2/Test.java
new file mode 100644 (file)
index 0000000..fe184df
--- /dev/null
@@ -0,0 +1,16 @@
+package test;
+
+public class Test {
+
+       public Test() {
+       }
+       
+       public static void main(String[] args) {
+               Test t = new Test();
+               t.itdFunction();
+       }
+       
+       private void privateMethod(String xxx) {
+               System.out.println("hello "+xxx);
+       }
+}
diff --git a/tests/bugs187/307147_2/TestAspect.aj b/tests/bugs187/307147_2/TestAspect.aj
new file mode 100644 (file)
index 0000000..24cef6c
--- /dev/null
@@ -0,0 +1,9 @@
+package test;
+
+public aspect TestAspect {
+       Object around(String s): call(* Test.*(..)) && args(s) {
+               System.out.println("Around " + thisJoinPoint.toString());
+               System.out.println("Captured "+s);
+               return proceed(s.toUpperCase());
+       }
+}
index ece3240e0718d0412304a82075c35673694e5a0b..3fce314bd73ce4a805e4e314def98b320ab4b6fb 100644 (file)
@@ -24,6 +24,14 @@ import org.aspectj.testing.XMLBasedAjcTestCase;
  */
 public class Ajc187Tests extends org.aspectj.testing.XMLBasedAjcTestCase {
 
+       public void testMissingJoinpoint_307147() throws Exception {
+               runTest("missing joinpoint");
+       }
+
+       public void testMissingJoinpoint_307147_2() throws Exception {
+               runTest("missing joinpoint 2");
+       }
+       
        public void testInfiniteLoop_475152() throws Exception {
                runTest("infinite loop");
        }
index e6db6d5e51ea5483db1070d065c08d6b68d6de38..19706f43a70def965a45b73c23cf96e98988054d 100644 (file)
@@ -2,6 +2,36 @@
 
 <suite>
 
+<ajc-test dir="bugs187/307147" title="missing joinpoint">
+<compile files="Test.java TestAspect.aj ITDAspect.aj" options="-1.8"/>
+<run class="test.Test">
+<stdout>
+<line text="Around call(void test.Test.function())"/>
+<line text="Normal function"/>
+<line text="Around call(void test.Test.privateMethod())"/>
+<line text="private method"/>
+<line text="Around call(void test.Test.publicMethod())"/>
+<line text="public method"/>
+<line text="Around call(void test.Test.itdFunction())"/>
+<line text="ITD function"/>
+<line text="Around call(void test.Test.privateMethod())"/>
+<line text="private method"/>
+<line text="Around call(void test.Test.publicMethod())"/>
+<line text="public method"/>
+</stdout></run>
+</ajc-test>
+
+<ajc-test dir="bugs187/307147_2" title="missing joinpoint 2">
+<compile files="Test.java TestAspect.aj ITDAspect.aj" options="-1.8"/>
+<run class="test.Test">
+<stdout>
+<line text="ITD function"/>
+<line text="Around call(void test.Test.privateMethod(String))"/>
+<line text="Captured Foo"/>
+<line text="hello FOO"/>
+</stdout></run>
+</ajc-test>
+
 <ajc-test dir="bugs187/475152" title="infinite loop">
 <compile files="AbstractAspect.aj, BaseAspect.aj, TestClass.java, AjTarget.java, TestAspect.aj" options="-1.8"/>
 </ajc-test>
index 88b1090c2a99831120e3dfdc23203bae5a0a6608..b4eaa3dd4eb381157a87fae6dc7906f2661ca11a 100644 (file)
@@ -3209,6 +3209,13 @@ class BcelClassWeaver implements IClassWeaver {
                                if (canMatch(Shadow.FieldGet) || canMatch(Shadow.FieldSet)) {
                                        match(BcelShadow.makeShadowForMethodCall(world, mg, ih, enclosingShadow, kind, declaredSig), shadowAccumulator);
                                }
+                       } else if (!declaredSig.getName().startsWith(NameMangler.PREFIX)) {
+                               // 307147 - resolution above may have found the real method directly rather
+                               // than needing to go through the effective signature attribute
+                               if (canMatch(Shadow.MethodCall)) {
+                                       match(BcelShadow.makeShadowForMethodCall(world, mg, ih, enclosingShadow, Shadow.MethodCall, declaredSig),
+                                                       shadowAccumulator);
+                               }
                        } else {
                                AjAttribute.EffectiveSignatureAttribute effectiveSig = declaredSig.getEffectiveSignature();
                                if (effectiveSig == null) {
index 9e5b6a210ce95057811aef4a1fc9b0a6edad00df..7a637bb2d2fef7dd1b521aa942b3841be156fc37 100644 (file)
@@ -44,6 +44,7 @@ import org.aspectj.bridge.MessageUtil;
 import org.aspectj.bridge.WeaveMessage;
 import org.aspectj.bridge.context.CompilationAndWeavingContext;
 import org.aspectj.bridge.context.ContextToken;
+import org.aspectj.weaver.AjAttribute;
 import org.aspectj.weaver.AjcMemberMaker;
 import org.aspectj.weaver.AnnotationAJ;
 import org.aspectj.weaver.AnnotationOnTypeMunger;
index 4f0dfe1bc0ac2db956656de02e99d16bd88365bc..de9e29aba16b67bf89d8fad91267896abea00c0a 100644 (file)
@@ -630,6 +630,32 @@ public class BcelWorld extends World implements Repository {
                UnresolvedType declaringType = null;
 
                String signature = ii.getSignature(cpg);
+               
+               // 307147
+               if (name.startsWith("ajc$privMethod$")) {
+                       // The invoke is on a privileged accessor. These may be created for different
+                       // kinds of target, not necessarily just private methods. In bug 307147 it is
+                       // for a private method. This code is identifying the particular case in 307147
+                       try {
+                               declaringType = UnresolvedType.forName(declaring);
+                               String typeNameAsFoundInAccessorName = declaringType.getName().replace('.', '_');
+                               int indexInAccessorName = name.lastIndexOf(typeNameAsFoundInAccessorName);
+                               if (indexInAccessorName != -1) {
+                                       String methodName = name.substring(indexInAccessorName+typeNameAsFoundInAccessorName.length()+1);
+                                       ResolvedType resolvedDeclaringType = declaringType.resolve(this);
+                                       ResolvedMember[] methods = resolvedDeclaringType.getDeclaredMethods();
+                                       for (ResolvedMember method: methods) {
+                                               if (method.getName().equals(methodName) && method.getSignature().equals(signature) && Modifier.isPrivate(method.getModifiers())) {
+                                                       return method;
+                                               }
+                                       }
+                               }
+                       } catch (Exception e) {
+                               // Remove this once confident above code isn't having unexpected side effects
+                               // Added 1.8.7
+                               e.printStackTrace();
+                       }
+               }
 
                int modifier = (ii instanceof INVOKEINTERFACE) ? Modifier.INTERFACE
                                : (ii.opcode == Constants.INVOKESTATIC) ? Modifier.STATIC : (ii.opcode == Constants.INVOKESPECIAL && !name