Fixes and improvements for local capture, avoid cryptic error on bad LVT

This commit is contained in:
Mumfrey committed 2015-05-21 15:38:14 +01:00
1 parent 4e1c5b272b
commit 10040e9f3d
4 files changed
+41 -7

No files matched your search

@@ -360,7 +360,7 @@ public class ASMHelper {
* @param node Node to print
*/
public static void printNode(AbstractInsnNode node) {
System.err.printf("%s ", node.getClass().getSimpleName());
System.err.printf("%-14s ", node.getClass().getSimpleName().replace("Node", ""));
if (node instanceof LabelNode) {
System.err.printf("[%s]", ((LabelNode)node).getLabel());
} else if (node instanceof JumpInsnNode) {
@@ -190,6 +190,13 @@ public class Locals {
break;
}
}
// Null out any "unknown" locals
for (int l = 0; l < frame.length; l++) {
if (frame[l] != null && frame[l].desc == null) {
frame[l] = null;
}
}
return frame;
}
@@ -317,8 +324,12 @@ public class Locals {
}
if (label == null) {
label = new LabelNode();
labels[i] = label;
AbstractInsnNode existingLabel = method.instructions.get(i);
if (existingLabel instanceof LabelNode) {
label = (LabelNode) existingLabel;
} else {
labels[i] = label = new LabelNode();
}
}
if (local == null && locals[j] != null) {
@@ -118,6 +118,10 @@ public class SignaturePrinter {
this.returnType = returnType;
this.argTypes = argTypes;
this.argNames = argNames;
if (this.argTypes.length > this.argNames.length) {
throw new IllegalArgumentException(String.format("Types array length must not exceed names array length! (names=%d, types=%d)",
this.argNames.length, this.argTypes.length));
}
}
public String getReturnType() {
@@ -172,8 +176,13 @@ public class SignaturePrinter {
sb.append(' ');
}
}
String name = typesOnly ? null : Strings.isNullOrEmpty(this.argNames[var]) ? "unnamed" + var : this.argNames[var];
this.appendType(sb, this.argTypes[var], name);
try {
String name = typesOnly ? null : Strings.isNullOrEmpty(this.argNames[var]) ? "unnamed" + var : this.argNames[var];
this.appendType(sb, this.argTypes[var], name);
} catch (Exception ex) {
System.err.printf("\n\n>>> argTypes=%d, argNames=%d\n\n", this.argTypes.length, this.argNames.length);
throw new RuntimeException(ex);
}
}
return sb.append(")");
}