Skip to content

Commit 6ed2880

Browse files
committed
more sonarcube cleanup
1 parent 9bb26bd commit 6ed2880

File tree

1 file changed

+16
-21
lines changed

1 file changed

+16
-21
lines changed

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

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1398,11 +1398,13 @@ static BigInteger objectToBigInteger(Object val, BigInteger defaultValue) {
13981398
}
13991399
// don't check if it's a string in case of unchecked Number subclasses
14001400
try {
1401-
// the other opt functions handle implicit conversions, i.e.
1402-
// jo.put("double",1.1d);
1403-
// jo.optInt("double"); -- will return 1, not an error
1404-
// this conversion to BigDecimal then to BigInteger is to maintain
1405-
// that type cast support that may truncate the decimal.
1401+
/**
1402+
* the other opt functions handle implicit conversions, i.e.
1403+
* jo.put("double",1.1d);
1404+
* jo.optInt("double"); -- will return 1, not an error
1405+
* this conversion to BigDecimal then to BigInteger is to maintain
1406+
* that type cast support that may truncate the decimal.
1407+
*/
14061408
final String valStr = val.toString();
14071409
if(isDecimalNotation(valStr)) {
14081410
return new BigDecimal(valStr).toBigInteger();
@@ -1506,11 +1508,7 @@ public float optFloat(String key, float defaultValue) {
15061508
if (val == null) {
15071509
return defaultValue;
15081510
}
1509-
final float floatValue = val.floatValue();
1510-
// if (Float.isNaN(floatValue) || Float.isInfinite(floatValue)) {
1511-
// return defaultValue;
1512-
// }
1513-
return floatValue;
1511+
return val.floatValue();
15141512
}
15151513

15161514
/**
@@ -1542,11 +1540,7 @@ public Float optFloatObject(String key, Float defaultValue) {
15421540
if (val == null) {
15431541
return defaultValue;
15441542
}
1545-
final Float floatValue = val.floatValue();
1546-
// if (Float.isNaN(floatValue) || Float.isInfinite(floatValue)) {
1547-
// return defaultValue;
1548-
// }
1549-
return floatValue;
1543+
return val.floatValue();
15501544
}
15511545

15521546
/**
@@ -1917,7 +1911,7 @@ private static String getKeyNameFromMethod(Method method) {
19171911
// if the first letter in the key is not uppercase, then skip.
19181912
// This is to maintain backwards compatibility before PR406
19191913
// (https://github.com/stleary/JSON-java/pull/406/)
1920-
if (key.length() == 0 || Character.isLowerCase(key.charAt(0))) {
1914+
if (key.isEmpty() || Character.isLowerCase(key.charAt(0))) {
19211915
return null;
19221916
}
19231917
if (key.length() == 1) {
@@ -1964,6 +1958,7 @@ private static void closeClosable(Object input) {
19641958
try {
19651959
((Closeable) input).close();
19661960
} catch (IOException ignore) {
1961+
// close has failed; best effort has been made
19671962
}
19681963
}
19691964
}
@@ -1983,7 +1978,7 @@ private static void closeClosable(Object input) {
19831978
* or one of its super class definitions
19841979
*/
19851980
private static <A extends Annotation> A getAnnotation(final Method m, final Class<A> annotationClass) {
1986-
// if we have invalid data the result is null
1981+
// If we have invalid data the result is null
19871982
if (m == null || annotationClass == null) {
19881983
return null;
19891984
}
@@ -1992,7 +1987,7 @@ private static <A extends Annotation> A getAnnotation(final Method m, final Clas
19921987
return m.getAnnotation(annotationClass);
19931988
}
19941989

1995-
// if we've already reached the Object class, return null;
1990+
// If we've already reached the Object class, return null;
19961991
Class<?> c = m.getDeclaringClass();
19971992
if (c.getSuperclass() == null) {
19981993
return null;
@@ -2004,13 +1999,13 @@ private static <A extends Annotation> A getAnnotation(final Method m, final Clas
20041999
Method im = i.getMethod(m.getName(), m.getParameterTypes());
20052000
return getAnnotation(im, annotationClass);
20062001
} catch (final SecurityException ex) {
2007-
continue;
2002+
// ignore this exception
20082003
} catch (final NoSuchMethodException ex) {
2009-
continue;
2004+
// ignore this excpetion
20102005
}
20112006
}
20122007

2013-
//If the superclass is Object, no annotations will be found any more
2008+
// If the superclass is Object, no annotations will be found any more
20142009
if (Object.class.equals(c.getSuperclass()))
20152010
return null;
20162011

0 commit comments

Comments
 (0)