From b92bd46a0e8b77bba2c86bc5952ebc01ab2ca77a Mon Sep 17 00:00:00 2001 From: Enrique Zamudio Date: Mon, 9 Apr 2018 21:55:37 -0500 Subject: [PATCH] More info in parsing exceptions --- .../java/com/solab/iso8583/parse/LllbinParseInfo.java | 9 ++++++--- .../java/com/solab/iso8583/parse/LllvarParseInfo.java | 6 +++--- .../java/com/solab/iso8583/parse/LlvarParseInfo.java | 6 ++++-- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/solab/iso8583/parse/LllbinParseInfo.java b/src/main/java/com/solab/iso8583/parse/LllbinParseInfo.java index afc92f0..0aa933c 100644 --- a/src/main/java/com/solab/iso8583/parse/LllbinParseInfo.java +++ b/src/main/java/com/solab/iso8583/parse/LllbinParseInfo.java @@ -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); } } } diff --git a/src/main/java/com/solab/iso8583/parse/LllvarParseInfo.java b/src/main/java/com/solab/iso8583/parse/LllvarParseInfo.java index 32cde9c..4049728 100644 --- a/src/main/java/com/solab/iso8583/parse/LllvarParseInfo.java +++ b/src/main/java/com/solab/iso8583/parse/LllvarParseInfo.java @@ -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 diff --git a/src/main/java/com/solab/iso8583/parse/LlvarParseInfo.java b/src/main/java/com/solab/iso8583/parse/LlvarParseInfo.java index 7662dd6..31bf195 100644 --- a/src/main/java/com/solab/iso8583/parse/LlvarParseInfo.java +++ b/src/main/java/com/solab/iso8583/parse/LlvarParseInfo.java @@ -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.