more sonarcube cleanup

This commit is contained in:
marilynel 2025-08-24 12:55:49 -08:00
parent 9bb26bdb34
commit 6ed2880f55

View File

@ -1398,11 +1398,13 @@ public class JSONObject {
} }
// don't check if it's a string in case of unchecked Number subclasses // don't check if it's a string in case of unchecked Number subclasses
try { try {
// the other opt functions handle implicit conversions, i.e. /**
// jo.put("double",1.1d); * the other opt functions handle implicit conversions, i.e.
// jo.optInt("double"); -- will return 1, not an error * jo.put("double",1.1d);
// this conversion to BigDecimal then to BigInteger is to maintain * jo.optInt("double"); -- will return 1, not an error
// that type cast support that may truncate the decimal. * this conversion to BigDecimal then to BigInteger is to maintain
* that type cast support that may truncate the decimal.
*/
final String valStr = val.toString(); final String valStr = val.toString();
if(isDecimalNotation(valStr)) { if(isDecimalNotation(valStr)) {
return new BigDecimal(valStr).toBigInteger(); return new BigDecimal(valStr).toBigInteger();
@ -1506,11 +1508,7 @@ public class JSONObject {
if (val == null) { if (val == null) {
return defaultValue; return defaultValue;
} }
final float floatValue = val.floatValue(); return val.floatValue();
// if (Float.isNaN(floatValue) || Float.isInfinite(floatValue)) {
// return defaultValue;
// }
return floatValue;
} }
/** /**
@ -1542,11 +1540,7 @@ public class JSONObject {
if (val == null) { if (val == null) {
return defaultValue; return defaultValue;
} }
final Float floatValue = val.floatValue(); return val.floatValue();
// if (Float.isNaN(floatValue) || Float.isInfinite(floatValue)) {
// return defaultValue;
// }
return floatValue;
} }
/** /**
@ -1917,7 +1911,7 @@ public class JSONObject {
// if the first letter in the key is not uppercase, then skip. // if the first letter in the key is not uppercase, then skip.
// This is to maintain backwards compatibility before PR406 // This is to maintain backwards compatibility before PR406
// (https://github.com/stleary/JSON-java/pull/406/) // (https://github.com/stleary/JSON-java/pull/406/)
if (key.length() == 0 || Character.isLowerCase(key.charAt(0))) { if (key.isEmpty() || Character.isLowerCase(key.charAt(0))) {
return null; return null;
} }
if (key.length() == 1) { if (key.length() == 1) {
@ -1964,6 +1958,7 @@ public class JSONObject {
try { try {
((Closeable) input).close(); ((Closeable) input).close();
} catch (IOException ignore) { } catch (IOException ignore) {
// close has failed; best effort has been made
} }
} }
} }
@ -1983,7 +1978,7 @@ public class JSONObject {
* or one of its super class definitions * or one of its super class definitions
*/ */
private static <A extends Annotation> A getAnnotation(final Method m, final Class<A> annotationClass) { private static <A extends Annotation> A getAnnotation(final Method m, final Class<A> annotationClass) {
// if we have invalid data the result is null // If we have invalid data the result is null
if (m == null || annotationClass == null) { if (m == null || annotationClass == null) {
return null; return null;
} }
@ -1992,7 +1987,7 @@ public class JSONObject {
return m.getAnnotation(annotationClass); return m.getAnnotation(annotationClass);
} }
// if we've already reached the Object class, return null; // If we've already reached the Object class, return null;
Class<?> c = m.getDeclaringClass(); Class<?> c = m.getDeclaringClass();
if (c.getSuperclass() == null) { if (c.getSuperclass() == null) {
return null; return null;
@ -2004,13 +1999,13 @@ public class JSONObject {
Method im = i.getMethod(m.getName(), m.getParameterTypes()); Method im = i.getMethod(m.getName(), m.getParameterTypes());
return getAnnotation(im, annotationClass); return getAnnotation(im, annotationClass);
} catch (final SecurityException ex) { } catch (final SecurityException ex) {
continue; // ignore this exception
} catch (final NoSuchMethodException ex) { } catch (final NoSuchMethodException ex) {
continue; // ignore this excpetion
} }
} }
//If the superclass is Object, no annotations will be found any more // If the superclass is Object, no annotations will be found any more
if (Object.class.equals(c.getSuperclass())) if (Object.class.equals(c.getSuperclass()))
return null; return null;