Skip to content

Commit 01727fd

Browse files
authored
Merge pull request stleary#769 from jscrdev/fixed-warnings
Addressed Java 17 compile warnings
2 parents c29d488 + 74cd73f commit 01727fd

2 files changed

Lines changed: 50 additions & 51 deletions

File tree

src/test/java/org/json/junit/JSONArrayTest.java

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -368,26 +368,26 @@ public void getArrayValues() {
368368
"hello".equals(jsonArray.getString(4)));
369369
// doubles
370370
assertTrue("Array double",
371-
new Double(23.45e-4).equals(jsonArray.getDouble(5)));
371+
Double.valueOf(23.45e-4).equals(jsonArray.getDouble(5)));
372372
assertTrue("Array string double",
373-
new Double(23.45).equals(jsonArray.getDouble(6)));
373+
Double.valueOf(23.45).equals(jsonArray.getDouble(6)));
374374
assertTrue("Array double can be float",
375-
new Float(23.45e-4f).equals(jsonArray.getFloat(5)));
375+
Float.valueOf(23.45e-4f).equals(jsonArray.getFloat(5)));
376376
// ints
377377
assertTrue("Array value int",
378-
new Integer(42).equals(jsonArray.getInt(7)));
378+
Integer.valueOf(42).equals(jsonArray.getInt(7)));
379379
assertTrue("Array value string int",
380-
new Integer(43).equals(jsonArray.getInt(8)));
380+
Integer.valueOf(43).equals(jsonArray.getInt(8)));
381381
// nested objects
382382
JSONArray nestedJsonArray = jsonArray.getJSONArray(9);
383383
assertTrue("Array value JSONArray", nestedJsonArray != null);
384384
JSONObject nestedJsonObject = jsonArray.getJSONObject(10);
385385
assertTrue("Array value JSONObject", nestedJsonObject != null);
386386
// longs
387387
assertTrue("Array value long",
388-
new Long(0).equals(jsonArray.getLong(11)));
388+
Long.valueOf(0).equals(jsonArray.getLong(11)));
389389
assertTrue("Array value string long",
390-
new Long(-1).equals(jsonArray.getLong(12)));
390+
Long.valueOf(-1).equals(jsonArray.getLong(12)));
391391

392392
assertTrue("Array value null", jsonArray.isNull(-1));
393393
Util.checkJSONArrayMaps(jsonArray);
@@ -545,11 +545,11 @@ public void opt() {
545545
Boolean.FALSE.equals(jsonArray.optBooleanObject(-1)));
546546

547547
assertTrue("Array opt double",
548-
new Double(23.45e-4).equals(jsonArray.optDouble(5)));
548+
Double.valueOf(23.45e-4).equals(jsonArray.optDouble(5)));
549549
assertTrue("Array opt double default",
550-
new Double(1).equals(jsonArray.optDouble(0, 1)));
550+
Double.valueOf(1).equals(jsonArray.optDouble(0, 1)));
551551
assertTrue("Array opt double default implicit",
552-
new Double(jsonArray.optDouble(99)).isNaN());
552+
Double.valueOf(jsonArray.optDouble(99)).isNaN());
553553

554554
assertTrue("Array opt double object",
555555
Double.valueOf(23.45e-4).equals(jsonArray.optDoubleObject(5)));
@@ -559,11 +559,11 @@ public void opt() {
559559
jsonArray.optDoubleObject(99).isNaN());
560560

561561
assertTrue("Array opt float",
562-
new Float(23.45e-4).equals(jsonArray.optFloat(5)));
562+
Float.valueOf(Double.valueOf(23.45e-4).floatValue()).equals(jsonArray.optFloat(5)));
563563
assertTrue("Array opt float default",
564-
new Float(1).equals(jsonArray.optFloat(0, 1)));
564+
Float.valueOf(1).equals(jsonArray.optFloat(0, 1)));
565565
assertTrue("Array opt float default implicit",
566-
new Float(jsonArray.optFloat(99)).isNaN());
566+
Float.valueOf(jsonArray.optFloat(99)).isNaN());
567567

568568
assertTrue("Array opt float object",
569569
Float.valueOf(23.45e-4F).equals(jsonArray.optFloatObject(5)));
@@ -575,14 +575,14 @@ public void opt() {
575575
assertTrue("Array opt Number",
576576
BigDecimal.valueOf(23.45e-4).equals(jsonArray.optNumber(5)));
577577
assertTrue("Array opt Number default",
578-
new Double(1).equals(jsonArray.optNumber(0, 1d)));
578+
Double.valueOf(1).equals(jsonArray.optNumber(0, 1d)));
579579
assertTrue("Array opt Number default implicit",
580-
new Double(jsonArray.optNumber(99,Double.NaN).doubleValue()).isNaN());
580+
Double.valueOf(jsonArray.optNumber(99,Double.NaN).doubleValue()).isNaN());
581581

582582
assertTrue("Array opt int",
583-
new Integer(42).equals(jsonArray.optInt(7)));
583+
Integer.valueOf(42).equals(jsonArray.optInt(7)));
584584
assertTrue("Array opt int default",
585-
new Integer(-1).equals(jsonArray.optInt(0, -1)));
585+
Integer.valueOf(-1).equals(jsonArray.optInt(0, -1)));
586586
assertTrue("Array opt int default implicit",
587587
0 == jsonArray.optInt(0));
588588

@@ -1011,12 +1011,12 @@ public void iteratorTest() {
10111011
assertTrue("Array double [23.45e-4]",
10121012
new BigDecimal("0.002345").equals(it.next()));
10131013
assertTrue("Array string double",
1014-
new Double(23.45).equals(Double.parseDouble((String)it.next())));
1014+
Double.valueOf(23.45).equals(Double.parseDouble((String)it.next())));
10151015

10161016
assertTrue("Array value int",
1017-
new Integer(42).equals(it.next()));
1017+
Integer.valueOf(42).equals(it.next()));
10181018
assertTrue("Array value string int",
1019-
new Integer(43).equals(Integer.parseInt((String)it.next())));
1019+
Integer.valueOf(43).equals(Integer.parseInt((String)it.next())));
10201020

10211021
JSONArray nestedJsonArray = (JSONArray)it.next();
10221022
assertTrue("Array value JSONArray", nestedJsonArray != null);
@@ -1025,9 +1025,9 @@ public void iteratorTest() {
10251025
assertTrue("Array value JSONObject", nestedJsonObject != null);
10261026

10271027
assertTrue("Array value long",
1028-
new Long(0).equals(((Number) it.next()).longValue()));
1028+
Long.valueOf(0).equals(((Number) it.next()).longValue()));
10291029
assertTrue("Array value string long",
1030-
new Long(-1).equals(Long.parseLong((String) it.next())));
1030+
Long.valueOf(-1).equals(Long.parseLong((String) it.next())));
10311031
assertTrue("should be at end of array", !it.hasNext());
10321032
Util.checkJSONArraysMaps(new ArrayList<JSONArray>(Arrays.asList(
10331033
jsonArray, nestedJsonArray

src/test/java/org/json/junit/JSONObjectTest.java

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@
5454
import org.json.junit.data.SingletonEnum;
5555
import org.json.junit.data.WeirdList;
5656
import org.junit.Test;
57-
import org.json.junit.Util;
5857

5958
import com.jayway.jsonpath.Configuration;
6059
import com.jayway.jsonpath.JsonPath;
@@ -304,12 +303,12 @@ public void jsonObjectByNullMap() {
304303
@Test
305304
public void jsonObjectByMap() {
306305
Map<String, Object> map = new HashMap<String, Object>();
307-
map.put("trueKey", new Boolean(true));
308-
map.put("falseKey", new Boolean(false));
306+
map.put("trueKey", Boolean.valueOf(true));
307+
map.put("falseKey", Boolean.valueOf(false));
309308
map.put("stringKey", "hello world!");
310309
map.put("escapeStringKey", "h\be\tllo w\u1234orld!");
311-
map.put("intKey", new Long(42));
312-
map.put("doubleKey", new Double(-23.45e67));
310+
map.put("intKey", Long.valueOf(42));
311+
map.put("doubleKey", Double.valueOf(-23.45e67));
313312
JSONObject jsonObject = new JSONObject(map);
314313

315314
// validate JSON
@@ -570,13 +569,13 @@ public void jsonObjectByMapWithUnsupportedValues() {
570569
@Test
571570
public void jsonObjectByMapWithNullValue() {
572571
Map<String, Object> map = new HashMap<String, Object>();
573-
map.put("trueKey", new Boolean(true));
574-
map.put("falseKey", new Boolean(false));
572+
map.put("trueKey", Boolean.valueOf(true));
573+
map.put("falseKey", Boolean.valueOf(false));
575574
map.put("stringKey", "hello world!");
576575
map.put("nullKey", null);
577576
map.put("escapeStringKey", "h\be\tllo w\u1234orld!");
578-
map.put("intKey", new Long(42));
579-
map.put("doubleKey", new Double(-23.45e67));
577+
map.put("intKey", Long.valueOf(42));
578+
map.put("doubleKey", Double.valueOf(-23.45e67));
580579
JSONObject jsonObject = new JSONObject(map);
581580

582581
// validate JSON
@@ -996,7 +995,7 @@ public void stringToValueNumbersTest() {
996995
assertTrue( "0.2 should be a BigDecimal!",
997996
JSONObject.stringToValue( "0.2" ) instanceof BigDecimal );
998997
assertTrue( "Doubles should be BigDecimal, even when incorrectly converting floats!",
999-
JSONObject.stringToValue( new Double( "0.2f" ).toString() ) instanceof BigDecimal );
998+
JSONObject.stringToValue( Double.valueOf( "0.2f" ).toString() ) instanceof BigDecimal );
1000999
/**
10011000
* This test documents a need for BigDecimal conversion.
10021001
*/
@@ -1006,13 +1005,13 @@ public void stringToValueNumbersTest() {
10061005
assertTrue( "1 should be an Integer!",
10071006
JSONObject.stringToValue( "1" ) instanceof Integer );
10081007
assertTrue( "Integer.MAX_VALUE should still be an Integer!",
1009-
JSONObject.stringToValue( new Integer( Integer.MAX_VALUE ).toString() ) instanceof Integer );
1008+
JSONObject.stringToValue( Integer.valueOf( Integer.MAX_VALUE ).toString() ) instanceof Integer );
10101009
assertTrue( "Large integers should be a Long!",
10111010
JSONObject.stringToValue( Long.valueOf(((long)Integer.MAX_VALUE) + 1 ) .toString() ) instanceof Long );
10121011
assertTrue( "Long.MAX_VALUE should still be an Integer!",
1013-
JSONObject.stringToValue( new Long( Long.MAX_VALUE ).toString() ) instanceof Long );
1012+
JSONObject.stringToValue( Long.valueOf( Long.MAX_VALUE ).toString() ) instanceof Long );
10141013

1015-
String str = new BigInteger( new Long( Long.MAX_VALUE ).toString() ).add( BigInteger.ONE ).toString();
1014+
String str = new BigInteger( Long.valueOf( Long.MAX_VALUE ).toString() ).add( BigInteger.ONE ).toString();
10161015
assertTrue( "Really large integers currently evaluate to BigInteger",
10171016
JSONObject.stringToValue(str).equals(new BigInteger("9223372036854775808")));
10181017
}
@@ -1259,8 +1258,8 @@ public void unexpectedDoubleToIntConversion() {
12591258
String key30 = "key30";
12601259
String key31 = "key31";
12611260
JSONObject jsonObject = new JSONObject();
1262-
jsonObject.put(key30, new Double(3.0));
1263-
jsonObject.put(key31, new Double(3.1));
1261+
jsonObject.put(key30, Double.valueOf(3.0));
1262+
jsonObject.put(key31, Double.valueOf(3.1));
12641263

12651264
assertTrue("3.0 should remain a double",
12661265
jsonObject.getDouble(key30) == 3);
@@ -1713,19 +1712,19 @@ public void jsonObjectIncrement() {
17131712
*/
17141713
assertFalse("Document unexpected behaviour with explicit type-casting float as double!", (double)0.2f == 0.2d );
17151714
assertFalse("Document unexpected behaviour with implicit type-cast!", 0.2f == 0.2d );
1716-
Double d1 = new Double( 1.1f );
1717-
Double d2 = new Double( "1.1f" );
1715+
Double d1 = Double.valueOf( 1.1f );
1716+
Double d2 = Double.valueOf( "1.1f" );
17181717
assertFalse( "Document implicit type cast from float to double before calling Double(double d) constructor", d1.equals( d2 ) );
17191718

1720-
assertTrue( "Correctly converting float to double via base10 (string) representation!", new Double( 3.1d ).equals( new Double( new Float( 3.1f ).toString() ) ) );
1719+
assertTrue( "Correctly converting float to double via base10 (string) representation!", Double.valueOf( 3.1d ).equals( Double.valueOf( Float.valueOf( 3.1f ).toString() ) ) );
17211720

17221721
// Pinpointing the not so obvious "buggy" conversion from float to double in JSONObject
17231722
JSONObject jo = new JSONObject();
17241723
jo.put( "bug", 3.1f ); // will call put( String key, double value ) with implicit and "buggy" type-cast from float to double
1725-
assertFalse( "The java-compiler did add some zero bits for you to the mantissa (unexpected, but well documented)", jo.get( "bug" ).equals( new Double( 3.1d ) ) );
1724+
assertFalse( "The java-compiler did add some zero bits for you to the mantissa (unexpected, but well documented)", jo.get( "bug" ).equals( Double.valueOf( 3.1d ) ) );
17261725

17271726
JSONObject inc = new JSONObject();
1728-
inc.put( "bug", new Float( 3.1f ) ); // This will put in instance of Float into JSONObject, i.e. call put( String key, Object value )
1727+
inc.put( "bug", Float.valueOf( 3.1f ) ); // This will put in instance of Float into JSONObject, i.e. call put( String key, Object value )
17291728
assertTrue( "Everything is ok here!", inc.get( "bug" ) instanceof Float );
17301729
inc.increment( "bug" ); // after adding 1, increment will call put( String key, double value ) with implicit and "buggy" type-cast from float to double!
17311730
// this.put(key, (Float) value + 1);
@@ -2040,14 +2039,14 @@ public void valueToString() {
20402039
assertTrue("map valueToString() incorrect",
20412040
jsonObject.toString().equals(JSONObject.valueToString(map)));
20422041
Collection<Integer> collection = new ArrayList<Integer>();
2043-
collection.add(new Integer(1));
2044-
collection.add(new Integer(2));
2045-
collection.add(new Integer(3));
2042+
collection.add(Integer.valueOf(1));
2043+
collection.add(Integer.valueOf(2));
2044+
collection.add(Integer.valueOf(3));
20462045
assertTrue("collection valueToString() expected: "+
20472046
jsonArray.toString()+ " actual: "+
20482047
JSONObject.valueToString(collection),
20492048
jsonArray.toString().equals(JSONObject.valueToString(collection)));
2050-
Integer[] array = { new Integer(1), new Integer(2), new Integer(3) };
2049+
Integer[] array = { Integer.valueOf(1), Integer.valueOf(2), Integer.valueOf(3) };
20512050
assertTrue("array valueToString() incorrect",
20522051
jsonArray.toString().equals(JSONObject.valueToString(array)));
20532052
Util.checkJSONObjectMaps(jsonObject);
@@ -2085,7 +2084,7 @@ public void wrapObject() {
20852084
JSONObject.NULL == JSONObject.wrap(null));
20862085

20872086
// wrap(Integer) returns Integer
2088-
Integer in = new Integer(1);
2087+
Integer in = Integer.valueOf(1);
20892088
assertTrue("Integer wrap() incorrect",
20902089
in == JSONObject.wrap(in));
20912090

@@ -2112,9 +2111,9 @@ public void wrapObject() {
21122111

21132112
// wrap collection returns JSONArray
21142113
Collection<Integer> collection = new ArrayList<Integer>();
2115-
collection.add(new Integer(1));
2116-
collection.add(new Integer(2));
2117-
collection.add(new Integer(3));
2114+
collection.add(Integer.valueOf(1));
2115+
collection.add(Integer.valueOf(2));
2116+
collection.add(Integer.valueOf(3));
21182117
JSONArray jsonArray = (JSONArray) (JSONObject.wrap(collection));
21192118

21202119
// validate JSON
@@ -2125,7 +2124,7 @@ public void wrapObject() {
21252124
assertTrue("expected 3", Integer.valueOf(3).equals(jsonArray.query("/2")));
21262125

21272126
// wrap Array returns JSONArray
2128-
Integer[] array = { new Integer(1), new Integer(2), new Integer(3) };
2127+
Integer[] array = { Integer.valueOf(1), Integer.valueOf(2), Integer.valueOf(3) };
21292128
JSONArray integerArrayJsonArray = (JSONArray)(JSONObject.wrap(array));
21302129

21312130
// validate JSON

0 commit comments

Comments
 (0)