From c8133d2d1cdeddd602b5c25b89dea2db9d8a1a5f Mon Sep 17 00:00:00 2001 From: tmayer Date: Fri, 26 Feb 2021 20:10:54 +0100 Subject: [PATCH 1/2] Exception fix --- .../minidev/json/parser/JSONParserBase.java | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/json-smart/src/main/java/net/minidev/json/parser/JSONParserBase.java b/json-smart/src/main/java/net/minidev/json/parser/JSONParserBase.java index a5dd024..36d9b8a 100644 --- a/json-smart/src/main/java/net/minidev/json/parser/JSONParserBase.java +++ b/json-smart/src/main/java/net/minidev/json/parser/JSONParserBase.java @@ -138,12 +138,20 @@ public void checkLeadinZero() throws ParseException { protected Number extractFloat() throws ParseException { if (!acceptLeadinZero) - checkLeadinZero(); - if (!useHiPrecisionFloat) - return Float.parseFloat(xs); - if (xs.length() > 18) // follow JSonIJ parsing method - return new BigDecimal(xs); - return Double.parseDouble(xs); + checkLeadinZero(); + + try { + if (!useHiPrecisionFloat) + return Float.parseFloat(xs); + + if (xs.length() > 18) // follow JSonIJ parsing method + return new BigDecimal(xs); + + return Double.parseDouble(xs); + + } catch(Exception e){ + throw new ParseException(pos, ERROR_UNEXPECTED_TOKEN, xs); + } } /** From c98873a3e85625d582cd448f90d97a1ad38b322a Mon Sep 17 00:00:00 2001 From: tmayer Date: Fri, 26 Feb 2021 23:21:53 +0100 Subject: [PATCH 2/2] Avoid catching exceptions other than NumberFormatException --- .../minidev/json/parser/JSONParserBase.java | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/json-smart/src/main/java/net/minidev/json/parser/JSONParserBase.java b/json-smart/src/main/java/net/minidev/json/parser/JSONParserBase.java index 36d9b8a..5f7c1be 100644 --- a/json-smart/src/main/java/net/minidev/json/parser/JSONParserBase.java +++ b/json-smart/src/main/java/net/minidev/json/parser/JSONParserBase.java @@ -138,20 +138,20 @@ public void checkLeadinZero() throws ParseException { protected Number extractFloat() throws ParseException { if (!acceptLeadinZero) - checkLeadinZero(); - - try { - if (!useHiPrecisionFloat) + checkLeadinZero(); + + try { + if (!useHiPrecisionFloat) return Float.parseFloat(xs); - - if (xs.length() > 18) // follow JSonIJ parsing method + + if (xs.length() > 18) // follow JSonIJ parsing method return new BigDecimal(xs); - return Double.parseDouble(xs); + return Double.parseDouble(xs); - } catch(Exception e){ - throw new ParseException(pos, ERROR_UNEXPECTED_TOKEN, xs); - } + } catch(NumberFormatException e){ + throw new ParseException(pos, ERROR_UNEXPECTED_TOKEN, xs); + } } /**