changeset 663:fe179de493b1

8062608: BCEL corrupts debug data of methods that use generics Summary: Fixed MethodGen constructor to not overwrite LocalVariableTable. Reviewed-by: joehw
author dbuck
date Thu, 06 Nov 2014 23:14:02 -0800
parents a12d347f8417
children aa6737ec5ced
files src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/MethodGen.java
diffstat 1 files changed, 14 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/MethodGen.java	Thu Nov 06 15:13:32 2014 -0800
+++ b/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);
         }