From 9e6e2aad5eaf0313a8c75c52809870e0f21c39b2 Mon Sep 17 00:00:00 2001 From: Nathan Sweet Date: Wed, 12 Oct 2011 02:21:04 +0000 Subject: [PATCH] Fixed issue 3, wrong max sizes. --- src/com/esotericsoftware/reflectasm/FieldAccess.java | 8 ++++---- src/com/esotericsoftware/reflectasm/MethodAccess.java | 9 +++------ 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/com/esotericsoftware/reflectasm/FieldAccess.java b/src/com/esotericsoftware/reflectasm/FieldAccess.java index e94feb5..4601bd3 100644 --- a/src/com/esotericsoftware/reflectasm/FieldAccess.java +++ b/src/com/esotericsoftware/reflectasm/FieldAccess.java @@ -42,7 +42,7 @@ public abstract class FieldAccess { String accessClassNameInternal = accessClassName.replace('.', '/'); String classNameInternal = className.replace('.', '/'); - ClassWriter cw = new ClassWriter(0); + ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS); MethodVisitor mv; cw.visit(V1_1, ACC_PUBLIC, accessClassNameInternal, null, "com/esotericsoftware/reflectasm/FieldAccess", null); { @@ -51,7 +51,7 @@ public abstract class FieldAccess { mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKESPECIAL, "com/esotericsoftware/reflectasm/FieldAccess", "", "()V"); mv.visitInsn(RETURN); - mv.visitMaxs(1, 1); + mv.visitMaxs(0, 0); mv.visitEnd(); } { @@ -135,7 +135,7 @@ public abstract class FieldAccess { mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "toString", "()Ljava/lang/String;"); mv.visitMethodInsn(INVOKESPECIAL, "java/lang/IllegalArgumentException", "", "(Ljava/lang/String;)V"); mv.visitInsn(ATHROW); - mv.visitMaxs(6, 5); + mv.visitMaxs(0, 0); mv.visitEnd(); } { @@ -204,7 +204,7 @@ public abstract class FieldAccess { mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "toString", "()Ljava/lang/String;"); mv.visitMethodInsn(INVOKESPECIAL, "java/lang/IllegalArgumentException", "", "(Ljava/lang/String;)V"); mv.visitInsn(ATHROW); - mv.visitMaxs(6, 4); + mv.visitMaxs(0, 0); mv.visitEnd(); } cw.visitEnd(); diff --git a/src/com/esotericsoftware/reflectasm/MethodAccess.java b/src/com/esotericsoftware/reflectasm/MethodAccess.java index 4e8f503..2f5fc84 100644 --- a/src/com/esotericsoftware/reflectasm/MethodAccess.java +++ b/src/com/esotericsoftware/reflectasm/MethodAccess.java @@ -44,7 +44,7 @@ public abstract class MethodAccess { String accessClassNameInternal = accessClassName.replace('.', '/'); String classNameInternal = className.replace('.', '/'); - ClassWriter cw = new ClassWriter(0); + ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS); MethodVisitor mv; cw.visit(V1_1, ACC_PUBLIC, accessClassNameInternal, null, "com/esotericsoftware/reflectasm/MethodAccess", null); { @@ -53,7 +53,7 @@ public abstract class MethodAccess { mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKESPECIAL, "com/esotericsoftware/reflectasm/MethodAccess", "", "()V"); mv.visitInsn(RETURN); - mv.visitMaxs(1, 1); + mv.visitMaxs(0, 0); mv.visitEnd(); } { @@ -61,8 +61,6 @@ public abstract class MethodAccess { null, null); mv.visitCode(); - int maxArgCount = 0; - if (!methods.isEmpty()) { mv.visitVarInsn(ALOAD, 1); mv.visitTypeInsn(CHECKCAST, classNameInternal); @@ -89,7 +87,6 @@ public abstract class MethodAccess { Method method = methods.get(i); Class[] paramTypes = method.getParameterTypes(); - maxArgCount = Math.max(maxArgCount, paramTypes.length); for (int paramIndex = 0; paramIndex < paramTypes.length; paramIndex++) { mv.visitVarInsn(ALOAD, 3); mv.visitIntInsn(BIPUSH, paramIndex); @@ -189,7 +186,7 @@ public abstract class MethodAccess { mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "toString", "()Ljava/lang/String;"); mv.visitMethodInsn(INVOKESPECIAL, "java/lang/IllegalArgumentException", "", "(Ljava/lang/String;)V"); mv.visitInsn(ATHROW); - mv.visitMaxs(Math.max(5, maxArgCount + 2), 5); + mv.visitMaxs(0, 0); mv.visitEnd(); } cw.visitEnd();