Skip to content

Commit

Permalink
Replace 'new Integer/Double/Long' by Integer/Double/Long.valueOf
Browse files Browse the repository at this point in the history
This constructor is deprecated since Java 9
  • Loading branch information
rPraml authored and gbrail committed Oct 15, 2021
1 parent 43793a4 commit edbd080
Show file tree
Hide file tree
Showing 13 changed files with 35 additions and 35 deletions.
2 changes: 1 addition & 1 deletion examples/Matrix.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public boolean has(int index, Scriptable start) {
@Override
public Object get(String name, Scriptable start) {
if (name.equals("dim"))
return new Integer(dim);
return Integer.valueOf(dim);

return NOT_FOUND;
}
Expand Down
2 changes: 1 addition & 1 deletion examples/RunScript4.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static void main(String args[])
// the top-level variable "myCounter". This is
// equivalent to the JavaScript code
// myCounter = new Counter(7);
Object[] arg = { new Integer(7) };
Object[] arg = { Integer.valueOf(7) };
Scriptable myCounter = cx.newObject(scope, "Counter", arg);
scope.put("myCounter", scope, myCounter);

Expand Down
2 changes: 1 addition & 1 deletion src/org/mozilla/javascript/ObjToIntMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ private static Object testKey(int i) {
return testPool[i];
}
}
Object x = new Double(i + 0.5);
Object x = Double.valueOf(i + 0.5);
if (0 <= i && i < MAX_POOL) {
if (testPool == null) {
testPool = new Object[MAX_POOL];
Expand Down
8 changes: 4 additions & 4 deletions src/org/mozilla/javascript/UintMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ private static void testHash(UintMap map, int N) {
System.out.print("."); System.out.flush();
for (int i = 0; i != N; ++i) {
map.put(i, new Integer(i));
map.put(i, Integer.valueOf(i));
check(-1 == map.getInt(i, -1));
Integer obj = (Integer)map.getObject(i);
check(obj != null && i == obj.intValue());
Expand Down Expand Up @@ -500,7 +500,7 @@ private static void testHash(UintMap map, int N) {
System.out.print("."); System.out.flush();
for (int i = 0; i != N; ++i) {
map.put(i * i, new Integer(i));
map.put(i * i, Integer.valueOf(i));
check(-1 == map.getInt(i * i, -1));
map.remove(i * i);
check(!map.has(i * i));
Expand All @@ -523,7 +523,7 @@ private static void testHash(UintMap map, int N) {
check(map.size() == 0);
for (int i = 0; i != N; ++i) {
map.put(i * i, i);
map.put(i * i + 1, new Double(i+0.5));
map.put(i * i + 1, Double.valueOf(i+0.5));
}
checkSameMaps(map, (UintMap)writeAndRead(map));
Expand Down Expand Up @@ -555,7 +555,7 @@ private static void testHash(UintMap map, int N) {
System.out.print("."); System.out.flush();
map = new UintMap();
for (int i = 0; i != N; ++i) {
map.put(2*i+1, new Double(i + 10));
map.put(2*i+1, Double.valueOf(i + 10));
}
for (int i = 0; i != N / 2; ++i) {
map.remove(2*i+1);
Expand Down
2 changes: 1 addition & 1 deletion src/org/mozilla/javascript/optimizer/Optimizer.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ private void optimizeFunction(OptFunctionNode theFunction) {
and if the parameter is being referenced in an Object context, the code is
if ("parameter_objectValue" == java/lang/Void.TYPE)
new Double(parameter_doubleValue)
Double.valueOf(parameter_doubleValue)
else
...fine..., use the parameter_objectValue
Expand Down
2 changes: 1 addition & 1 deletion testsrc/org/mozilla/javascript/tests/Bug409702Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void testAdapter() {
try {
Scriptable scope = cx.initStandardObjects();
Object result = cx.evaluateString(scope, source, "source", 1, null);
assertEquals(new Integer(value), result);
assertEquals(Integer.valueOf(value), result);
} finally {
Context.exit();
}
Expand Down
2 changes: 1 addition & 1 deletion testsrc/org/mozilla/javascript/tests/Bug419940Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public void testAdapter() {
try {
Scriptable scope = cx.initStandardObjects();
Object result = cx.evaluateString(scope, source, "source", 1, null);
assertEquals(new Integer(value), result);
assertEquals(Integer.valueOf(value), result);
} finally {
Context.exit();
}
Expand Down
4 changes: 2 additions & 2 deletions testsrc/org/mozilla/javascript/tests/Bug448816Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ protected void setUp() {
reference.put("a", "a");
reference.put("b", Boolean.TRUE);
reference.put("c", new HashMap<Object, Object>());
reference.put(new Integer(1), new Integer(42));
reference.put(Integer.valueOf(1), Integer.valueOf(42));
// get a js object as map
Context context = Context.enter();
ScriptableObject scope = context.initStandardObjects();
Expand All @@ -53,7 +53,7 @@ public void testBasicAccess() {
assertEquals(map.get("a"), reference.get("a"));
assertEquals(map.get("b"), reference.get("b"));
assertEquals(map.get("c"), reference.get("c"));
assertEquals(map.get(new Integer(1)), reference.get(new Integer(1)));
assertEquals(map.get(Integer.valueOf(1)), reference.get(Integer.valueOf(1)));
assertEquals(map.get("notfound"), reference.get("notfound"));
assertTrue(map.containsKey("b"));
assertTrue(map.containsValue(Boolean.TRUE));
Expand Down
2 changes: 1 addition & 1 deletion testsrc/org/mozilla/javascript/tests/Bug466207Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ protected void setUp() {
reference.add("a");
reference.add(Boolean.TRUE);
reference.add(new HashMap<Object, Object>());
reference.add(new Integer(42));
reference.add(Integer.valueOf(42));
reference.add("a");
// get a js object as map
Context context = Context.enter();
Expand Down
10 changes: 5 additions & 5 deletions testsrc/org/mozilla/javascript/tests/ContinuationsApiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public void testScriptWithContinuations() {
} catch (ContinuationPending pending) {

Object applicationState = pending.getApplicationState();
assertEquals(new Integer(3), applicationState);
assertEquals(Integer.valueOf(3), applicationState);
int saved = (Integer) applicationState;
Object result = cx.resumeContinuation(pending.getContinuation(), globalScope, saved + 1);
assertEquals(5, ((Number)result).intValue());
Expand All @@ -119,13 +119,13 @@ public void testScriptWithMultipleContinuations() {
} catch (ContinuationPending pending) {
try {
Object applicationState = pending.getApplicationState();
assertEquals(new Integer(3), applicationState);
assertEquals(Integer.valueOf(3), applicationState);
int saved = (Integer) applicationState;
cx.resumeContinuation(pending.getContinuation(), globalScope, saved + 1);
fail("Should throw another ContinuationPending");
} catch (ContinuationPending pending2) {
Object applicationState2 = pending2.getApplicationState();
assertEquals(new Integer(6), applicationState2);
assertEquals(Integer.valueOf(6), applicationState2);
int saved2 = (Integer) applicationState2;
Object result2 = cx.resumeContinuation(pending2.getContinuation(), globalScope, saved2 + 1);
assertEquals(13, ((Number)result2).intValue());
Expand All @@ -146,13 +146,13 @@ public void testScriptWithNestedContinuations() {
} catch (ContinuationPending pending) {
try {
Object applicationState = pending.getApplicationState();
assertEquals(new Integer(1), applicationState);
assertEquals(Integer.valueOf(1), applicationState);
int saved = (Integer) applicationState;
cx.resumeContinuation(pending.getContinuation(), globalScope, saved + 1);
fail("Should throw another ContinuationPending");
} catch (ContinuationPending pending2) {
Object applicationState2 = pending2.getApplicationState();
assertEquals(new Integer(4), applicationState2);
assertEquals(Integer.valueOf(4), applicationState2);
int saved2 = (Integer) applicationState2;
Object result2 = cx.resumeContinuation(pending2.getContinuation(), globalScope, saved2 + 2);
assertEquals(8, ((Number)result2).intValue());
Expand Down
24 changes: 12 additions & 12 deletions testsrc/org/mozilla/javascript/tests/JavaAcessibilityTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ protected boolean hasFeature(Context cx, int featureIndex) {

public void testAccessingFields() {
Object result = runScript(importClass + "PrivateAccessClass.staticPackagePrivateInt");
assertEquals(new Integer(0), result);
assertEquals(Integer.valueOf(0), result);

result = runScript(importClass + "PrivateAccessClass.staticPrivateInt");
assertEquals(new Integer(1), result);
assertEquals(Integer.valueOf(1), result);

result = runScript(importClass + "PrivateAccessClass.staticProtectedInt");
assertEquals(new Integer(2), result);
assertEquals(Integer.valueOf(2), result);

result = runScript(importClass + "new PrivateAccessClass().packagePrivateString");
assertEquals("package private", ((NativeJavaObject) result).unwrap());
Expand All @@ -68,33 +68,33 @@ public void testAccessingFields() {
assertEquals("protected", ((NativeJavaObject) result).unwrap());

result = runScript(importClass + "new PrivateAccessClass.PrivateNestedClass().packagePrivateInt");
assertEquals(new Integer(0), result);
assertEquals(Integer.valueOf(0), result);

result = runScript(importClass + "new PrivateAccessClass.PrivateNestedClass().privateInt");
assertEquals(new Integer(1), result);
assertEquals(Integer.valueOf(1), result);

result = runScript(importClass + "new PrivateAccessClass.PrivateNestedClass().protectedInt");
assertEquals(new Integer(2), result);
assertEquals(Integer.valueOf(2), result);
}

public void testAccessingMethods() {
Object result = runScript(importClass + "PrivateAccessClass.staticPackagePrivateMethod()");
assertEquals(new Integer(0), result);
assertEquals(Integer.valueOf(0), result);

result = runScript(importClass + "PrivateAccessClass.staticPrivateMethod()");
assertEquals(new Integer(1), result);
assertEquals(Integer.valueOf(1), result);

result = runScript(importClass + "PrivateAccessClass.staticProtectedMethod()");
assertEquals(new Integer(2), result);
assertEquals(Integer.valueOf(2), result);

result = runScript(importClass + "new PrivateAccessClass().packagePrivateMethod()");
assertEquals(new Integer(3), result);
assertEquals(Integer.valueOf(3), result);

result = runScript(importClass + "new PrivateAccessClass().privateMethod()");
assertEquals(new Integer(4), result);
assertEquals(Integer.valueOf(4), result);

result = runScript(importClass + "new PrivateAccessClass().protectedMethod()");
assertEquals(new Integer(5), result);
assertEquals(Integer.valueOf(5), result);
}

public void testAccessingConstructors() {
Expand Down
8 changes: 4 additions & 4 deletions testsrc/org/mozilla/javascript/tests/WrapFactoryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public class WrapFactoryTest {
public void primitiveWrapTrue() {
test(true, "text", "string", "object", "object");
test(true, Boolean.FALSE, "boolean", "object", "object");
test(true, new Integer(1), "number", "object", "object");
test(true, new Long(2L), "number", "object", "object");
test(true, Integer.valueOf(1), "number", "object", "object");
test(true, Long.valueOf(2L), "number", "object", "object");
test(true, new BigInteger("3"), "bigint", "object", "object");
test(true, new BigDecimal("4.0"), "number", "object", "object");
}
Expand All @@ -37,8 +37,8 @@ public void primitiveWrapTrue() {
public void primitiveWrapFalse() {
test(false, "text", "string", "string", "string"); // Great! I want to do this.
test(false, Boolean.FALSE, "boolean", "boolean", "boolean");
test(false, new Integer(1), "number", "number", "number");
test(false, new Long(2L), "number", "number", "number");
test(false, Integer.valueOf(1), "number", "number", "number");
test(false, Long.valueOf(2L), "number", "number", "number");

test(false, new BigInteger("30"), "bigint", "bigint", "bigint");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,7 @@ static void setResizeWeight(JSplitPane pane, double weight) {
try {
Method m = JSplitPane.class.getMethod("setResizeWeight",
new Class[]{double.class});
m.invoke(pane, new Object[]{new Double(weight)});
m.invoke(pane, new Object[]{Double.valueOf(weight)});
} catch (NoSuchMethodException exc) {
} catch (IllegalAccessException exc) {
} catch (java.lang.reflect.InvocationTargetException exc) {
Expand Down

0 comments on commit edbd080

Please sign in to comment.