From 20126982750d9ca096adae044feb920034a7ff08 Mon Sep 17 00:00:00 2001 From: "Kristian S. Stangeland" Date: Thu, 27 Sep 2012 06:04:29 +0200 Subject: [PATCH] Just in case, try to load the generated class first. We might have generated it from a previous run. --- .../reflect/compiler/StructureCompiler.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/ProtocolLib/src/com/comphenix/protocol/reflect/compiler/StructureCompiler.java b/ProtocolLib/src/com/comphenix/protocol/reflect/compiler/StructureCompiler.java index 2b989f9e..438aca91 100644 --- a/ProtocolLib/src/com/comphenix/protocol/reflect/compiler/StructureCompiler.java +++ b/ProtocolLib/src/com/comphenix/protocol/reflect/compiler/StructureCompiler.java @@ -42,7 +42,7 @@ import net.sf.cglib.asm.*; // case 6: return (TField) (Object) target.g; // case 7: return (TField) (Object) target.h; // default: -// throw new IllegalArgumentException("Invalid index " + fieldIndex); +// throw new FieldAccessException("Invalid index " + fieldIndex); // } // } // @@ -61,7 +61,7 @@ import net.sf.cglib.asm.*; // case 6: target.g = (Byte) value; break; // case 7: target.h = (Integer) value; break; // default: -// throw new IllegalArgumentException("Invalid index " + index); +// throw new FieldAccessException("Invalid index " + index); // } // // // Chaining @@ -181,6 +181,16 @@ public final class StructureCompiler { String targetSignature = Type.getDescriptor(targetType); String targetName = targetType.getName().replace('.', '/'); + try { + // This class might have been generated before. Try to load it. + Class before = loader.loadClass(PACKAGE_NAME.replace('/', '.') + "." + className); + + if (before != null) + return before; + } catch (ClassNotFoundException e) { + // That's ok. + } + cw.visit(Opcodes.V1_6, Opcodes.ACC_PUBLIC + Opcodes.ACC_SUPER, PACKAGE_NAME + "/" + className, "L" + COMPILED_CLASS + ";", COMPILED_CLASS, null);