]> source.dussan.org Git - aspectj.git/commitdiff
Cope with unusual local variable table per 539121
authorAndy Clement <aclement@pivotal.io>
Mon, 14 Jan 2019 23:51:56 +0000 (15:51 -0800)
committerAndy Clement <aclement@pivotal.io>
Mon, 14 Jan 2019 23:51:56 +0000 (15:51 -0800)
weaver/src/org/aspectj/weaver/bcel/AtAjAttributes.java

index 19170b547d403bd59929ab2da079992d57c91c49..2da044c11180e4ed4b77b1e4e4320238e83f3896 100644 (file)
@@ -1763,6 +1763,14 @@ public class AtAjAttributes {
                                }
                        }
                        if (arguments.size() == 0) {
+                               // The local variable table is causing us trouble, try the annotation value
+                               // See 539121 for a jacoco variant of the cobertura issue below
+                               if (argNamesFromAnnotation != null) {
+                                       String[] argNames = extractArgNamesFromAnnotationValue(method, argNamesFromAnnotation, methodStruct);
+                                       if (argNames.length != 0) {
+                                               return argNames;
+                                       }
+                               }
                                // could be cobertura code where some extra bytecode has been stuffed in at the start of the method
                                // but the local variable table hasn't been repaired - for example:
                                // LocalVariable(start_pc = 6, length = 40, index = 0:com.example.ExampleAspect this)
@@ -1783,32 +1791,11 @@ public class AtAjAttributes {
                                }
                        }
                } else {
-                       // No debug info, do we have an annotation value we can rely on?
                        if (argNamesFromAnnotation != null) {
-                               StringTokenizer st = new StringTokenizer(argNamesFromAnnotation, " ,");
-                               List<String> args = new ArrayList<String>();
-                               while (st.hasMoreTokens()) {
-                                       args.add(st.nextToken());
-                               }
-                               if (args.size() != method.getArgumentTypes().length) {
-                                       StringBuffer shortString = new StringBuffer().append(lastbit(method.getReturnType().toString())).append(" ")
-                                                       .append(method.getName());
-                                       if (method.getArgumentTypes().length > 0) {
-                                               shortString.append("(");
-                                               for (int i = 0; i < method.getArgumentTypes().length; i++) {
-                                                       shortString.append(lastbit(method.getArgumentTypes()[i].toString()));
-                                                       if ((i + 1) < method.getArgumentTypes().length) {
-                                                               shortString.append(",");
-                                                       }
-
-                                               }
-                                               shortString.append(")");
-                                       }
-                                       reportError("argNames annotation value does not specify the right number of argument names for the method '"
-                                                       + shortString.toString() + "'", methodStruct);
-                                       return EMPTY_STRINGS;
+                               String[] argNames = extractArgNamesFromAnnotationValue(method, argNamesFromAnnotation, methodStruct);
+                               if (argNames != null) {
+                                       return argNames;
                                }
-                               return args.toArray(new String[] {});
                        }
                }
 
@@ -1836,6 +1823,34 @@ public class AtAjAttributes {
                return argumentNames;
        }
 
+       private static String[] extractArgNamesFromAnnotationValue(Method method, String argNamesFromAnnotation,
+                       AjAttributeMethodStruct methodStruct) {
+               StringTokenizer st = new StringTokenizer(argNamesFromAnnotation, " ,");
+               List<String> args = new ArrayList<String>();
+               while (st.hasMoreTokens()) {
+                       args.add(st.nextToken());
+               }
+               if (args.size() != method.getArgumentTypes().length) {
+                       StringBuffer shortString = new StringBuffer().append(lastbit(method.getReturnType().toString())).append(" ")
+                                       .append(method.getName());
+                       if (method.getArgumentTypes().length > 0) {
+                               shortString.append("(");
+                               for (int i = 0; i < method.getArgumentTypes().length; i++) {
+                                       shortString.append(lastbit(method.getArgumentTypes()[i].toString()));
+                                       if ((i + 1) < method.getArgumentTypes().length) {
+                                               shortString.append(",");
+                                       }
+
+                               }
+                               shortString.append(")");
+                       }
+                       reportError("argNames annotation value does not specify the right number of argument names for the method '"
+                                       + shortString.toString() + "'", methodStruct);
+                       return EMPTY_STRINGS;
+               }
+               return args.toArray(new String[] {});
+       }
+
        /**
         * A method argument, used for sorting by indexOnStack (ie order in signature)
         *