]> source.dussan.org Git - aspectj.git/commitdiff
Fix 500796: Allow for kotlin creating 'synthetic' local variable table entries
authorAndy Clement <aclement@pivotal.io>
Tue, 8 Nov 2016 00:18:54 +0000 (16:18 -0800)
committerAndy Clement <aclement@pivotal.io>
Tue, 8 Nov 2016 00:18:54 +0000 (16:18 -0800)
16 files changed:
bcel-builder/src/org/aspectj/apache/bcel/generic/MethodGen.java
lib/bcel/bcel-src.zip
lib/bcel/bcel-verifier-src.zip
lib/bcel/bcel-verifier.jar
lib/bcel/bcel.jar
tests/src/org/aspectj/systemtest/ajc150/AnnotationBinding.java
tests/src/org/aspectj/systemtest/ajc150/GenericITDsDesign.java
tests/src/org/aspectj/systemtest/ajc150/GenericsTests.java
tests/src/org/aspectj/systemtest/ajc160/SanityTests.java
tests/src/org/aspectj/systemtest/ajc1610/NewFeatures.java
tests/src/org/aspectj/systemtest/ajc163/Ajc163Tests.java
weaver/src/org/aspectj/weaver/bcel/BcelAdvice.java
weaver/src/org/aspectj/weaver/bcel/BcelTypeMunger.java
weaver/src/org/aspectj/weaver/bcel/LazyMethodGen.java
weaver/src/org/aspectj/weaver/bcel/UnwovenClassFile.java
weaver/testsrc/org/aspectj/weaver/bcel/WorldTestCase.java

index 59cf7397ed6bfb6b184cb85b893bd6dfd5fd118a..21673dec0405c2c8579f9bf57d018fc3d4276e29 100644 (file)
@@ -880,9 +880,19 @@ public class MethodGen extends FieldGenOrMethodGen {
        }
 
        /**
-        * Compute maximum number of local variables.
+        * Compute maximum number of local variables based on the parameter count and bytecode usage of variables.
         */
        public void setMaxLocals() {
+               setMaxLocals(false);
+       }
+       
+       /**
+        * Compute maximum number of local variables.
+        * 
+        * @param respectLocalVariableTable if true and the local variable table indicates more are in use
+        * than the code suggests, respect the higher value from the local variable table data.
+        */
+       public void setMaxLocals(boolean respectLocalVariableTable) {
                if (il != null) {
                        int max = isStatic() ? 0 : 1;
 
@@ -903,10 +913,13 @@ public class MethodGen extends FieldGenOrMethodGen {
                                        }
                                }
                        }
-
-                       maxLocals = max;
+                       if (!respectLocalVariableTable || max > maxLocals) {
+                               maxLocals = max;
+                       }
                } else {
-                       maxLocals = 0;
+                       if (!respectLocalVariableTable) {
+                               maxLocals = 0;
+                       }
                }
        }
 
index c96574cdf3b76885f55024625c2ac3d410f37d57..58136055bbc8790991d69d0e6604d41abdc827de 100644 (file)
Binary files a/lib/bcel/bcel-src.zip and b/lib/bcel/bcel-src.zip differ
index bf5a86a3e8bfe2f9367f79f53bdb3ae7b04e5370..c6a16a60b7a62a1b38130804577adc227213288e 100644 (file)
Binary files a/lib/bcel/bcel-verifier-src.zip and b/lib/bcel/bcel-verifier-src.zip differ
index 7ca7ec48bc925a34180bf780ab9f1c5814b1d9d7..05c04d096c44d1f52e8ebbdbd1e50b5a20b9b68a 100644 (file)
Binary files a/lib/bcel/bcel-verifier.jar and b/lib/bcel/bcel-verifier.jar differ
index 5da57de723b8e601113d18a46ffd64683d7c8756..fdfd8dedae8fcd6393accd25eea986c2525d6d09 100644 (file)
Binary files a/lib/bcel/bcel.jar and b/lib/bcel/bcel.jar differ
index 63cebdb06ff59e25596335baa44543fe55ce6860..4665676414285fbc95c5a77b7b1ad2a4e91ffca8 100644 (file)
@@ -18,6 +18,7 @@ import junit.framework.Test;
 import org.aspectj.asm.AsmManager;
 import org.aspectj.asm.IHierarchy;
 import org.aspectj.asm.IProgramElement;
+import org.aspectj.asm.IRelationship;
 import org.aspectj.asm.internal.Relationship;
 import org.aspectj.testing.XMLBasedAjcTestCase;
 
@@ -313,7 +314,7 @@ public class AnnotationBinding extends XMLBasedAjcTestCase {
                                        "declare @method: int A.m() : @Fruit(\"orange\")");
                        assertTrue("Couldn't find 'declare @method' element in the tree", ipe != null);
 
-                       List l = asm.getRelationshipMap().get(ipe);
+                       List<IRelationship> l = asm.getRelationshipMap().get(ipe);
                        assertTrue("Should have a relationship but does not ", l.size() > 0);
 
                        ipe = top.findElementForLabel(top.getRoot(), IProgramElement.Kind.DECLARE_ANNOTATION_AT_METHOD,
@@ -343,7 +344,7 @@ public class AnnotationBinding extends XMLBasedAjcTestCase {
                                        "declare @field: int A.i : @Fruit(\"orange\")");
                        assertTrue("Couldn't find 'declare @type' element in the tree", ipe != null);
 
-                       List l = asm.getRelationshipMap().get(ipe);
+                       List<IRelationship> l = asm.getRelationshipMap().get(ipe);
                        assertTrue("Should have a relationship but does not ", l.size() > 0);
 
                        ipe = top.findElementForLabel(top.getRoot(), IProgramElement.Kind.DECLARE_ANNOTATION_AT_FIELD,
@@ -375,7 +376,7 @@ public class AnnotationBinding extends XMLBasedAjcTestCase {
                                        "declare @constructor: A.new(java.lang.String) : @Fruit(\"pear\")");
                        assertTrue("Couldn't find 'declare @constructor' element in the tree", ipe != null);
 
-                       List l = asm.getRelationshipMap().get(ipe);
+                       List<IRelationship> l = asm.getRelationshipMap().get(ipe);
                        assertTrue("Should have a relationship but does not ", l.size() > 0);
 
                        ipe = top.findElementForLabel(top.getRoot(), IProgramElement.Kind.DECLARE_ANNOTATION_AT_CONSTRUCTOR,
index dfedf65a016649ba6db267248851b6d4b93c0c59..6209298c1045488e598cda22adcbba26b0c5c191 100644 (file)
@@ -15,6 +15,7 @@ import org.aspectj.apache.bcel.util.ClassPath;
 import org.aspectj.apache.bcel.util.SyntheticRepository;
 import org.aspectj.testing.XMLBasedAjcTestCase;
 import org.aspectj.tools.ajc.Ajc;
+import org.aspectj.weaver.ConcreteTypeMunger;
 import org.aspectj.weaver.CrosscuttingMembers;
 import org.aspectj.weaver.ReferenceType;
 import org.aspectj.weaver.ResolvedMember;
@@ -75,12 +76,12 @@ public class GenericITDsDesign extends XMLBasedAjcTestCase {
                                .equals(sig));
        }
 
-       public List /* BcelTypeMunger */getTypeMunger(String classname) {
+       public List<ConcreteTypeMunger> getTypeMunger(String classname) {
                ClassPath cp = new ClassPath(ajc.getSandboxDirectory() + File.pathSeparator + System.getProperty("java.class.path"));
                recentWorld = new BcelWorld(cp.toString());
                ReferenceType resolvedType = (ReferenceType) recentWorld.resolve(classname);
                CrosscuttingMembers cmembers = resolvedType.collectCrosscuttingMembers(true);
-               List tmungers = cmembers.getTypeMungers();
+               List<ConcreteTypeMunger> tmungers = cmembers.getTypeMungers();
                return tmungers;
        }
 
@@ -100,9 +101,9 @@ public class GenericITDsDesign extends XMLBasedAjcTestCase {
                return null;
        }
 
-       public Hashtable getMeTheFields(String classname) {
+       public Hashtable<String,Field> getMeTheFields(String classname) {
                JavaClass theClass = getClassFromDisk(ajc, classname);
-               Hashtable retval = new Hashtable();
+               Hashtable<String,Field> retval = new Hashtable<>();
                org.aspectj.apache.bcel.classfile.Field[] fs = theClass.getFields();
                for (int i = 0; i < fs.length; i++) {
                        Field field = fs[i];
@@ -206,7 +207,7 @@ public class GenericITDsDesign extends XMLBasedAjcTestCase {
        // Verifying what gets into a class targetted with a field ITD
        public void testDesignF() {
                runTest("generic itds - design F");
-               Hashtable fields = getMeTheFields("C");
+               Hashtable<String,Field> fields = getMeTheFields("C");
 
                // Declared in src as: List C.list1; and List<Z> C<Z>.list2;
                Field list1 = (Field) fields.get("list1");// ajc$interField$$list1");
@@ -229,7 +230,7 @@ public class GenericITDsDesign extends XMLBasedAjcTestCase {
        // Verifying what gets into a class when an interface it implements was targetted with a field ITD
        public void testDesignG() {
                runTest("generic itds - design G");
-               Hashtable fields = getMeTheFields("C");
+               Hashtable<String,Field> fields = getMeTheFields("C");
 
                // The ITDs are targetting an interface. That interface is generic and is parameterized with
                // 'String' when implemented in the class C. This means the fields that make it into C should
index 21efa3328beebef71c5cf52b3506bf1532aecf63..1ec2b21c17d652a6cb97378f47d9b676fad95a54 100644 (file)
@@ -875,11 +875,11 @@ public class GenericsTests extends XMLBasedAjcTestCase {
         * bridge methods have been created.
         */
        public void checkMethodsExist(String classname,String[] methods) {
-               Set methodsFound = new HashSet();
+               Set<String> methodsFound = new HashSet<>();
                StringBuffer debugString = new StringBuffer();
                try {
                        ClassLoader cl = new URLClassLoader(new URL[]{ajc.getSandboxDirectory().toURL()});
-                       Class clz = Class.forName(classname,false,cl);
+                       Class<?> clz = Class.forName(classname,false,cl);
                        java.lang.reflect.Method[] ms = clz.getDeclaredMethods();
                        if (ms!=null) {
                                for (int i =0;i<ms.length;i++) {
@@ -905,8 +905,7 @@ public class GenericsTests extends XMLBasedAjcTestCase {
                }
                StringBuffer unexpectedMethods = new StringBuffer();
                if (!methodsFound.isEmpty()) {
-                       for (Iterator iter = methodsFound.iterator(); iter.hasNext();) {
-                               String element = (String) iter.next();
+                       for (String element: methodsFound) {
                                unexpectedMethods.append("[").append(element).append("]");
                        }
                        fail("These methods weren't expected: "+unexpectedMethods);
@@ -924,7 +923,7 @@ public class GenericsTests extends XMLBasedAjcTestCase {
             return false;
         }
         try {
-            final Class[] noparms = new Class[0];
+            final Class<?>[] noparms = new Class[0];
             java.lang.reflect.Method isBridge 
                 = java.lang.reflect.Method.class.getMethod("isBridge", noparms);
             Boolean result = (Boolean) isBridge.invoke(m, new Object[0]);
@@ -959,7 +958,6 @@ public class GenericsTests extends XMLBasedAjcTestCase {
        
        public static void checkOneSignatureAttribute(Ajc ajc,String classname) {
                JavaClass clazz = getClass(ajc,classname);
-               Signature sigAttr = null;
                Attribute[] attrs = clazz.getAttributes();
                int signatureCount = 0;
                StringBuffer sb = new StringBuffer();
@@ -981,7 +979,7 @@ public class GenericsTests extends XMLBasedAjcTestCase {
                                sigAttr.getSignature().equals(sig));            
        }
                
-       private static String stringify(Class[] clazzes) {
+       private static String stringify(Class<?>[] clazzes) {
                if (clazzes==null) return "";
                StringBuffer sb = new StringBuffer();
                for (int i = 0; i < clazzes.length; i++) {
index 5d0462c99094f61e136ba1489e1575c9fbf7c5ac..45eac49cec1c1fce8cf0da66c250145808571745 100644 (file)
@@ -94,6 +94,7 @@ public class SanityTests extends org.aspectj.testing.XMLBasedAjcTestCase {
        // }
 
        /* For the specified class, check that each method has a stackmap attribute */
+       @SuppressWarnings("unused")
        private void checkStackMapExistence(String classname, String toIgnore) throws ClassNotFoundException {
                toIgnore = "_" + (toIgnore == null ? "" : toIgnore) + "_";
                JavaClass jc = getClassFrom(ajc.getSandboxDirectory(), classname);
index b9de3dff7a003eaa4b486d21d5a5530420706c35..588d7118684511b300bd54799df1219961412106 100644 (file)
@@ -31,6 +31,7 @@ public class NewFeatures extends org.aspectj.testing.XMLBasedAjcTestCase {
                }
        }
 
+       @SuppressWarnings("unused")
        public void testMakeSJPOptimizationCollapsedSJPYes14() {
                this.runTest("makeSJP optimization - Collapsed SJP - Yes 1.4");
                try {
index 224f695efb18e353c314c83623184a7358b25b9c..15abc89211b8afc15e432e4d9dcd48e0882ad20c 100644 (file)
@@ -11,7 +11,6 @@
 package org.aspectj.systemtest.ajc163;
 
 import java.io.File;
-import java.util.Iterator;
 import java.util.List;
 
 import junit.framework.Test;
@@ -174,9 +173,8 @@ public class Ajc163Tests extends org.aspectj.testing.XMLBasedAjcTestCase {
                if (whereToLook.getSourceLocation() != null && whereToLook.getSourceLocation().getLine() == line) {
                        return whereToLook;
                }
-               List kids = whereToLook.getChildren();
-               for (Iterator iterator = kids.iterator(); iterator.hasNext();) {
-                       IProgramElement object = (IProgramElement) iterator.next();
+               List<IProgramElement> kids = whereToLook.getChildren();
+               for (IProgramElement object: kids) {
                        if (object.getSourceLocation() != null && object.getSourceLocation().getLine() == line) {
                                return object;
                        }
index a9f214723627d2deec90e008e96bbb12d0f3bcab..d22b17d121cdc07d25711bb812322bed7296423f 100644 (file)
@@ -26,7 +26,6 @@ import org.aspectj.apache.bcel.generic.InstructionConstants;
 import org.aspectj.apache.bcel.generic.InstructionFactory;
 import org.aspectj.apache.bcel.generic.InstructionHandle;
 import org.aspectj.apache.bcel.generic.InstructionList;
-import org.aspectj.apache.bcel.generic.InvokeDynamic;
 import org.aspectj.apache.bcel.generic.LineNumberTag;
 import org.aspectj.apache.bcel.generic.LocalVariableTag;
 import org.aspectj.bridge.ISourceLocation;
index 8d5d26499013b4f6345f40f22fe14adba8ceddbc..9768cb9e4f274b6ec6a6e5f603b57bc17c78b2fa 100644 (file)
@@ -44,7 +44,6 @@ 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 0b02041aba4540b92d5e2e99385de56dae613ef0..2655a34564da65dae0df0bda8b8444cb1dc384f0 100644 (file)
@@ -1020,7 +1020,8 @@ public final class LazyMethodGen implements Traceable {
                        } else {
                                packBody(gen);
                        }
-                       gen.setMaxLocals();
+                       
+                       gen.setMaxLocals(true); 
                        gen.setMaxStack();
                } else {
                        gen.setInstructionList(null);
index 79a96c7755b482956ef89ced3d121415aff6bfef..d02c90130ab6f8a34a374e2465bf1bec2e21a7a8 100644 (file)
@@ -71,10 +71,10 @@ public class UnwovenClassFile implements IUnwovenClassFile {
        }
 
        public void writeUnchangedBytes() throws IOException {
-               writeWovenBytes(getBytes(), Collections.EMPTY_LIST);
+               writeWovenBytes(getBytes(), Collections.<ChildClass>emptyList());
        }
 
-       public void writeWovenBytes(byte[] bytes, List childClasses) throws IOException {
+       public void writeWovenBytes(byte[] bytes, List<ChildClass> childClasses) throws IOException {
                writeChildClasses(childClasses);
 
                // System.err.println("should write: " + getClassName());
index 1fb75685299d86304d95eaee6b641ada80e0bc73..3d21b57ad1abb2c692fe3b19fa4e1dff783b2912 100644 (file)
@@ -13,8 +13,6 @@
 package org.aspectj.weaver.bcel;
 
 import java.lang.reflect.Modifier;
-import java.util.Objects;
-import java.util.function.Consumer;
 
 import org.aspectj.weaver.Advice;
 import org.aspectj.weaver.BcweaverTests;