Skip to content

Commit 04d6e83

Browse files
author
John J. Aylward
committed
* Missed JSONArray optFloat and optDouble for the revert
* prevents erasure of stack trace for rethrown exceptions
1 parent 849b392 commit 04d6e83

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

JSONArray.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ public double getDouble(int index) throws JSONException {
244244
return object instanceof Number ? ((Number) object).doubleValue()
245245
: Double.parseDouble((String) object);
246246
} catch (Exception e) {
247-
throw new JSONException("JSONArray[" + index + "] is not a number.");
247+
throw new JSONException("JSONArray[" + index + "] is not a number.", e);
248248
}
249249
}
250250

@@ -287,7 +287,7 @@ public Number getNumber(int index) throws JSONException {
287287
}
288288
return JSONObject.stringToNumber(object.toString());
289289
} catch (Exception e) {
290-
throw new JSONException("JSONArray[" + index + "] is not a number.");
290+
throw new JSONException("JSONArray[" + index + "] is not a number.", e);
291291
}
292292
}
293293

@@ -331,7 +331,7 @@ public BigDecimal getBigDecimal (int index) throws JSONException {
331331
return new BigDecimal(object.toString());
332332
} catch (Exception e) {
333333
throw new JSONException("JSONArray[" + index +
334-
"] could not convert to BigDecimal.");
334+
"] could not convert to BigDecimal.", e);
335335
}
336336
}
337337

@@ -351,7 +351,7 @@ public BigInteger getBigInteger (int index) throws JSONException {
351351
return new BigInteger(object.toString());
352352
} catch (Exception e) {
353353
throw new JSONException("JSONArray[" + index +
354-
"] could not convert to BigInteger.");
354+
"] could not convert to BigInteger.", e);
355355
}
356356
}
357357

@@ -370,7 +370,7 @@ public int getInt(int index) throws JSONException {
370370
return object instanceof Number ? ((Number) object).intValue()
371371
: Integer.parseInt((String) object);
372372
} catch (Exception e) {
373-
throw new JSONException("JSONArray[" + index + "] is not a number.");
373+
throw new JSONException("JSONArray[" + index + "] is not a number.", e);
374374
}
375375
}
376376

@@ -426,7 +426,7 @@ public long getLong(int index) throws JSONException {
426426
return object instanceof Number ? ((Number) object).longValue()
427427
: Long.parseLong((String) object);
428428
} catch (Exception e) {
429-
throw new JSONException("JSONArray[" + index + "] is not a number.");
429+
throw new JSONException("JSONArray[" + index + "] is not a number.", e);
430430
}
431431
}
432432

@@ -569,7 +569,7 @@ public double optDouble(int index, double defaultValue) {
569569
}
570570
if (val instanceof String) {
571571
try {
572-
return new BigDecimal((String) val).doubleValue();
572+
return Double.parseDouble((String) val);
573573
} catch (Exception e) {
574574
return defaultValue;
575575
}
@@ -611,7 +611,7 @@ public float optFloat(int index, float defaultValue) {
611611
}
612612
if (val instanceof String) {
613613
try {
614-
return new BigDecimal((String) val).floatValue();
614+
return Float.parseFloat((String) val);
615615
} catch (Exception e) {
616616
return defaultValue;
617617
}

0 commit comments

Comments
 (0)