diff options
-rw-r--r-- | tests/ajcTests.xml | 6 | ||||
-rw-r--r-- | tests/ajcTestsFailing.xml | 6 | ||||
-rw-r--r-- | weaver/src/org/aspectj/weaver/ResolvedMember.java | 5 | ||||
-rw-r--r-- | weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java | 53 | ||||
-rw-r--r-- | weaver/src/org/aspectj/weaver/bcel/BcelField.java | 17 | ||||
-rw-r--r-- | weaver/src/org/aspectj/weaver/bcel/BcelMethod.java | 2 |
6 files changed, 70 insertions, 19 deletions
diff --git a/tests/ajcTests.xml b/tests/ajcTests.xml index a7c73d20d..5cccbc37b 100644 --- a/tests/ajcTests.xml +++ b/tests/ajcTests.xml @@ -6456,4 +6456,10 @@ <compile files="CloneMethod.java"/> <run class="CloneMethod"/> </ajc-test> + + <ajc-test dir="bugs" pr="39711" + title="Class Literals as non final fields (also assert, and this$0)"> + <compile files="ClassLiteralField.java" options="-source14"/> + <run class="ClassLiteralField"/> + </ajc-test> </suite> diff --git a/tests/ajcTestsFailing.xml b/tests/ajcTestsFailing.xml index cd8e52f6e..ddc6cc1dd 100644 --- a/tests/ajcTestsFailing.xml +++ b/tests/ajcTestsFailing.xml @@ -4,9 +4,5 @@ <!-- contains valid tests that the compiler has never passed --> <suite> - <ajc-test dir="bugs" pr="39711" - title="Class Literals as non final fields (also assert, and this$0)"> - <compile files="ClassLiteralField.java" options="-source14"/> - <run class="ClassLiteralField"/> - </ajc-test> + </suite> diff --git a/weaver/src/org/aspectj/weaver/ResolvedMember.java b/weaver/src/org/aspectj/weaver/ResolvedMember.java index b457db0b4..60164e167 100644 --- a/weaver/src/org/aspectj/weaver/ResolvedMember.java +++ b/weaver/src/org/aspectj/weaver/ResolvedMember.java @@ -88,6 +88,10 @@ public class ResolvedMember extends Member implements IHasPosition { return true; } + public boolean isSynthetic() { + return false; + } + public void write(DataOutputStream s) throws IOException { getKind().write(s); getDeclaringType().write(s); @@ -194,6 +198,5 @@ public class ResolvedMember extends Member implements IHasPosition { public void setCheckedExceptions(TypeX[] checkedExceptions) { this.checkedExceptions = checkedExceptions; } - } diff --git a/weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java b/weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java index 97c8fbdae..5595b45db 100644 --- a/weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java +++ b/weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java @@ -833,9 +833,7 @@ class BcelClassWeaver implements IClassWeaver { Instruction i = ih.getInstruction(); if (i instanceof FieldInstruction) { FieldInstruction fi = (FieldInstruction) i; - - - + if (i instanceof PUTFIELD || i instanceof PUTSTATIC) { // check for sets of constant fields. We first check the previous // instruction. If the previous instruction is a LD_WHATEVER (push @@ -852,19 +850,13 @@ class BcelClassWeaver implements IClassWeaver { // it's final, so it's the set of a final constant, so it's // not a join point according to 1.0.6 and 1.1. } else { - match( - BcelShadow.makeFieldSet(world, mg, ih, enclosingShadow), - shadowAccumulator); + matchSetInstruction(mg, ih, enclosingShadow, shadowAccumulator); } } else { - match( - BcelShadow.makeFieldSet(world, mg, ih, enclosingShadow), - shadowAccumulator); + matchSetInstruction(mg, ih, enclosingShadow, shadowAccumulator); } } else { - match( - BcelShadow.makeFieldGet(world, mg, ih, enclosingShadow), - shadowAccumulator); + matchGetInstruction(mg, ih, enclosingShadow, shadowAccumulator); } } else if (i instanceof InvokeInstruction) { InvokeInstruction ii = (InvokeInstruction) i; @@ -907,6 +899,43 @@ class BcelClassWeaver implements IClassWeaver { } } + + private void matchSetInstruction(LazyMethodGen mg, InstructionHandle ih, BcelShadow enclosingShadow, List shadowAccumulator) { + FieldInstruction fi = (FieldInstruction) ih.getInstruction(); + Member field = world.makeFieldSignature(clazz, fi); + ResolvedMember resolvedField = field.resolve(world); + if (resolvedField == null) { + // we can't find the field, so it's not a join point. + return; + } else if (Modifier.isFinal(resolvedField.getModifiers()) && + Utility.isConstantPushInstruction(ih.getPrev().getInstruction())) + { + // it's the set of a final constant, so it's + // not a join point according to 1.0.6 and 1.1. + return; + } else if (resolvedField.isSynthetic()) { + // sets of synthetics aren't join points in 1.1 + return; + } else { + match(BcelShadow.makeFieldSet(world, mg, ih, enclosingShadow), shadowAccumulator); + } + } + + private void matchGetInstruction(LazyMethodGen mg, InstructionHandle ih, BcelShadow enclosingShadow, List shadowAccumulator) { + FieldInstruction fi = (FieldInstruction) ih.getInstruction(); + Member field = world.makeFieldSignature(clazz, fi); + ResolvedMember resolvedField = field.resolve(world); + if (resolvedField == null) { + // we can't find the field, so it's not a join point. + return; + } else if (resolvedField.isSynthetic()) { + // sets of synthetics aren't join points in 1.1 + return; + } else { + match(BcelShadow.makeFieldGet(world, mg, ih, enclosingShadow), shadowAccumulator); + } + } + private void matchInvokeInstruction(LazyMethodGen mg, InstructionHandle ih, InvokeInstruction invoke, diff --git a/weaver/src/org/aspectj/weaver/bcel/BcelField.java b/weaver/src/org/aspectj/weaver/bcel/BcelField.java index 72cc5bd0f..f4b93d952 100644 --- a/weaver/src/org/aspectj/weaver/bcel/BcelField.java +++ b/weaver/src/org/aspectj/weaver/bcel/BcelField.java @@ -16,7 +16,9 @@ package org.aspectj.weaver.bcel; import java.util.Iterator; import java.util.List; +import org.apache.bcel.classfile.Attribute; import org.apache.bcel.classfile.Field; +import org.apache.bcel.classfile.Synthetic; import org.aspectj.weaver.AjAttribute; import org.aspectj.weaver.BCException; import org.aspectj.weaver.ResolvedMember; @@ -27,6 +29,7 @@ final class BcelField extends ResolvedMember { private Field field; private boolean isAjSynthetic; + private boolean isSynthetic = false; BcelField(BcelObjectType declaringType, Field field) { super( @@ -43,7 +46,8 @@ final class BcelField extends ResolvedMember { // ---- private void unpackAttributes(World world) { - List as = BcelAttributes.readAjAttributes(field.getAttributes(), getSourceContext(world)); + Attribute[] attrs = field.getAttributes(); + List as = BcelAttributes.readAjAttributes(attrs, getSourceContext(world)); for (Iterator iter = as.iterator(); iter.hasNext();) { AjAttribute a = (AjAttribute) iter.next(); if (a instanceof AjAttribute.AjSynthetic) { @@ -53,9 +57,20 @@ final class BcelField extends ResolvedMember { } } isAjSynthetic = false; + + + for (int i = attrs.length - 1; i >= 0; i--) { + if (attrs[i] instanceof Synthetic) isSynthetic = true; + } } + + public boolean isAjSynthetic() { return isAjSynthetic; // || getName().startsWith(NameMangler.PREFIX); } + + public boolean isSynthetic() { + return isSynthetic; + } } diff --git a/weaver/src/org/aspectj/weaver/bcel/BcelMethod.java b/weaver/src/org/aspectj/weaver/bcel/BcelMethod.java index 788258010..a2a4a5fc2 100644 --- a/weaver/src/org/aspectj/weaver/bcel/BcelMethod.java +++ b/weaver/src/org/aspectj/weaver/bcel/BcelMethod.java @@ -103,6 +103,8 @@ final class BcelMethod extends ResolvedMember { return isAjSynthetic; // || getName().startsWith(NameMangler.PREFIX); } + //FIXME needs an isSynthetic method + public ShadowMunger getAssociatedShadowMunger() { return associatedShadowMunger; } |