From d7087c2da5084f72e197599c40cfd530b64f7d0e Mon Sep 17 00:00:00 2001 From: Dan Mulloy Date: Sun, 30 Nov 2014 18:29:22 -0500 Subject: [PATCH] Make write error messages more informational --- .../comphenix/protocol/reflect/StructureModifier.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/reflect/StructureModifier.java b/ProtocolLib/src/main/java/com/comphenix/protocol/reflect/StructureModifier.java index 0f2ff8f5..58dead0b 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/reflect/StructureModifier.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/reflect/StructureModifier.java @@ -282,11 +282,12 @@ public class StructureModifier { * @throws FieldAccessException The field doesn't exist, or it cannot be accessed under the current security contraints. */ public StructureModifier write(int fieldIndex, TField value) throws FieldAccessException { - if (fieldIndex < 0 || fieldIndex >= data.size()) - throw new FieldAccessException("Field index must be within 0 - count", - new IndexOutOfBoundsException("Out of bounds")); + if (fieldIndex < 0) + throw new FieldAccessException(String.format("Field index (%s) cannot be negative.", fieldIndex)); + if (fieldIndex >= data.size()) + throw new FieldAccessException(String.format("Field index out of bounds. (Index: %s, Size: %s)", fieldIndex, data.size())); if (target == null) - throw new IllegalStateException("Cannot write to a NULL target."); + throw new IllegalStateException("Cannot write to a null target"); // Use the converter, if it exists Object obj = needConversion() ? converter.getGeneric(getFieldType(fieldIndex), value) : value;