<message kind="error" line="13"/>
</compile>
</ajc-test>
+
+ <ajc-test dir="bugs" pr="39479"
+ title="NPE in bcel.LazyMethodGen when delegating from one ctor to a second that includes a switch">
+ <compile files="NewSwitch.java"/>
+ <run class="NewSwitch"/>
+ </ajc-test>
+
+ <ajc-test dir="bugs" pr="40109"
+ title="switch statement in aspects crashes weaving">
+ <compile files="SwitchInAround.java"/>
+ <run class="SwitchInAround"/>
+ </ajc-test>
</suite>
--- /dev/null
+import org.aspectj.testing.Tester;
+
+public class SwitchInAround {
+ public static void main(String[] args) {
+ SwitchInAround o = new SwitchInAround();
+ Tester.checkEqual(o.doit(1), "1");
+ Tester.checkEqual(o.doit(2), "2");
+ Tester.checkEqual(o.doit(3), "default");
+ }
+
+ public String doit(int i) {
+ return "doit";
+ }
+}
+
+privileged aspect A {
+ String around(int index): args(index) && call(String doit(int)) {
+ switch(index) {
+ case 1:
+ return "1";
+ case 2:
+ return "2";
+ default:
+ return "default";
+ }
+ }
+}
\ No newline at end of file
import org.apache.bcel.classfile.ClassParser;
import org.apache.bcel.classfile.JavaClass;
import org.apache.bcel.classfile.Method;
+import org.apache.bcel.generic.ArrayType;
import org.apache.bcel.generic.BIPUSH;
import org.apache.bcel.generic.BasicType;
import org.apache.bcel.generic.BranchInstruction;
import org.apache.bcel.generic.InstructionTargeter;
import org.apache.bcel.generic.LDC;
import org.apache.bcel.generic.ObjectType;
-import org.apache.bcel.generic.ArrayType;
import org.apache.bcel.generic.ReferenceType;
import org.apache.bcel.generic.SIPUSH;
+import org.apache.bcel.generic.SWITCH;
+import org.apache.bcel.generic.Select;
import org.apache.bcel.generic.TargetLostException;
import org.apache.bcel.generic.Type;
import org.aspectj.weaver.BCException;
throw new BCException("this really can't happen");
}
}
+
+ /**
+ * Fix for Bugzilla #39479, #40109 patch contributed by Andy Clement
+ *
+ * Need to manually copy Select instructions - if we rely on the the 'fresh' object
+ * created by copy(), the InstructionHandle array 'targets' inside the Select
+ * object will not have been deep copied, so modifying targets in fresh will modify
+ * the original Select - not what we want ! (It is a bug in BCEL to do with cloning
+ * Select objects).
+ *
+ * <pre>
+ * declare error:
+ * call(* Instruction.copy()) && within(org.aspectj.weaver)
+ * && !withincode(* Utility.copyInstruction(Instruction)):
+ * "use Utility.copyInstruction to work-around bug in Select.copy()";
+ * </pre>
+ */
+ public static Instruction copyInstruction(Instruction i) {
+ if (i instanceof Select) {
+ Select freshSelect = (Select)i;
+
+ // Create a new targets array that looks just like the existing one
+ InstructionHandle[] targets = new InstructionHandle[freshSelect.getTargets().length];
+ for (int ii = 0; ii < targets.length; ii++) {
+ targets[ii] = freshSelect.getTargets()[ii];
+ }
+
+ // Create a new select statement with the new targets array
+ SWITCH switchStatement = new SWITCH(freshSelect.getMatchs(),targets,freshSelect.getTarget());
+ return (Select)switchStatement.getInstruction();
+ } else {
+ return i.copy(); // Use clone for shallow copy...
+ }
+ }
+
/** returns -1 if no source line attribute */
// this naive version overruns the JVM stack size, if only Java understood tail recursion...