| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -480,6 +480,7 @@ public JSONObject(Object object, String ... names) { | |||
| 480 | 480 | try { | |
| 481 | 481 | this.putOpt(name, c.getField(name).get(object)); | |
| 482 | 482 | } catch (Exception ignore) { | |
| 483 | + // if invalid, do not include key:value pair in JSONObject | ||
| 483 | 484 | } | |
| 484 | 485 | } | |
| 485 | 486 | } | |
@@ -651,9 +652,9 @@ public static String doubleToString(double d) { | |||
| 651 | 652 | return "null"; | |
| 652 | 653 | } | |
| 653 | 654 | ||
| 654 | - // Shave off trailing zeros and decimal point, if possible. | ||
| 655 | - | ||
| 655 | + // Shave off trailing zeros and decimal point, if possible. | ||
| 656 | 656 | String string = Double.toString(d); | |
| 657 | + // idx = 0 case is covered by behavior of Double.toString() | ||
| 657 | 658 | if (string.indexOf('.') > 0 && string.indexOf('e') < 0 | |
| 658 | 659 | && string.indexOf('E') < 0) { | |
| 659 | 660 | while (string.endsWith("0")) { | |
@@ -1130,8 +1131,8 @@ public static String numberToString(Number number) throws JSONException { | |||
| 1130 | 1131 | testValidity(number); | |
| 1131 | 1132 | ||
| 1132 | 1133 | // Shave off trailing zeros and decimal point, if possible. | |
| 1133 | - | ||
| 1134 | 1134 | String string = number.toString(); | |
| 1135 | + // idx = 0 case is covered by behavior of .toString() | ||
| 1135 | 1136 | if (string.indexOf('.') > 0 && string.indexOf('e') < 0 | |
| 1136 | 1137 | && string.indexOf('E') < 0) { | |
| 1137 | 1138 | while (string.endsWith("0")) { | |
@@ -1397,11 +1398,13 @@ static BigInteger objectToBigInteger(Object val, BigInteger defaultValue) { | |||
| 1397 | 1398 | } | |
| 1398 | 1399 | // don't check if it's a string in case of unchecked Number subclasses | |
| 1399 | 1400 | try { | |
| 1400 | - // the other opt functions handle implicit conversions, i.e. | ||
| 1401 | - // jo.put("double",1.1d); | ||
| 1402 | - // jo.optInt("double"); -- will return 1, not an error | ||
| 1403 | - // this conversion to BigDecimal then to BigInteger is to maintain | ||
| 1404 | - // 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 | + */ | ||
| 1405 | 1408 | final String valStr = val.toString(); | |
| 1406 | 1409 | if(isDecimalNotation(valStr)) { | |
| 1407 | 1410 | return new BigDecimal(valStr).toBigInteger(); | |
@@ -1505,11 +1508,7 @@ public float optFloat(String key, float defaultValue) { | |||
| 1505 | 1508 | if (val == null) { | |
| 1506 | 1509 | return defaultValue; | |
| 1507 | 1510 | } | |
| 1508 | - final float floatValue = val.floatValue(); | ||
| 1509 | - // if (Float.isNaN(floatValue) || Float.isInfinite(floatValue)) { | ||
| 1510 | - // return defaultValue; | ||
| 1511 | - // } | ||
| 1512 | - return floatValue; | ||
| 1511 | + return val.floatValue(); | ||
| 1513 | 1512 | } | |
| 1514 | 1513 | ||
| 1515 | 1514 | /** | |
@@ -1541,11 +1540,7 @@ public Float optFloatObject(String key, Float defaultValue) { | |||
| 1541 | 1540 | if (val == null) { | |
| 1542 | 1541 | return defaultValue; | |
| 1543 | 1542 | } | |
| 1544 | - final Float floatValue = val.floatValue(); | ||
| 1545 | - // if (Float.isNaN(floatValue) || Float.isInfinite(floatValue)) { | ||
| 1546 | - // return defaultValue; | ||
| 1547 | - // } | ||
| 1548 | - return floatValue; | ||
| 1543 | + return val.floatValue(); | ||
| 1549 | 1544 | } | |
| 1550 | 1545 | ||
| 1551 | 1546 | /** | |
@@ -1916,7 +1911,7 @@ private static String getKeyNameFromMethod(Method method) { | |||
| 1916 | 1911 | // if the first letter in the key is not uppercase, then skip. | |
| 1917 | 1912 | // This is to maintain backwards compatibility before PR406 | |
| 1918 | 1913 | // (https://github.com/stleary/JSON-java/pull/406/) | |
| 1919 | - if (key.length() == 0 || Character.isLowerCase(key.charAt(0))) { | ||
| 1914 | + if (key.isEmpty() || Character.isLowerCase(key.charAt(0))) { | ||
| 1920 | 1915 | return null; | |
| 1921 | 1916 | } | |
| 1922 | 1917 | if (key.length() == 1) { | |
@@ -1963,6 +1958,7 @@ private static void closeClosable(Object input) { | |||
| 1963 | 1958 | try { | |
| 1964 | 1959 | ((Closeable) input).close(); | |
| 1965 | 1960 | } catch (IOException ignore) { | |
| 1961 | + // close has failed; best effort has been made | ||
| 1966 | 1962 | } | |
| 1967 | 1963 | } | |
| 1968 | 1964 | } | |
@@ -1982,7 +1978,7 @@ private static void closeClosable(Object input) { | |||
| 1982 | 1978 | * or one of its super class definitions | |
| 1983 | 1979 | */ | |
| 1984 | 1980 | private static <A extends Annotation> A getAnnotation(final Method m, final Class<A> annotationClass) { | |
| 1985 | - // if we have invalid data the result is null | ||
| 1981 | + // If we have invalid data the result is null | ||
| 1986 | 1982 | if (m == null || annotationClass == null) { | |
| 1987 | 1983 | return null; | |
| 1988 | 1984 | } | |
@@ -1991,7 +1987,7 @@ private static <A extends Annotation> A getAnnotation(final Method m, final Clas | |||
| 1991 | 1987 | return m.getAnnotation(annotationClass); | |
| 1992 | 1988 | } | |
| 1993 | 1989 | ||
| 1994 | - // if we've already reached the Object class, return null; | ||
| 1990 | + // If we've already reached the Object class, return null; | ||
| 1995 | 1991 | Class<?> c = m.getDeclaringClass(); | |
| 1996 | 1992 | if (c.getSuperclass() == null) { | |
| 1997 | 1993 | return null; | |
@@ -2003,13 +1999,13 @@ private static <A extends Annotation> A getAnnotation(final Method m, final Clas | |||
| 2003 | 1999 | Method im = i.getMethod(m.getName(), m.getParameterTypes()); | |
| 2004 | 2000 | return getAnnotation(im, annotationClass); | |
| 2005 | 2001 | } catch (final SecurityException ex) { | |
| 2006 | - continue; | ||
| 2002 | + // ignore this exception | ||
| 2007 | 2003 | } catch (final NoSuchMethodException ex) { | |
| 2008 | - continue; | ||
| 2004 | + // ignore this excpetion | ||
| 2009 | 2005 | } | |
| 2010 | 2006 | } | |
| 2011 | 2007 | ||
| 2012 | - //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 | ||
| 2013 | 2009 | if (Object.class.equals(c.getSuperclass())) | |
| 2014 | 2010 | return null; | |
| 2015 | 2011 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments