Skip to content

Commit

Permalink
Remove uses of primitive constructors
Browse files Browse the repository at this point in the history
these constructors are deprecated in JDK 16, which results in spurious
diagnostics in these tests.

PiperOrigin-RevId: 347858153
  • Loading branch information
cushon authored and Error Prone Team committed Dec 16, 2020
1 parent 1b578c8 commit affa419
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -413,9 +413,9 @@ public void listOfClassOrDistinctInstances_uniqueElements_iterating_replacesWith
"import java.util.ArrayList;",
"class Test {",
" private static final ImmutableList<Class<?>> CLS_LIST = ",
" ImmutableList.of(Long.class, Double.class);",
" ImmutableList.of(Long.class, Double.class);",
" private static final ImmutableList<Object> OBJ_LIST =",
" ImmutableList.of(new Long(1), new Double(2.0));",
" ImmutableList.of(new String(\"\"), new Object());",
" private void myFunc() {",
" CLS_LIST.stream().forEach(System.out::println);",
" OBJ_LIST.forEach(System.out::println);",
Expand All @@ -430,9 +430,9 @@ public void listOfClassOrDistinctInstances_uniqueElements_iterating_replacesWith
"import java.util.ArrayList;",
"class Test {",
" private static final ImmutableSet<Class<?>> CLS_LIST = ",
" ImmutableSet.of(Long.class, Double.class);",
" ImmutableSet.of(Long.class, Double.class);",
" private static final ImmutableSet<Object> OBJ_LIST =",
" ImmutableSet.of(new Long(1), new Double(2.0));",
" ImmutableSet.of(new String(\"\"), new Object());",
" private void myFunc() {",
" CLS_LIST.stream().forEach(System.out::println);",
" OBJ_LIST.forEach(System.out::println);",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ public void testRefactoringGenericToPrimitive() {
"import java.util.function.Function;",
" public class NumbertoT { ",
" private <T> int sumAll(Function<T, Integer> sizeConv) {",
" return sizeConv.apply((T) new Integer(3));",
" return sizeConv.apply((T) Integer.valueOf(3));",
" }",
" public int getSumAll() {",
" return sumAll(o -> 2);",
Expand All @@ -206,7 +206,7 @@ public void testRefactoringGenericToPrimitive() {
" import java.util.function.ToIntFunction;",
" public class NumbertoT { ",
" private <T> int sumAll(ToIntFunction<T> sizeConv) {",
" return sizeConv.applyAsInt((T) new Integer(3));",
" return sizeConv.applyAsInt((T) Integer.valueOf(3));",
" }",
" public int getSumAll() {",
" return sumAll(o -> 2);",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,14 @@ public void detectsSynchronizedBoxedLocks_encapsulated_boxedInitializers() throw
.addSourceLines(
"Test.java",
"class Test {",
" private Object badByteLock = new Byte((byte)1);",
" private Object badShortLock = new Short((short)1);",
" private Object badIntLock = new Integer(1);",
" private Object badLongLock = new Long(1);",
" private Object badFloatLock = new Float(1.0);",
" private Object badDoubleLock = new Double(1.0);",
" private Object badBooleanLock = new Boolean(false);",
" private Object badCharLock = new Character('c');",
" private Object badByteLock = Byte.valueOf((byte)1);",
" private Object badShortLock = Short.valueOf((short)1);",
" private Object badIntLock = Integer.valueOf(1);",
" private Object badLongLock = Long.valueOf(1);",
" private Object badFloatLock = Float.valueOf(1.0f);",
" private Object badDoubleLock = Double.valueOf(1.0);",
" private Object badBooleanLock = Boolean.valueOf(false);",
" private Object badCharLock = Character.valueOf('c');",
" private void test() {",
bugOnSynchronizedBlock("badByteLock"),
bugOnSynchronizedBlock("badShortLock"),
Expand Down Expand Up @@ -258,14 +258,14 @@ public void detectsMonitorMethodBoxedLock_encapsulated_boxedInitializers() throw
.addSourceLines(
"Test.java",
"class Test {",
" private Object badByteLock = new Byte((byte)1);",
" private Object badShortLock = new Short((short)1);",
" private Object badIntLock = new Integer(1);",
" private Object badLongLock = new Long(1);",
" private Object badFloatLock = new Float(1.0);",
" private Object badDoubleLock = new Double(1.0);",
" private Object badBooleanLock = new Boolean(false);",
" private Object badCharLock = new Character('c');",
" private Object badByteLock = Byte.valueOf((byte)1);",
" private Object badShortLock = Short.valueOf((short)1);",
" private Object badIntLock = Integer.valueOf(1);",
" private Object badLongLock = Long.valueOf(1);",
" private Object badFloatLock = Float.valueOf(1.0f);",
" private Object badDoubleLock = Double.valueOf(1.0);",
" private Object badBooleanLock = Boolean.valueOf(false);",
" private Object badCharLock = Character.valueOf('c');",
" private void test() throws InterruptedException {",
bugOnMonitorMethods("badByteLock"),
bugOnMonitorMethods("badShortLock"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ public void deleteRoundMethodIntClass() {
"Test.java", //
"class Test {",
" void f() {",
" Integer i = new Integer(3);",
" Integer i = Integer.valueOf(3);",
" int y = Math.round(i);",
" }",
"}")
.addOutputLines(
"Test.java", //
"class Test {",
" void f() {",
" Integer i = new Integer(3);",
" Integer i = Integer.valueOf(3);",
" int y = i;",
" }",
"}")
Expand Down Expand Up @@ -99,7 +99,7 @@ public void replaceRoundMethodLongClass() {
"Test.java", //
"class Test {",
" void f() {",
" Long l = new Long(\"3\");",
" Long l = Long.valueOf(\"3\");",
" int y = Math.round(l);",
" }",
"}")
Expand All @@ -108,7 +108,7 @@ public void replaceRoundMethodLongClass() {
"import com.google.common.primitives.Ints;",
"class Test {",
" void f() {",
" Long l = new Long(\"3\");",
" Long l = Long.valueOf(\"3\");",
" int y = Ints.saturatedCast(l);",
" }",
"}")
Expand All @@ -122,7 +122,7 @@ public void roundingFloatNegative() {
"Test.java", //
"class Test {",
" void f() {",
" Float f = new Float(\"3\");",
" Float f = Float.valueOf(\"3\");",
" int y = Math.round(f);",
" }",
"}")
Expand All @@ -137,7 +137,7 @@ public void roundingDoubleNegative() {
"Test.java", //
"class Test {",
" void f() {",
" Double d = new Double(\"3\");",
" Double d = Double.valueOf(\"3\");",
" Long y = Math.round(d);",
" }",
"}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ public void hashCodeBoxedPrimitiveNegative() {
"Test.java", //
"import java.util.Objects;",
"class Test {",
" Integer x = new Integer(3);",
" Integer x = Integer.valueOf(3);",
" void f() {",
" int y = Objects.hashCode(x);",
" }",
Expand All @@ -305,7 +305,7 @@ public void hashCodeOtherMethodNegative() {
"Test.java", //
"import java.util.Objects;",
"class Test {",
" Integer x = new Integer(3);",
" Integer x = Integer.valueOf(3);",
" void f() {",
" int y = x.hashCode();",
" }",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ public void unusedLocalVar() {
" notUsedLocal = this.calculate()",
" + 1 ;",
" notUsedLocal--;",
" notUsedLocal += new Integer(1);",
" notUsedLocal += Integer.valueOf(1);",
" System.out.println(usedLocal);",
" }",
" System.out.println(usedLocal);",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public void testMatches_succeedsForCompileTimeConstantFormatString() {
" @FormatMethod public static void log(@FormatString String s, Object... args) {}",
" public static void callLog() {",
" final String formatString = \"%d\";",
" log(formatString, new Integer(0));",
" log(formatString, Integer.valueOf(0));",
" }",
"}")
.doTest();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ static String staticReturnNullable() {
static final String CONSTANT_DERIVED_STRING = CONSTANT_DERIVED_BOOLEAN ? CONSTANT_STRING : "";
static final MyClass CONSTANT_OTHER_CLASS = new MyClass();
static final Integer[] CONSTANT_OBJECT_ARRAY = new Integer[7];
static final Integer[] CONSTANT_ARRAY_INITIALIZER = {new Integer(5)};
static final Integer[] CONSTANT_ARRAY_INITIALIZER = {Integer.valueOf(5)};
static final Object CONSTANT_NO_INITIALIZER;

static {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public void invocationMatchers() {
" // BUG: Diagnostic contains: ",
" String s = \"5\".toString();",
" // BUG: Diagnostic contains: ",
" int result = new Integer(5).compareTo(6);",
" int result = Integer.valueOf(5).compareTo(6);",
" // BUG: Diagnostic contains: ",
" return String.valueOf(5);",
" }",
Expand Down
2 changes: 1 addition & 1 deletion docs/bugpattern/MissingTestCall.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ of any use.
new EqualsTester()
.addEqualityGroup("hello", new String("hello"))
.addEqualityGroup("world", new String("world"))
.addEqualityGroup(2, new Integer(2));
.addEqualityGroup(2, Integer.valueOf(2));
// Oops: forgot to call `testEquals()`
}
```

0 comments on commit affa419

Please sign in to comment.