From a64a935964cc3afd1279aa9d303a01f7ceb7fde2 Mon Sep 17 00:00:00 2001 From: eklaDFF Date: Sat, 3 Aug 2024 14:06:41 +0530 Subject: [PATCH] replace deprecated Constructor based initialization of primitive type's Wrapper Class with WrapperClass.valueOf(value) --- .../test/java/lang/BoxObjectCacheTest.java | 19 +++++++++---------- .../gov/nasa/jpf/test/mc/basic/AttrsTest.java | 2 +- .../nasa/jpf/util/SparseClusterArrayTest.java | 6 +++--- src/tests/java11/StringConcatenationTest.java | 2 +- 4 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/tests/gov/nasa/jpf/test/java/lang/BoxObjectCacheTest.java b/src/tests/gov/nasa/jpf/test/java/lang/BoxObjectCacheTest.java index 9cfc18d3..2e4ceb50 100644 --- a/src/tests/gov/nasa/jpf/test/java/lang/BoxObjectCacheTest.java +++ b/src/tests/gov/nasa/jpf/test/java/lang/BoxObjectCacheTest.java @@ -17,13 +17,12 @@ */ package gov.nasa.jpf.test.java.lang; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; - import gov.nasa.jpf.util.test.TestJPF; - import org.junit.Test; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + /** * regression test for java.lang.Integer */ @@ -135,7 +134,7 @@ public void testIntCacheBoxObject() throws SecurityException, NoSuchMethodExcept Integer i1 = Integer.valueOf( 1); // should be cached assertTrue( i1.intValue() == 1); - Integer i2 = new Integer(1); + Integer i2 = Integer.valueOf(1); Method m = Integer.class.getMethod("intValue", new Class[0]); Integer i3 = (Integer) m.invoke(i2, new Object[0]); assertTrue( i1 == i3); @@ -149,7 +148,7 @@ public void testCharacterCacheBoxObject() throws SecurityException, NoSuchMethod Character c1 = Character.valueOf( '?'); // should be cached assertTrue( c1.charValue() == '?'); - Character c2 = new Character('?'); + Character c2 = Character.valueOf('?'); Method m = Character.class.getMethod("charValue", new Class[0]); Character c3 = (Character) m.invoke(c2, new Object[0]); assertTrue( c1 == c3); @@ -163,7 +162,7 @@ public void testByteCacheBoxObject() throws SecurityException, NoSuchMethodExcep Byte b1 = Byte.valueOf( (byte)1); // should be cached assertTrue( b1.byteValue() == 1); - Byte b2 = new Byte((byte)1); + Byte b2 = Byte.valueOf((byte)1); Method m = Byte.class.getMethod("byteValue", new Class[0]); Byte b3 = (Byte) m.invoke(b2, new Object[0]); assertTrue( b1 == b3); @@ -177,7 +176,7 @@ public void testShortCacheBoxObject() throws SecurityException, NoSuchMethodExce Short s1 = Short.valueOf((short)1); // should be cached assertTrue( s1.shortValue() == 1); - Short s2 = new Short((short)1); + Short s2 = Short.valueOf((short)1); Method m = Short.class.getMethod("shortValue", new Class[0]); Short s3 = (Short) m.invoke(s2, new Object[0]); assertTrue( s1 == s3); @@ -191,7 +190,7 @@ public void testLongCacheBoxObject() throws SecurityException, NoSuchMethodExcep Long l1 = Long.valueOf(1); // should be cached assertTrue( l1.longValue() == 1); - Long l2 = new Long(1); + Long l2 = Long.valueOf(1); Method m = Long.class.getMethod("longValue", new Class[0]); Long l3 = (Long) m.invoke(l2, new Object[0]); assertTrue( l1 == l3); @@ -205,7 +204,7 @@ public void testBooleanCacheBoxObject() throws SecurityException, NoSuchMethodEx Boolean b1 = Boolean.valueOf(true); // should be cached assertTrue( b1.booleanValue() == true); - Boolean b2 = new Boolean(true); + Boolean b2 = Boolean.valueOf(true); Method m = Boolean.class.getMethod("booleanValue", new Class[0]); Boolean b3 = (Boolean) m.invoke(b2, new Object[0]); assertTrue( b1 == b3); diff --git a/src/tests/gov/nasa/jpf/test/mc/basic/AttrsTest.java b/src/tests/gov/nasa/jpf/test/mc/basic/AttrsTest.java index a7b881a6..3087524b 100644 --- a/src/tests/gov/nasa/jpf/test/mc/basic/AttrsTest.java +++ b/src/tests/gov/nasa/jpf/test/mc/basic/AttrsTest.java @@ -361,7 +361,7 @@ int goModel (double d, int i) { } } - @SuppressWarnings("deprecation") + @SuppressWarnings("removal") // Integer o = new Integer(v) @Test public void testInteger() { if (verifyNoPropertyViolation()) { int v = 42; diff --git a/src/tests/gov/nasa/jpf/util/SparseClusterArrayTest.java b/src/tests/gov/nasa/jpf/util/SparseClusterArrayTest.java index 833311fd..e1451082 100644 --- a/src/tests/gov/nasa/jpf/util/SparseClusterArrayTest.java +++ b/src/tests/gov/nasa/jpf/util/SparseClusterArrayTest.java @@ -18,15 +18,15 @@ package gov.nasa.jpf.util; -import static gov.nasa.jpf.util.SparseClusterArray.S1; import gov.nasa.jpf.util.SparseClusterArray.Entry; import gov.nasa.jpf.util.SparseClusterArray.Snapshot; import gov.nasa.jpf.util.test.TestJPF; +import org.junit.Test; import java.util.HashMap; import java.util.Random; -import org.junit.Test; +import static gov.nasa.jpf.util.SparseClusterArray.S1; /** * unit test for gov.nasa.jpf.util.SparseClusterArray @@ -182,7 +182,7 @@ public void testClone() { @Override @SuppressWarnings("deprecation") public Integer clone (Integer other) { - return new Integer(other); + return Integer.valueOf(other); } }; SparseClusterArray newArr = arr.deepCopy(cloner); diff --git a/src/tests/java11/StringConcatenationTest.java b/src/tests/java11/StringConcatenationTest.java index ca21193e..5aad82e9 100644 --- a/src/tests/java11/StringConcatenationTest.java +++ b/src/tests/java11/StringConcatenationTest.java @@ -131,7 +131,7 @@ public void testStringConcatenationWith_multipleStrings() { @Test public void testStringConcatenationWith_mixedTypes() { if (verifyNoPropertyViolation()) { - Character ch = new Character('@'); + Character ch = Character.valueOf('@'); byte b = 10; String name = "xyz"; char dot = '.';