More info in parsing exceptions

This commit is contained in:
Enrique Zamudio
2018-04-09 21:55:37 -05:00
parent a3bca5144a
commit b92bd46a0e
3 changed files with 13 additions and 8 deletions
@@ -55,7 +55,8 @@ public class LllbinParseInfo extends FieldParseInfo {
l, field, pos), pos);
} else if (l+pos+3 > buf.length) {
throw new ParseException(String.format(
"Insufficient data for LLLBIN field %d, pos %d", field, pos), pos);
"Insufficient data for LLLBIN field %d, pos %d len %d",
field, pos, l), pos);
}
byte[] binval = l == 0 ? new byte[0] : HexCodec.hexDecode(new String(buf, pos + 3, l));
if (custom == null) {
@@ -68,7 +69,8 @@ public class LllbinParseInfo extends FieldParseInfo {
new IsoValue<>(type, dec, 0, custom);
} catch (IndexOutOfBoundsException ex) {
throw new ParseException(String.format(
"Insufficient data for LLLBIN field %d, pos %d", field, pos), pos);
"Insufficient data for LLLBIN field %d, pos %d len %d",
field, pos, l), pos);
}
} else {
try {
@@ -78,7 +80,8 @@ public class LllbinParseInfo extends FieldParseInfo {
new IsoValue<>(type, dec, l, custom);
} catch (IndexOutOfBoundsException ex) {
throw new ParseException(String.format(
"Insufficient data for LLLBIN field %d, pos %d", field, pos), pos);
"Insufficient data for LLLBIN field %d, pos %d len %d",
field, pos, l), pos);
}
}
}
@@ -51,15 +51,15 @@ public class LllvarParseInfo extends FieldParseInfo {
throw new ParseException(String.format("Invalid LLLVAR length %d(%s) field %d pos %d",
len, new String(buf, pos, 3), field, pos), pos);
} else if (len+pos+3 > buf.length) {
throw new ParseException(String.format("Insufficient data for LLLVAR field %d, pos %d",
field, pos), pos);
throw new ParseException(String.format("Insufficient data for LLLVAR field %d, pos %d len %d",
field, pos, len), pos);
}
String _v;
try {
_v = len == 0 ? "" : new String(buf, pos + 3, len, getCharacterEncoding());
} catch (IndexOutOfBoundsException ex) {
throw new ParseException(String.format(
"Insufficient data for LLLVAR header, field %d pos %d", field, pos), pos);
"Insufficient data for LLLVAR header, field %d pos %d len %d", field, pos, len), pos);
}
//This is new: if the String's length is different from the specified length in the
//buffer, there are probably some extended characters. So we create a String from
@@ -52,14 +52,16 @@ public class LlvarParseInfo extends FieldParseInfo {
"Invalid LLVAR length %d, field %d pos %d", len, field, pos), pos);
} else if (len+pos+2 > buf.length) {
throw new ParseException(String.format(
"Insufficient data for LLVAR field %d, pos %d", field, pos), pos);
"Insufficient data for LLVAR field %d, pos %d len %d",
field, pos, len), pos);
}
String _v;
try {
_v = len == 0 ? "" : new String(buf, pos + 2, len, getCharacterEncoding());
} catch (IndexOutOfBoundsException ex) {
throw new ParseException(String.format(
"Insufficient data for LLVAR header, field %d pos %d", field, pos), pos);
"Insufficient data for LLVAR header, field %d pos %d len %d",
field, pos, len), pos);
}
//This is new: if the String's length is different from the specified
// length in the buffer, there are probably some extended characters.