Skip to content

Commit 9512fbd

Browse files
author
Leonardo Lopes
committed
"someone" forget to cast in the right way
1 parent b955163 commit 9512fbd

File tree

2 files changed

+18
-19
lines changed

2 files changed

+18
-19
lines changed

src/main/java/org/json/JSONArray.java

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ public boolean getBoolean(int index) throws JSONException {
288288
.equalsIgnoreCase("true"))) {
289289
return true;
290290
}
291-
throw wrongValueFormatException(index, "boolean", null);
291+
throw wrongValueFormatException(index, "Boolean", null);
292292
}
293293

294294
/**
@@ -326,7 +326,7 @@ public double getDouble(int index) throws JSONException {
326326
public float getFloat(int index) throws JSONException {
327327
final Object object = this.get(index);
328328
if(object instanceof Number) {
329-
return ((Float)object).floatValue();
329+
return ((Number)object).floatValue();
330330
}
331331
try {
332332
return Float.parseFloat(object.toString());
@@ -377,8 +377,7 @@ public <E extends Enum<E>> E getEnum(Class<E> clazz, int index) throws JSONExcep
377377
// JSONException should really take a throwable argument.
378378
// If it did, I would re-implement this with the Enum.valueOf
379379
// method and place any thrown exception in the JSONException
380-
throw wrongValueFormatException(index, "enum of type "
381-
+ JSONObject.quote(clazz.getSimpleName()), null);
380+
throw wrongValueFormatException(index, "enum of type " + JSONObject.quote(clazz.getSimpleName()), null);
382381
}
383382
return val;
384383
}
@@ -396,13 +395,13 @@ public <E extends Enum<E>> E getEnum(Class<E> clazz, int index) throws JSONExcep
396395
* If the key is not found or if the value cannot be converted
397396
* to a BigDecimal.
398397
*/
399-
public BigDecimal getBigDecimal (int index) throws JSONException {
398+
public BigDecimal getBigDecimal(int index) throws JSONException {
400399
Object object = this.get(index);
401-
BigDecimal val = JSONObject.objectToBigDecimal(object, null);
402-
if(val == null) {
403-
throw wrongValueFormatException(index, "BigDecimal", object, null);
400+
BigDecimal ret = JSONObject.objectToBigDecimal(object, null);
401+
if (ret != null) {
402+
return ret;
404403
}
405-
return val;
404+
throw wrongValueFormatException(index, "BigDecimal", object, null);
406405
}
407406

408407
/**
@@ -415,13 +414,13 @@ public BigDecimal getBigDecimal (int index) throws JSONException {
415414
* If the key is not found or if the value cannot be converted
416415
* to a BigInteger.
417416
*/
418-
public BigInteger getBigInteger (int index) throws JSONException {
417+
public BigInteger getBigInteger(int index) throws JSONException {
419418
Object object = this.get(index);
420-
BigInteger val = JSONObject.objectToBigInteger(object, null);
421-
if(val == null) {
422-
throw wrongValueFormatException(index, "BigInteger", object, null);
419+
BigInteger ret = JSONObject.objectToBigInteger(object, null);
420+
if (ret != null) {
421+
return ret;
423422
}
424-
return val;
423+
throw wrongValueFormatException(index, "BigInteger", object, null);
425424
}
426425

427426
/**

src/main/java/org/json/JSONObject.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ public <E extends Enum<E>> E getEnum(Class<E> clazz, String key) throws JSONExce
594594
// JSONException should really take a throwable argument.
595595
// If it did, I would re-implement this with the Enum.valueOf
596596
// method and place any thrown exception in the JSONException
597-
throw wrongValueFormatException(key, "enum of type " + quote(clazz.getSimpleName()), null);
597+
throw wrongValueFormatException(key, "enum of type " + JSONObject.quote(clazz.getSimpleName()), null);
598598
}
599599
return val;
600600
}
@@ -635,7 +635,7 @@ public boolean getBoolean(String key) throws JSONException {
635635
*/
636636
public BigInteger getBigInteger(String key) throws JSONException {
637637
Object object = this.get(key);
638-
BigInteger ret = objectToBigInteger(object, null);
638+
BigInteger ret = JSONObject.objectToBigInteger(object, null);
639639
if (ret != null) {
640640
return ret;
641641
}
@@ -657,7 +657,7 @@ public BigInteger getBigInteger(String key) throws JSONException {
657657
*/
658658
public BigDecimal getBigDecimal(String key) throws JSONException {
659659
Object object = this.get(key);
660-
BigDecimal ret = objectToBigDecimal(object, null);
660+
BigDecimal ret = JSONObject.objectToBigDecimal(object, null);
661661
if (ret != null) {
662662
return ret;
663663
}
@@ -724,7 +724,7 @@ public Number getNumber(String key) throws JSONException {
724724
if (object instanceof Number) {
725725
return (Number)object;
726726
}
727-
return stringToNumber(object.toString());
727+
return JSONObject.stringToNumber(object.toString());
728728
} catch (Exception e) {
729729
throw wrongValueFormatException(key, "number", e);
730730
}
@@ -860,7 +860,7 @@ public String getString(String key) throws JSONException {
860860
if (object instanceof String) {
861861
return (String) object;
862862
}
863-
throw wrongValueFormatException(key, "string", null);
863+
throw wrongValueFormatException(key, "String", null);
864864
}
865865

866866
/**

0 commit comments

Comments
 (0)