Fixed a bug causing a StackOverflowException on packet construction.

This commit is contained in:
Kristian S. Stangeland 2012-10-17 09:53:59 +02:00
parent d5028b584d
commit 69a5675161
2 changed files with 23 additions and 3 deletions

View File

@ -67,6 +67,16 @@ public abstract class CompiledStructureModifier<TField> 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<TField> 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<TField> writeGenerated(int index, Object value) throws FieldAccessException;
@Override

View File

@ -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);