From f44dc75e6b0e9a80b41dce7b43fa1a393a4a2adb Mon Sep 17 00:00:00 2001 From: Alexander Kriegisch Date: Sat, 5 Aug 2023 12:15:37 +0700 Subject: [PATCH] Fix inline accessor method bug in BcelAccessForInlineMunger Make sure to create one ajc$inlineAccessMethod per identically named (overloaded) private aspect method in BcelAccessForInlineMunger.createOrGetInlineAccessorForMethod. Fixes #250. Signed-off-by: Alexander Kriegisch --- .../ataspectj/AroundInlineMungerTestAspects.java | 8 +++++--- .../weaver/bcel/BcelAccessForInlineMunger.java | 14 +++++++++----- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/tests/java5/ataspectj/ataspectj/AroundInlineMungerTestAspects.java b/tests/java5/ataspectj/ataspectj/AroundInlineMungerTestAspects.java index 8eb1dca07..baeac0f72 100644 --- a/tests/java5/ataspectj/ataspectj/AroundInlineMungerTestAspects.java +++ b/tests/java5/ataspectj/ataspectj/AroundInlineMungerTestAspects.java @@ -23,7 +23,9 @@ import org.aspectj.lang.ProceedingJoinPoint; public class AroundInlineMungerTestAspects { public static class OpenBase { - protected void superMethod() {} + protected String superMethod(String s) { + return s; + } } public static class OpenSubBase extends OpenBase {} @@ -43,7 +45,7 @@ public class AroundInlineMungerTestAspects { public Object around1(ProceedingJoinPoint jp) throws Throwable { aroundCount++; priv(1, 2L, 3); - super.superMethod(); + super.superMethod("x"); new Open.Inner().priv();//fails to be wrapped so this advice will not be inlined but previous call were still prepared return jp.proceed(); } @@ -64,7 +66,7 @@ public class AroundInlineMungerTestAspects { @SuppressAjWarnings public Object around2(ProceedingJoinPoint jp) throws Throwable { aroundCount++; - super.superMethod(); + super.superMethod("x"); new Open.Inner().priv();//fails to be wrapped so next calls won't be prepared but previous was priv(1, 2L, 3); return jp.proceed(); diff --git a/weaver/src/main/java/org/aspectj/weaver/bcel/BcelAccessForInlineMunger.java b/weaver/src/main/java/org/aspectj/weaver/bcel/BcelAccessForInlineMunger.java index 6bc5cb4a0..3736353b2 100644 --- a/weaver/src/main/java/org/aspectj/weaver/bcel/BcelAccessForInlineMunger.java +++ b/weaver/src/main/java/org/aspectj/weaver/bcel/BcelAccessForInlineMunger.java @@ -101,7 +101,11 @@ public class BcelAccessForInlineMunger extends BcelTypeMunger { */ @Override public ResolvedMember getMatchingSyntheticMember(Member member) { - ResolvedMember rm = inlineAccessors.get(member.getName());// + member.getSignature()); + String name = member.getName(); + String signature = name.startsWith("ajc$superDispatch$") + ? member.getSignature() + : member.getSignature().replaceFirst("\\([^;]+;", "("); + ResolvedMember rm = inlineAccessors.get(name + signature); // System.err.println("lookup for " + member.getName() + ":" + member.getSignature() + " = " // + (rm == null ? "" : rm.getName())); return rm; @@ -229,7 +233,7 @@ public class BcelAccessForInlineMunger extends BcelTypeMunger { private ResolvedMember createOrGetInlineAccessorForMethod(ResolvedMember resolvedMember) { String accessorName = NameMangler.inlineAccessMethodForMethod(resolvedMember.getName(), resolvedMember.getDeclaringType(), aspectType); - String key = accessorName;// new StringBuilder(accessorName).append(resolvedMember.getSignature()).toString(); + String key = accessorName + resolvedMember.getSignature(); ResolvedMember inlineAccessor = inlineAccessors.get(key); // System.err.println(key + " accessor=" + inlineAccessor); if (inlineAccessor == null) { @@ -272,7 +276,7 @@ public class BcelAccessForInlineMunger extends BcelTypeMunger { private ResolvedMember createOrGetInlineAccessorForSuperDispatch(ResolvedMember resolvedMember) { String accessor = NameMangler.superDispatchMethod(aspectType, resolvedMember.getName()); - String key = accessor; + String key = accessor + resolvedMember.getSignature(); ResolvedMember inlineAccessor = inlineAccessors.get(key); if (inlineAccessor == null) { @@ -316,7 +320,7 @@ public class BcelAccessForInlineMunger extends BcelTypeMunger { private ResolvedMember createOrGetInlineAccessorForFieldGet(ResolvedMember resolvedMember) { String accessor = NameMangler.inlineAccessMethodForFieldGet(resolvedMember.getName(), resolvedMember.getDeclaringType(), aspectType); - String key = accessor; + String key = accessor + "()" + resolvedMember.getSignature(); ResolvedMember inlineAccessor = inlineAccessors.get(key); if (inlineAccessor == null) { @@ -357,7 +361,7 @@ public class BcelAccessForInlineMunger extends BcelTypeMunger { private ResolvedMember createOrGetInlineAccessorForFieldSet(ResolvedMember resolvedMember) { String accessor = NameMangler.inlineAccessMethodForFieldSet(resolvedMember.getName(), resolvedMember.getDeclaringType(), aspectType); - String key = accessor; + String key = accessor + "(" + resolvedMember.getSignature() + ")V"; ResolvedMember inlineAccessor = inlineAccessors.get(key); if (inlineAccessor == null) { -- 2.39.5