From 69a5675161730c6f272c0ec0a8f3662f924f598c Mon Sep 17 00:00:00 2001 From: "Kristian S. Stangeland" Date: Wed, 17 Oct 2012 09:53:59 +0200 Subject: [PATCH] Fixed a bug causing a StackOverflowException on packet construction. --- .../compiler/CompiledStructureModifier.java | 21 +++++++++++++++++++ .../reflect/compiler/StructureCompiler.java | 5 ++--- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/reflect/compiler/CompiledStructureModifier.java b/ProtocolLib/src/main/java/com/comphenix/protocol/reflect/compiler/CompiledStructureModifier.java index caea3167..602815f8 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/reflect/compiler/CompiledStructureModifier.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/reflect/compiler/CompiledStructureModifier.java @@ -67,6 +67,16 @@ public abstract class CompiledStructureModifier extends StructureModifie else return (TField) result; } + + /** + * Read the given field index using reflection. + * @param index - index of field. + * @return Resulting value. + * @throws FieldAccessException The field doesn't exist, or it cannot be accessed under the current security contraints. + */ + protected Object readReflected(int index) throws FieldAccessException { + return super.read(index); + } protected abstract Object readGenerated(int fieldIndex) throws FieldAccessException; @@ -78,6 +88,17 @@ public abstract class CompiledStructureModifier extends StructureModifie return writeGenerated(index, value); } + /** + * Write the given field using reflection. + * @param index - index of field. + * @param value - new value. + * @throws FieldAccessException The field doesn't exist, or it cannot be accessed under the current security contraints. + */ + @SuppressWarnings("unchecked") + protected void writeReflected(int index, Object value) throws FieldAccessException { + super.write(index, (TField) value); + } + protected abstract StructureModifier writeGenerated(int index, Object value) throws FieldAccessException; @Override diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/reflect/compiler/StructureCompiler.java b/ProtocolLib/src/main/java/com/comphenix/protocol/reflect/compiler/StructureCompiler.java index 14f8bdb2..fde9de08 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/reflect/compiler/StructureCompiler.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/reflect/compiler/StructureCompiler.java @@ -335,8 +335,7 @@ public final class StructureCompiler { mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitVarInsn(Opcodes.ILOAD, 1); mv.visitVarInsn(Opcodes.ALOAD, 2); - mv.visitMethodInsn(Opcodes.INVOKESPECIAL, COMPILED_CLASS, "write", "(ILjava/lang/Object;)L" + SUPER_CLASS + ";"); - mv.visitInsn(Opcodes.POP); + mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, COMPILED_CLASS, "writeReflected", "(ILjava/lang/Object;)V;"); } mv.visitJumpInsn(Opcodes.GOTO, returnLabel); @@ -408,7 +407,7 @@ public final class StructureCompiler { // We have to use reflection for private and protected fields. mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitVarInsn(Opcodes.ILOAD, 1); - mv.visitMethodInsn(Opcodes.INVOKESPECIAL, COMPILED_CLASS, "read", "(I)Ljava/lang/Object;"); + mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, COMPILED_CLASS, "readReflected", "(I)Ljava/lang/Object;"); } mv.visitInsn(Opcodes.ARETURN);