From a024df9675409344ecdf232d6ac3a283602323d5 Mon Sep 17 00:00:00 2001 From: Andy Clement Date: Fri, 25 May 2018 12:49:56 -0700 Subject: Initial cut at bug 535086 - pertypewithin and non vis types In this version unless you specify an aspect is privileged then the pertypewithin clause will not match types not visible from the aspect (private types or default vis types in another package) Debating whether to change this to not require privileged. --- weaver/src/org/aspectj/weaver/bcel/BcelShadow.java | 17 +++++++++++++---- weaver/src/org/aspectj/weaver/bcel/BcelTypeMunger.java | 4 +++- 2 files changed, 16 insertions(+), 5 deletions(-) (limited to 'weaver/src/org/aspectj') diff --git a/weaver/src/org/aspectj/weaver/bcel/BcelShadow.java b/weaver/src/org/aspectj/weaver/bcel/BcelShadow.java index 6ba22ed97..2e8d3ab6b 100644 --- a/weaver/src/org/aspectj/weaver/bcel/BcelShadow.java +++ b/weaver/src/org/aspectj/weaver/bcel/BcelShadow.java @@ -1129,6 +1129,7 @@ public class BcelShadow extends Shadow { return getThisJoinPointStaticPartBcelVar(false); } + @Override public BcelVar getThisAspectInstanceVar(ResolvedType aspectType) { return new AspectInstanceVar(aspectType); } @@ -1995,16 +1996,24 @@ public class BcelShadow extends Shadow { * Causes the aspect instance to be *set* for later retrievable through localAspectof()/aspectOf() */ public void weavePerTypeWithinAspectInitialization(final BcelAdvice munger, UnresolvedType t) { - - if (t.resolve(world).isInterface()) { - return; // Don't initialize statics in + ResolvedType tResolved = t.resolve(world); + if (tResolved.isInterface()) { + return; // Don't initialize statics in interfaces + } + ResolvedType aspectRT = munger.getConcreteAspect(); + BcelWorld.getBcelObjectType(aspectRT); + + // Although matched, if the visibility rules prevent the aspect from seeing this type, don't + // insert any code (easier to do it here than try to affect the matching logic, unfortunately) + if (!(tResolved.canBeSeenBy(aspectRT) || aspectRT.isPrivilegedAspect())) { + return; } + final InstructionFactory fact = getFactory(); InstructionList entryInstructions = new InstructionList(); InstructionList entrySuccessInstructions = new InstructionList(); - BcelWorld.getBcelObjectType(munger.getConcreteAspect()); String aspectname = munger.getConcreteAspect().getName(); String ptwField = NameMangler.perTypeWithinFieldForTarget(munger.getConcreteAspect()); diff --git a/weaver/src/org/aspectj/weaver/bcel/BcelTypeMunger.java b/weaver/src/org/aspectj/weaver/bcel/BcelTypeMunger.java index c82c352ae..b92760fe9 100644 --- a/weaver/src/org/aspectj/weaver/bcel/BcelTypeMunger.java +++ b/weaver/src/org/aspectj/weaver/bcel/BcelTypeMunger.java @@ -829,7 +829,9 @@ public class BcelTypeMunger extends ConcreteTypeMunger { // e.g ajc$com_blah_SecurityAspect$ptwAspectInstance FieldGen fg = makeFieldGen(gen, AjcMemberMaker.perTypeWithinField(gen.getType(), aspectType)); gen.addField(fg, getSourceLocation()); - + if (!gen.getType().canBeSeenBy(aspectType) && aspectType.isPrivilegedAspect()) { + gen.forcePublic(); + } // Add an accessor for this new field, the // ajc$$localAspectOf() method // e.g. -- cgit v1.2.3