From 680ad75e3086009fd456b140b37bb0fd71c50c08 Mon Sep 17 00:00:00 2001 From: Victor Sosa Date: Wed, 30 Dec 2015 13:36:58 -0400 Subject: [PATCH] fix for WW-4269 blank double results in NumberFormatException being thrown on sending JSON in request body --- .../java/org/apache/struts2/json/JSONReader.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/plugins/json/src/main/java/org/apache/struts2/json/JSONReader.java b/plugins/json/src/main/java/org/apache/struts2/json/JSONReader.java index 3f8c17572..75abb19c2 100644 --- a/plugins/json/src/main/java/org/apache/struts2/json/JSONReader.java +++ b/plugins/json/src/main/java/org/apache/struts2/json/JSONReader.java @@ -155,6 +155,7 @@ public class JSONReader { return new JSONException("Input string is not well formed JSON (invalid char " + this.c + ")"); } + @SuppressWarnings("unchecked") protected List array() throws JSONException { List ret = new ArrayList(); @@ -174,7 +175,7 @@ public class JSONReader { return ret; } - protected Object number() { + protected Object number() throws JSONException { this.buf.setLength(0); boolean toDouble = false; @@ -202,9 +203,17 @@ public class JSONReader { } if (toDouble) { - return Double.parseDouble(this.buf.toString()); + try { + return Double.parseDouble(this.buf.toString()); + } catch (NumberFormatException e) { + throw buildInvalidInputException(); + } } else { - return Long.parseLong(this.buf.toString()); + try { + return Long.parseLong(this.buf.toString()); + } catch (NumberFormatException e) { + throw buildInvalidInputException(); + } } }