8062608: BCEL corrupts debug data of methods that use generics
authordbuck
Thu, 06 Nov 2014 23:14:02 -0800
changeset 27535 872cc59854b0
parent 27394 4e7c4d692e93
child 27536 533660d72131
8062608: BCEL corrupts debug data of methods that use generics Summary: Fixed MethodGen constructor to not overwrite LocalVariableTable. Reviewed-by: joehw
jaxp/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/MethodGen.java
--- a/jaxp/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/MethodGen.java	Wed Jul 05 20:06:58 2017 +0200
+++ b/jaxp/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/MethodGen.java	Thu Nov 06 23:14:02 2014 -0800
@@ -259,10 +259,11 @@
                                l.getIndex(), start, end);
             }
           } else if (a instanceof LocalVariableTypeTable) {
-             LocalVariable[] lv = ((LocalVariableTypeTable) a).getLocalVariableTypeTable();
-             removeLocalVariables();
-             for (int k = 0; k < lv.length; k++) {
-                 LocalVariable l = lv[k];
+             LocalVariable[] oldLV = ((LocalVariableTypeTable) a).getLocalVariableTypeTable();
+             int lvLength = oldLV.length;
+             LocalVariable[] newLV = new LocalVariable[lvLength];
+             for (int k = 0; k < lvLength; k++) {
+                 LocalVariable l = oldLV[k];
                  InstructionHandle start = il.findHandle(l.getStartPC());
                  InstructionHandle end = il.findHandle(l.getStartPC() + l.getLength());
                  // Repair malformed handles
@@ -272,9 +273,16 @@
                  if (null == end) {
                      end = il.getEnd();
                  }
-                 addLocalVariable(l.getName(), Type.getType(l.getSignature()), l
-                         .getIndex(), start, end);
+                 LocalVariable newVar = new LocalVariable(l);
+                 int startPosition = start.getPosition();
+                 newVar.setStartPC(startPosition);
+                 newVar.setLength(end.getPosition() - startPosition);
+                 newLV[k] = newVar;
               }
+              LocalVariableTypeTable newLVTT = new LocalVariableTypeTable(
+                      (LocalVariableTypeTable)a);
+              newLVTT.setLocalVariableTable(newLV);
+              addCodeAttribute(newLVTT);
           } else
             addCodeAttribute(a);
         }