From 215f2563ab098f86f143d59e472b766c9876119a Mon Sep 17 00:00:00 2001 From: cpovirk Date: Fri, 27 Dec 2024 18:45:32 -0800 Subject: [PATCH] Fix or suppress `IdentifierName` (and sometimes `ConstantNameForConstants`) warnings. RELNOTES=n/a PiperOrigin-RevId: 710181163 --- .../AbstractPackageSanityTestsTest.java | 1 + .../concurrent/ExecutionListBenchmark.java | 10 +- .../google/common/base/PredicatesTest.java | 8 +- .../com/google/common/base/SuppliersTest.java | 6 +- .../google/common/collect/OrderingTest.java | 14 +-- .../com/google/common/collect/QueuesTest.java | 24 ++-- .../common/math/BigDecimalMathTest.java | 20 +-- .../common/math/BigIntegerMathTest.java | 20 +-- .../google/common/net/InetAddressesTest.java | 2 + .../AbstractInvocationHandlerTest.java | 4 - .../google/common/reflect/TypeTokenTest.java | 16 +-- .../com/google/common/reflect/TypesTest.java | 4 +- .../common/util/concurrent/FuturesTest.java | 4 +- .../util/concurrent/JSR166TestCase.java | 11 +- .../com/google/common/base/Throwables.java | 4 +- .../google/common/collect/TreeRangeSet.java | 48 ++++---- .../src/com/google/common/hash/Hashing.java | 6 + .../common/hash/Murmur3_128HashFunction.java | 1 + .../common/hash/Murmur3_32HashFunction.java | 1 + .../src/com/google/common/io/Closeables.java | 10 ++ .../src/com/google/common/io/Flushables.java | 1 + .../AbstractPackageSanityTestsTest.java | 1 + .../common/testing/NullPointerTesterTest.java | 114 +++++++++--------- .../concurrent/ExecutionListBenchmark.java | 10 +- .../google/common/base/PredicatesTest.java | 8 +- .../com/google/common/base/SuppliersTest.java | 6 +- .../google/common/collect/OrderingTest.java | 14 +-- .../com/google/common/collect/QueuesTest.java | 24 ++-- .../google/common/collect/StreamsTest.java | 24 ++-- .../common/math/BigDecimalMathTest.java | 20 +-- .../common/math/BigIntegerMathTest.java | 20 +-- .../google/common/net/InetAddressesTest.java | 2 + .../AbstractInvocationHandlerTest.java | 4 - .../google/common/reflect/TypeTokenTest.java | 16 +-- .../com/google/common/reflect/TypesTest.java | 4 +- .../common/util/concurrent/FuturesTest.java | 4 +- .../util/concurrent/JSR166TestCase.java | 11 +- .../com/google/common/base/Throwables.java | 4 +- .../google/common/collect/TreeRangeSet.java | 48 ++++---- guava/src/com/google/common/hash/Hashing.java | 6 + .../common/hash/Murmur3_128HashFunction.java | 1 + .../common/hash/Murmur3_32HashFunction.java | 1 + .../src/com/google/common/io/Closeables.java | 10 ++ .../src/com/google/common/io/Flushables.java | 1 + 44 files changed, 315 insertions(+), 253 deletions(-) diff --git a/android/guava-testlib/test/com/google/common/testing/AbstractPackageSanityTestsTest.java b/android/guava-testlib/test/com/google/common/testing/AbstractPackageSanityTestsTest.java index 6ddcde40c359..9712d8aa0112 100644 --- a/android/guava-testlib/test/com/google/common/testing/AbstractPackageSanityTestsTest.java +++ b/android/guava-testlib/test/com/google/common/testing/AbstractPackageSanityTestsTest.java @@ -110,6 +110,7 @@ static class EmptyTestSuite {} static class Foo {} + @SuppressWarnings("IdentifierName") // We're testing that we ignore classes with underscores. static class Foo_Bar {} public static class PublicFoo {} diff --git a/android/guava-tests/benchmark/com/google/common/util/concurrent/ExecutionListBenchmark.java b/android/guava-tests/benchmark/com/google/common/util/concurrent/ExecutionListBenchmark.java index c7e1de2c3f35..227ad99be874 100644 --- a/android/guava-tests/benchmark/com/google/common/util/concurrent/ExecutionListBenchmark.java +++ b/android/guava-tests/benchmark/com/google/common/util/concurrent/ExecutionListBenchmark.java @@ -89,7 +89,7 @@ public Object getImpl() { @Override ExecutionListWrapper newExecutionList() { return new ExecutionListWrapper() { - final ExecutionListCAS list = new ExecutionListCAS(); + final ExecutionListUsingCompareAndSwap list = new ExecutionListUsingCompareAndSwap(); @Override public void add(Runnable runnable, Executor executor) { @@ -581,8 +581,8 @@ private static final class RunnableExecutorPair { // A version of the list that uses compare and swap to manage the stack without locks. @SuppressWarnings({"SunApi", "removal"}) // b/345822163 - private static final class ExecutionListCAS { - static final Logger log = Logger.getLogger(ExecutionListCAS.class.getName()); + private static final class ExecutionListUsingCompareAndSwap { + static final Logger log = Logger.getLogger(ExecutionListUsingCompareAndSwap.class.getName()); private static final Unsafe UNSAFE; private static final long HEAD_OFFSET; @@ -596,7 +596,9 @@ private static final class ExecutionListCAS { static { try { UNSAFE = getUnsafe(); - HEAD_OFFSET = UNSAFE.objectFieldOffset(ExecutionListCAS.class.getDeclaredField("head")); + HEAD_OFFSET = + UNSAFE.objectFieldOffset( + ExecutionListUsingCompareAndSwap.class.getDeclaredField("head")); } catch (Exception ex) { throw new Error(ex); } diff --git a/android/guava-tests/test/com/google/common/base/PredicatesTest.java b/android/guava-tests/test/com/google/common/base/PredicatesTest.java index 26fd6bb5909b..cafa435a1133 100644 --- a/android/guava-tests/test/com/google/common/base/PredicatesTest.java +++ b/android/guava-tests/test/com/google/common/base/PredicatesTest.java @@ -717,7 +717,7 @@ public void testIn_serialization() { } public void testIn_handlesNullPointerException() { - class CollectionThatThrowsNPE extends ArrayList { + class CollectionThatThrowsNullPointerException extends ArrayList { @J2ktIncompatible // Kotlin doesn't support companions for inner classes private static final long serialVersionUID = 1L; @@ -727,13 +727,13 @@ public boolean contains(@Nullable Object element) { return super.contains(element); } } - Collection nums = new CollectionThatThrowsNPE<>(); + Collection nums = new CollectionThatThrowsNullPointerException<>(); Predicate<@Nullable Integer> isFalse = Predicates.in(nums); assertFalse(isFalse.apply(null)); } public void testIn_handlesClassCastException() { - class CollectionThatThrowsCCE extends ArrayList { + class CollectionThatThrowsClassCastException extends ArrayList { @J2ktIncompatible // Kotlin doesn't support companions for inner classes private static final long serialVersionUID = 1L; @@ -742,7 +742,7 @@ public boolean contains(@Nullable Object element) { throw new ClassCastException(""); } } - Collection nums = new CollectionThatThrowsCCE<>(); + Collection nums = new CollectionThatThrowsClassCastException<>(); nums.add(3); Predicate isThree = Predicates.in(nums); assertFalse(isThree.apply(3)); diff --git a/android/guava-tests/test/com/google/common/base/SuppliersTest.java b/android/guava-tests/test/com/google/common/base/SuppliersTest.java index b894146330f9..10cd0b040e2a 100644 --- a/android/guava-tests/test/com/google/common/base/SuppliersTest.java +++ b/android/guava-tests/test/com/google/common/base/SuppliersTest.java @@ -107,11 +107,11 @@ private void memoizeTest(CountingSupplier countingSupplier) { } public void testMemoize_redudantly() { - memoize_redudantlyTest(new CountingSupplier()); - memoize_redudantlyTest(new SerializableCountingSupplier()); + memoizeRedudantlyTest(new CountingSupplier()); + memoizeRedudantlyTest(new SerializableCountingSupplier()); } - private void memoize_redudantlyTest(CountingSupplier countingSupplier) { + private void memoizeRedudantlyTest(CountingSupplier countingSupplier) { Supplier memoizedSupplier = Suppliers.memoize(countingSupplier); assertSame(memoizedSupplier, Suppliers.memoize(memoizedSupplier)); } diff --git a/android/guava-tests/test/com/google/common/collect/OrderingTest.java b/android/guava-tests/test/com/google/common/collect/OrderingTest.java index dfe3373a0b86..f2338011e98c 100644 --- a/android/guava-tests/test/com/google/common/collect/OrderingTest.java +++ b/android/guava-tests/test/com/google/common/collect/OrderingTest.java @@ -358,7 +358,7 @@ public void testReverseOfReverseSameAsForward() { } private enum StringLengthFunction implements Function { - StringLength; + STRING_LENGTH; @Override public Integer apply(String string) { @@ -370,35 +370,35 @@ public Integer apply(String string) { public void testOnResultOf_natural() { Comparator comparator = - Ordering.natural().onResultOf(StringLengthFunction.StringLength); + Ordering.natural().onResultOf(StringLengthFunction.STRING_LENGTH); assertTrue(comparator.compare("to", "be") == 0); assertTrue(comparator.compare("or", "not") < 0); assertTrue(comparator.compare("that", "to") > 0); new EqualsTester() .addEqualityGroup( - comparator, Ordering.natural().onResultOf(StringLengthFunction.StringLength)) + comparator, Ordering.natural().onResultOf(StringLengthFunction.STRING_LENGTH)) .addEqualityGroup(DECREASING_INTEGER) .testEquals(); reserializeAndAssert(comparator); - assertEquals("Ordering.natural().onResultOf(StringLength)", comparator.toString()); + assertEquals("Ordering.natural().onResultOf(STRING_LENGTH)", comparator.toString()); } public void testOnResultOf_chained() { Comparator comparator = - DECREASING_INTEGER.onResultOf(StringLengthFunction.StringLength); + DECREASING_INTEGER.onResultOf(StringLengthFunction.STRING_LENGTH); assertTrue(comparator.compare("to", "be") == 0); assertTrue(comparator.compare("not", "or") < 0); assertTrue(comparator.compare("to", "that") > 0); new EqualsTester() .addEqualityGroup( - comparator, DECREASING_INTEGER.onResultOf(StringLengthFunction.StringLength)) + comparator, DECREASING_INTEGER.onResultOf(StringLengthFunction.STRING_LENGTH)) .addEqualityGroup(DECREASING_INTEGER.onResultOf(Functions.constant(1))) .addEqualityGroup(Ordering.natural()) .testEquals(); reserializeAndAssert(comparator); - assertEquals("Ordering.natural().reverse().onResultOf(StringLength)", comparator.toString()); + assertEquals("Ordering.natural().reverse().onResultOf(STRING_LENGTH)", comparator.toString()); } public void testLexicographical() { diff --git a/android/guava-tests/test/com/google/common/collect/QueuesTest.java b/android/guava-tests/test/com/google/common/collect/QueuesTest.java index 53d7509dee99..277e9eceb1f3 100644 --- a/android/guava-tests/test/com/google/common/collect/QueuesTest.java +++ b/android/guava-tests/test/com/google/common/collect/QueuesTest.java @@ -125,11 +125,11 @@ private void testMultipleProducers(BlockingQueue q) throws InterruptedEx public void testDrainTimesOut() throws Exception { for (BlockingQueue q : blockingQueues()) { - testDrainTimesOut(q); + checkDrainTimesOut(q); } } - private void testDrainTimesOut(BlockingQueue q) throws Exception { + private void checkDrainTimesOut(BlockingQueue q) throws Exception { for (boolean interruptibly : new boolean[] {true, false}) { assertEquals(0, Queues.drain(q, ImmutableList.of(), 1, 10, MILLISECONDS)); @@ -157,11 +157,11 @@ private void testDrainTimesOut(BlockingQueue q) throws Exception { public void testZeroElements() throws Exception { for (BlockingQueue q : blockingQueues()) { - testZeroElements(q); + checkZeroElements(q); } } - private void testZeroElements(BlockingQueue q) throws InterruptedException { + private void checkZeroElements(BlockingQueue q) throws InterruptedException { for (boolean interruptibly : new boolean[] {true, false}) { // asking to drain zero elements assertEquals(0, drain(q, ImmutableList.of(), 0, 10, MILLISECONDS, interruptibly)); @@ -170,21 +170,21 @@ private void testZeroElements(BlockingQueue q) throws InterruptedExcepti public void testEmpty() throws Exception { for (BlockingQueue q : blockingQueues()) { - testEmpty(q); + checkEmpty(q); } } - private void testEmpty(BlockingQueue q) { + private void checkEmpty(BlockingQueue q) { assertDrained(q); } public void testNegativeMaxElements() throws Exception { for (BlockingQueue q : blockingQueues()) { - testNegativeMaxElements(q); + checkNegativeMaxElements(q); } } - private void testNegativeMaxElements(BlockingQueue q) throws InterruptedException { + private void checkNegativeMaxElements(BlockingQueue q) throws InterruptedException { @SuppressWarnings("unused") // https://errorprone.info/bugpattern/FutureReturnValueIgnored Future possiblyIgnoredError = threadPool.submit(new Producer(q, 1)); @@ -199,11 +199,11 @@ private void testNegativeMaxElements(BlockingQueue q) throws Interrupted public void testDrain_throws() throws Exception { for (BlockingQueue q : blockingQueues()) { - testDrain_throws(q); + checkDrainThrows(q); } } - private void testDrain_throws(BlockingQueue q) { + private void checkDrainThrows(BlockingQueue q) { @SuppressWarnings("unused") // https://errorprone.info/bugpattern/FutureReturnValueIgnored Future possiblyIgnoredError = threadPool.submit(new Interrupter(currentThread())); try { @@ -215,11 +215,11 @@ private void testDrain_throws(BlockingQueue q) { public void testDrainUninterruptibly_doesNotThrow() throws Exception { for (BlockingQueue q : blockingQueues()) { - testDrainUninterruptibly_doesNotThrow(q); + testDrainUninterruptiblyDoesNotThrow(q); } } - private void testDrainUninterruptibly_doesNotThrow(final BlockingQueue q) { + private void testDrainUninterruptiblyDoesNotThrow(final BlockingQueue q) { final Thread mainThread = currentThread(); @SuppressWarnings("unused") // https://errorprone.info/bugpattern/FutureReturnValueIgnored Future possiblyIgnoredError = diff --git a/android/guava-tests/test/com/google/common/math/BigDecimalMathTest.java b/android/guava-tests/test/com/google/common/math/BigDecimalMathTest.java index bb383a0d891d..ba78c5dba7cc 100644 --- a/android/guava-tests/test/com/google/common/math/BigDecimalMathTest.java +++ b/android/guava-tests/test/com/google/common/math/BigDecimalMathTest.java @@ -181,13 +181,15 @@ public void testRoundToDouble_twoToThe54PlusFour() { } public void testRoundToDouble_maxDouble() { - BigDecimal maxDoubleAsBD = new BigDecimal(Double.MAX_VALUE); - new RoundToDoubleTester(maxDoubleAsBD).setExpectation(Double.MAX_VALUE, values()).test(); + BigDecimal maxDoubleAsBigDecimal = new BigDecimal(Double.MAX_VALUE); + new RoundToDoubleTester(maxDoubleAsBigDecimal) + .setExpectation(Double.MAX_VALUE, values()) + .test(); } public void testRoundToDouble_maxDoublePlusOne() { - BigDecimal maxDoubleAsBD = new BigDecimal(Double.MAX_VALUE).add(BigDecimal.ONE); - new RoundToDoubleTester(maxDoubleAsBD) + BigDecimal maxDoubleAsBigDecimal = new BigDecimal(Double.MAX_VALUE).add(BigDecimal.ONE); + new RoundToDoubleTester(maxDoubleAsBigDecimal) .setExpectation(Double.MAX_VALUE, DOWN, FLOOR, HALF_EVEN, HALF_UP, HALF_DOWN) .setExpectation(Double.POSITIVE_INFINITY, UP, CEILING) .roundUnnecessaryShouldThrow() @@ -247,13 +249,15 @@ public void testRoundToDouble_negativeTwoToThe54MinusFour() { } public void testRoundToDouble_minDouble() { - BigDecimal minDoubleAsBD = new BigDecimal(-Double.MAX_VALUE); - new RoundToDoubleTester(minDoubleAsBD).setExpectation(-Double.MAX_VALUE, values()).test(); + BigDecimal minDoubleAsBigDecimal = new BigDecimal(-Double.MAX_VALUE); + new RoundToDoubleTester(minDoubleAsBigDecimal) + .setExpectation(-Double.MAX_VALUE, values()) + .test(); } public void testRoundToDouble_minDoubleMinusOne() { - BigDecimal minDoubleAsBD = new BigDecimal(-Double.MAX_VALUE).subtract(BigDecimal.ONE); - new RoundToDoubleTester(minDoubleAsBD) + BigDecimal minDoubleAsBigDecimal = new BigDecimal(-Double.MAX_VALUE).subtract(BigDecimal.ONE); + new RoundToDoubleTester(minDoubleAsBigDecimal) .setExpectation(-Double.MAX_VALUE, DOWN, CEILING, HALF_EVEN, HALF_UP, HALF_DOWN) .setExpectation(Double.NEGATIVE_INFINITY, UP, FLOOR) .roundUnnecessaryShouldThrow() diff --git a/android/guava-tests/test/com/google/common/math/BigIntegerMathTest.java b/android/guava-tests/test/com/google/common/math/BigIntegerMathTest.java index e60cf683dfbc..f710ecdaa683 100644 --- a/android/guava-tests/test/com/google/common/math/BigIntegerMathTest.java +++ b/android/guava-tests/test/com/google/common/math/BigIntegerMathTest.java @@ -621,16 +621,18 @@ public void testRoundToDouble_twoToThe54PlusFour() { @J2ktIncompatible @GwtIncompatible public void testRoundToDouble_maxDouble() { - BigInteger maxDoubleAsBI = DoubleMath.roundToBigInteger(Double.MAX_VALUE, UNNECESSARY); - new RoundToDoubleTester(maxDoubleAsBI).setExpectation(Double.MAX_VALUE, values()).test(); + BigInteger maxDoubleAsBigInteger = DoubleMath.roundToBigInteger(Double.MAX_VALUE, UNNECESSARY); + new RoundToDoubleTester(maxDoubleAsBigInteger) + .setExpectation(Double.MAX_VALUE, values()) + .test(); } @J2ktIncompatible @GwtIncompatible public void testRoundToDouble_maxDoublePlusOne() { - BigInteger maxDoubleAsBI = + BigInteger maxDoubleAsBigInteger = DoubleMath.roundToBigInteger(Double.MAX_VALUE, UNNECESSARY).add(BigInteger.ONE); - new RoundToDoubleTester(maxDoubleAsBI) + new RoundToDoubleTester(maxDoubleAsBigInteger) .setExpectation(Double.MAX_VALUE, DOWN, FLOOR, HALF_EVEN, HALF_UP, HALF_DOWN) .setExpectation(Double.POSITIVE_INFINITY, UP, CEILING) .roundUnnecessaryShouldThrow() @@ -706,16 +708,18 @@ public void testRoundToDouble_negativeTwoToThe54MinusFour() { @J2ktIncompatible @GwtIncompatible public void testRoundToDouble_minDouble() { - BigInteger minDoubleAsBI = DoubleMath.roundToBigInteger(-Double.MAX_VALUE, UNNECESSARY); - new RoundToDoubleTester(minDoubleAsBI).setExpectation(-Double.MAX_VALUE, values()).test(); + BigInteger minDoubleAsBigInteger = DoubleMath.roundToBigInteger(-Double.MAX_VALUE, UNNECESSARY); + new RoundToDoubleTester(minDoubleAsBigInteger) + .setExpectation(-Double.MAX_VALUE, values()) + .test(); } @J2ktIncompatible @GwtIncompatible public void testRoundToDouble_minDoubleMinusOne() { - BigInteger minDoubleAsBI = + BigInteger minDoubleAsBigInteger = DoubleMath.roundToBigInteger(-Double.MAX_VALUE, UNNECESSARY).subtract(BigInteger.ONE); - new RoundToDoubleTester(minDoubleAsBI) + new RoundToDoubleTester(minDoubleAsBigInteger) .setExpectation(-Double.MAX_VALUE, DOWN, CEILING, HALF_EVEN, HALF_UP, HALF_DOWN) .setExpectation(Double.NEGATIVE_INFINITY, UP, FLOOR) .roundUnnecessaryShouldThrow() diff --git a/android/guava-tests/test/com/google/common/net/InetAddressesTest.java b/android/guava-tests/test/com/google/common/net/InetAddressesTest.java index 3f442deaab98..03425f0abebf 100644 --- a/android/guava-tests/test/com/google/common/net/InetAddressesTest.java +++ b/android/guava-tests/test/com/google/common/net/InetAddressesTest.java @@ -735,6 +735,7 @@ public void testIsMaximum() throws UnknownHostException { assertTrue(InetAddresses.isMaximum(address)); } + @SuppressWarnings("IdentifierName") // the best we could do for adjacent digit blocks public void testIncrementIPv4() throws UnknownHostException { InetAddress address_66_0 = InetAddress.getByName("172.24.66.0"); InetAddress address_66_255 = InetAddress.getByName("172.24.66.255"); @@ -753,6 +754,7 @@ public void testIncrementIPv4() throws UnknownHostException { assertThrows(IllegalArgumentException.class, () -> InetAddresses.increment(address_ffffff)); } + @SuppressWarnings("IdentifierName") // the best we could do for adjacent digit blocks public void testIncrementIPv6() throws UnknownHostException { InetAddress addressV6_66_0 = InetAddress.getByName("2001:db8::6600"); InetAddress addressV6_66_ff = InetAddress.getByName("2001:db8::66ff"); diff --git a/android/guava-tests/test/com/google/common/reflect/AbstractInvocationHandlerTest.java b/android/guava-tests/test/com/google/common/reflect/AbstractInvocationHandlerTest.java index 7a02d07db059..5684dda5c6e8 100644 --- a/android/guava-tests/test/com/google/common/reflect/AbstractInvocationHandlerTest.java +++ b/android/guava-tests/test/com/google/common/reflect/AbstractInvocationHandlerTest.java @@ -55,10 +55,6 @@ interface A {} interface B {} public void testEquals() { - class AB implements A, B {} - class BA implements B, A {} - AB ab = new AB(); - BA ba = new BA(); new EqualsTester() .addEqualityGroup(newDelegatingList(LIST1)) // Actually, this violates List#equals contract. diff --git a/android/guava-tests/test/com/google/common/reflect/TypeTokenTest.java b/android/guava-tests/test/com/google/common/reflect/TypeTokenTest.java index 4acb5a1086ed..cfaf9f6ffdd1 100644 --- a/android/guava-tests/test/com/google/common/reflect/TypeTokenTest.java +++ b/android/guava-tests/test/com/google/common/reflect/TypeTokenTest.java @@ -584,9 +584,9 @@ private abstract static class Third extends Second {} private abstract static class Fourth extends Third {} - private static class ConcreteIS extends Fourth {} + private static class ConcreteIntegerString extends Fourth {} - private static class ConcreteSI extends Fourth {} + private static class ConcreteStringInteger extends Fourth {} public void testAssignableClassToClass() { @SuppressWarnings("rawtypes") // To test TypeToken @@ -759,8 +759,8 @@ public void testAssignableClassToType() { assertFalse(tokenL.isSupertypeOf(List.class)); TypeToken> tokenF = new TypeToken>() {}; - assertTrue(tokenF.isSupertypeOf(ConcreteIS.class)); - assertFalse(tokenF.isSupertypeOf(ConcreteSI.class)); + assertTrue(tokenF.isSupertypeOf(ConcreteIntegerString.class)); + assertFalse(tokenF.isSupertypeOf(ConcreteStringInteger.class)); } public void testAssignableClassToArrayType() { @@ -775,8 +775,8 @@ public void testAssignableParameterizedTypeToType() { assertFalse(tokenL.isSupertypeOf(IntegerList.class.getGenericInterfaces()[0])); TypeToken> tokenF = new TypeToken>() {}; - assertTrue(tokenF.isSupertypeOf(ConcreteIS.class.getGenericSuperclass())); - assertFalse(tokenF.isSupertypeOf(ConcreteSI.class.getGenericSuperclass())); + assertTrue(tokenF.isSupertypeOf(ConcreteIntegerString.class.getGenericSuperclass())); + assertFalse(tokenF.isSupertypeOf(ConcreteStringInteger.class.getGenericSuperclass())); } public void testGenericArrayTypeToArrayType() { @@ -798,8 +798,8 @@ public void testAssignableTokenToType() { assertFalse(tokenF.isSupertypeOf(new TypeToken>() {})); assertTrue(tokenF.isSupertypeOf(new TypeToken>() {})); assertFalse(tokenF.isSupertypeOf(new TypeToken>() {})); - assertTrue(tokenF.isSupertypeOf(new TypeToken() {})); - assertFalse(tokenF.isSupertypeOf(new TypeToken() {})); + assertTrue(tokenF.isSupertypeOf(new TypeToken() {})); + assertFalse(tokenF.isSupertypeOf(new TypeToken() {})); } public void testAssignableWithWildcards() { diff --git a/android/guava-tests/test/com/google/common/reflect/TypesTest.java b/android/guava-tests/test/com/google/common/reflect/TypesTest.java index 42ac44f5bbda..785b3a65872a 100644 --- a/android/guava-tests/test/com/google/common/reflect/TypesTest.java +++ b/android/guava-tests/test/com/google/common/reflect/TypesTest.java @@ -84,10 +84,10 @@ class LocalClass {} } public void testNewParameterizedType_staticLocalClass() { - doTestNewParameterizedType_staticLocalClass(); + doTestNewParameterizedTypeStaticLocalClass(); } - private static void doTestNewParameterizedType_staticLocalClass() { + private static void doTestNewParameterizedTypeStaticLocalClass() { class LocalClass {} Type jvmType = new LocalClass() {}.getClass().getGenericSuperclass(); Type ourType = Types.newParameterizedType(LocalClass.class, String.class); diff --git a/android/guava-tests/test/com/google/common/util/concurrent/FuturesTest.java b/android/guava-tests/test/com/google/common/util/concurrent/FuturesTest.java index aa900d6a0802..683abc29c47e 100644 --- a/android/guava-tests/test/com/google/common/util/concurrent/FuturesTest.java +++ b/android/guava-tests/test/com/google/common/util/concurrent/FuturesTest.java @@ -3337,7 +3337,7 @@ public void testSuccessfulAsList_resultCancelledRacingInputDone() throws Excepti Logger exceptionLogger = Logger.getLogger(AbstractFuture.class.getName()); exceptionLogger.addHandler(listenerLoggerHandler); try { - doTestSuccessfulAsList_resultCancelledRacingInputDone(); + doTestSuccessfulAsListResultCancelledRacingInputDone(); assertWithMessage("Nothing should be logged") .that(listenerLoggerHandler.getStoredLogRecords()) @@ -3347,7 +3347,7 @@ public void testSuccessfulAsList_resultCancelledRacingInputDone() throws Excepti } } - private static void doTestSuccessfulAsList_resultCancelledRacingInputDone() throws Exception { + private static void doTestSuccessfulAsListResultCancelledRacingInputDone() throws Exception { // Simple (combined.cancel -> input.cancel -> setOneValue): successfulAsList(ImmutableList.of(SettableFuture.create())).cancel(true); diff --git a/android/guava-tests/test/com/google/common/util/concurrent/JSR166TestCase.java b/android/guava-tests/test/com/google/common/util/concurrent/JSR166TestCase.java index d95939b56c0f..341cfa83b099 100644 --- a/android/guava-tests/test/com/google/common/util/concurrent/JSR166TestCase.java +++ b/android/guava-tests/test/com/google/common/util/concurrent/JSR166TestCase.java @@ -100,12 +100,15 @@ * tests. * */ -// We call threadUnexpectedException, which does the right thing for errors. -@SuppressWarnings("AssertionFailureIgnored") +@SuppressWarnings({ + // We call threadUnexpectedException, which does the right thing for errors. + "AssertionFailureIgnored", + // We're following the upstream naming to reduce diffs. + "IdentifierName", + "ConstantCaseForConstants", +}) @NullUnmarked abstract class JSR166TestCase extends TestCase { - private static final boolean useSecurityManager = Boolean.getBoolean("jsr166.useSecurityManager"); - protected static final boolean expensiveTests = Boolean.getBoolean("jsr166.expensiveTests"); /** diff --git a/android/guava/src/com/google/common/base/Throwables.java b/android/guava/src/com/google/common/base/Throwables.java index 1ac398a8f8c7..319828d8990b 100644 --- a/android/guava/src/com/google/common/base/Throwables.java +++ b/android/guava/src/com/google/common/base/Throwables.java @@ -454,7 +454,7 @@ private static Object invokeAccessibleNonThrowingMethod( /** Access to some fancy internal JVM internals. */ @J2ktIncompatible @GwtIncompatible // java.lang.reflect - private static final @Nullable Object jla = getJLA(); + private static final @Nullable Object jla = getJla(); /** * The "getStackTraceElementMethod" method, only available on some JDKs so we use reflection to @@ -479,7 +479,7 @@ private static Object invokeAccessibleNonThrowingMethod( @SuppressWarnings("removal") // b/318391980 @J2ktIncompatible @GwtIncompatible // java.lang.reflect - private static @Nullable Object getJLA() { + private static @Nullable Object getJla() { try { /* * We load sun.misc.* classes using reflection since Android doesn't support these classes and diff --git a/android/guava/src/com/google/common/collect/TreeRangeSet.java b/android/guava/src/com/google/common/collect/TreeRangeSet.java index 2ee5b08ffa67..11f585c35ef3 100644 --- a/android/guava/src/com/google/common/collect/TreeRangeSet.java +++ b/android/guava/src/com/google/common/collect/TreeRangeSet.java @@ -187,31 +187,31 @@ public void add(Range rangeToAdd) { Cut lbToAdd = rangeToAdd.lowerBound; Cut ubToAdd = rangeToAdd.upperBound; - Entry, Range> entryBelowLB = rangesByLowerBound.lowerEntry(lbToAdd); - if (entryBelowLB != null) { + Entry, Range> entryBelowLb = rangesByLowerBound.lowerEntry(lbToAdd); + if (entryBelowLb != null) { // { < - Range rangeBelowLB = entryBelowLB.getValue(); - if (rangeBelowLB.upperBound.compareTo(lbToAdd) >= 0) { + Range rangeBelowLb = entryBelowLb.getValue(); + if (rangeBelowLb.upperBound.compareTo(lbToAdd) >= 0) { // { < }, and we will need to coalesce - if (rangeBelowLB.upperBound.compareTo(ubToAdd) >= 0) { + if (rangeBelowLb.upperBound.compareTo(ubToAdd) >= 0) { // { < > } - ubToAdd = rangeBelowLB.upperBound; + ubToAdd = rangeBelowLb.upperBound; /* * TODO(cpovirk): can we just "return;" here? Or, can we remove this if() entirely? If * not, add tests to demonstrate the problem with each approach */ } - lbToAdd = rangeBelowLB.lowerBound; + lbToAdd = rangeBelowLb.lowerBound; } } - Entry, Range> entryBelowUB = rangesByLowerBound.floorEntry(ubToAdd); - if (entryBelowUB != null) { + Entry, Range> entryBelowUb = rangesByLowerBound.floorEntry(ubToAdd); + if (entryBelowUb != null) { // { > - Range rangeBelowUB = entryBelowUB.getValue(); - if (rangeBelowUB.upperBound.compareTo(ubToAdd) >= 0) { + Range rangeBelowUb = entryBelowUb.getValue(); + if (rangeBelowUb.upperBound.compareTo(ubToAdd) >= 0) { // { > }, and we need to coalesce - ubToAdd = rangeBelowUB.upperBound; + ubToAdd = rangeBelowUb.upperBound; } } @@ -232,32 +232,32 @@ public void remove(Range rangeToRemove) { // We will use { } to illustrate ranges currently in the range set, and < > // to illustrate rangeToRemove. - Entry, Range> entryBelowLB = rangesByLowerBound.lowerEntry(rangeToRemove.lowerBound); - if (entryBelowLB != null) { + Entry, Range> entryBelowLb = rangesByLowerBound.lowerEntry(rangeToRemove.lowerBound); + if (entryBelowLb != null) { // { < - Range rangeBelowLB = entryBelowLB.getValue(); - if (rangeBelowLB.upperBound.compareTo(rangeToRemove.lowerBound) >= 0) { + Range rangeBelowLb = entryBelowLb.getValue(); + if (rangeBelowLb.upperBound.compareTo(rangeToRemove.lowerBound) >= 0) { // { < }, and we will need to subdivide if (rangeToRemove.hasUpperBound() - && rangeBelowLB.upperBound.compareTo(rangeToRemove.upperBound) >= 0) { + && rangeBelowLb.upperBound.compareTo(rangeToRemove.upperBound) >= 0) { // { < > } replaceRangeWithSameLowerBound( - Range.create(rangeToRemove.upperBound, rangeBelowLB.upperBound)); + Range.create(rangeToRemove.upperBound, rangeBelowLb.upperBound)); } replaceRangeWithSameLowerBound( - Range.create(rangeBelowLB.lowerBound, rangeToRemove.lowerBound)); + Range.create(rangeBelowLb.lowerBound, rangeToRemove.lowerBound)); } } - Entry, Range> entryBelowUB = rangesByLowerBound.floorEntry(rangeToRemove.upperBound); - if (entryBelowUB != null) { + Entry, Range> entryBelowUb = rangesByLowerBound.floorEntry(rangeToRemove.upperBound); + if (entryBelowUb != null) { // { > - Range rangeBelowUB = entryBelowUB.getValue(); + Range rangeBelowUb = entryBelowUb.getValue(); if (rangeToRemove.hasUpperBound() - && rangeBelowUB.upperBound.compareTo(rangeToRemove.upperBound) >= 0) { + && rangeBelowUb.upperBound.compareTo(rangeToRemove.upperBound) >= 0) { // { > } replaceRangeWithSameLowerBound( - Range.create(rangeToRemove.upperBound, rangeBelowUB.upperBound)); + Range.create(rangeToRemove.upperBound, rangeBelowUb.upperBound)); } } diff --git a/android/guava/src/com/google/common/hash/Hashing.java b/android/guava/src/com/google/common/hash/Hashing.java index af5afcb41e1b..84396d227071 100644 --- a/android/guava/src/com/google/common/hash/Hashing.java +++ b/android/guava/src/com/google/common/hash/Hashing.java @@ -104,6 +104,7 @@ public static HashFunction goodFastHash(int minimumBits) { * #murmur3_32_fixed(int)} instead. */ @Deprecated + @SuppressWarnings("IdentifierName") // the best we could do for adjacent digit blocks public static HashFunction murmur3_32(int seed) { return new Murmur3_32HashFunction(seed, /* supplementaryPlaneFix= */ false); } @@ -122,6 +123,7 @@ public static HashFunction murmur3_32(int seed) { * #murmur3_32_fixed()} instead. */ @Deprecated + @SuppressWarnings("IdentifierName") // the best we could do for adjacent digit blocks public static HashFunction murmur3_32() { return Murmur3_32HashFunction.MURMUR3_32; } @@ -138,6 +140,7 @@ public static HashFunction murmur3_32() { * * @since 31.0 */ + @SuppressWarnings("IdentifierName") // the best we could do for adjacent digit blocks public static HashFunction murmur3_32_fixed(int seed) { return new Murmur3_32HashFunction(seed, /* supplementaryPlaneFix= */ true); } @@ -154,6 +157,7 @@ public static HashFunction murmur3_32_fixed(int seed) { * * @since 31.0 */ + @SuppressWarnings("IdentifierName") // the best we could do for adjacent digit blocks public static HashFunction murmur3_32_fixed() { return Murmur3_32HashFunction.MURMUR3_32_FIXED; } @@ -165,6 +169,7 @@ public static HashFunction murmur3_32_fixed() { * *

The exact C++ equivalent is the MurmurHash3_x64_128 function (Murmur3F). */ + @SuppressWarnings("IdentifierName") // the best we could do for adjacent digit blocks public static HashFunction murmur3_128(int seed) { return new Murmur3_128HashFunction(seed); } @@ -176,6 +181,7 @@ public static HashFunction murmur3_128(int seed) { * *

The exact C++ equivalent is the MurmurHash3_x64_128 function (Murmur3F). */ + @SuppressWarnings("IdentifierName") // the best we could do for adjacent digit blocks public static HashFunction murmur3_128() { return Murmur3_128HashFunction.MURMUR3_128; } diff --git a/android/guava/src/com/google/common/hash/Murmur3_128HashFunction.java b/android/guava/src/com/google/common/hash/Murmur3_128HashFunction.java index c340f0297661..3ce78e8614c6 100644 --- a/android/guava/src/com/google/common/hash/Murmur3_128HashFunction.java +++ b/android/guava/src/com/google/common/hash/Murmur3_128HashFunction.java @@ -41,6 +41,7 @@ * @author Dimitris Andreou */ @Immutable +@SuppressWarnings("IdentifierName") // the best we could do for adjacent digit blocks final class Murmur3_128HashFunction extends AbstractHashFunction implements Serializable { static final HashFunction MURMUR3_128 = new Murmur3_128HashFunction(0); diff --git a/android/guava/src/com/google/common/hash/Murmur3_32HashFunction.java b/android/guava/src/com/google/common/hash/Murmur3_32HashFunction.java index a40c2fbeb00e..4ed25af7291e 100644 --- a/android/guava/src/com/google/common/hash/Murmur3_32HashFunction.java +++ b/android/guava/src/com/google/common/hash/Murmur3_32HashFunction.java @@ -51,6 +51,7 @@ * @author Kurt Alfred Kluever */ @Immutable +@SuppressWarnings("IdentifierName") // the best we could do for adjacent digit blocks final class Murmur3_32HashFunction extends AbstractHashFunction implements Serializable { static final HashFunction MURMUR3_32 = new Murmur3_32HashFunction(0, /* supplementaryPlaneFix= */ false); diff --git a/android/guava/src/com/google/common/io/Closeables.java b/android/guava/src/com/google/common/io/Closeables.java index 3a225edfbd3a..e9c580af36a6 100644 --- a/android/guava/src/com/google/common/io/Closeables.java +++ b/android/guava/src/com/google/common/io/Closeables.java @@ -69,6 +69,16 @@ private Closeables() {} * @throws IOException if {@code swallowIOException} is false and {@code close} throws an {@code * IOException}. */ + /* + * The proper capitalization would be "swallowIoException." However: + * + * - It might be preferable to be consistent with the JDK precedent (which they stuck with even + * for "UncheckedIOException"). + * + * - If we change the name, some of our callers break because our Android Lint ParameterName check + * doesn't make the exception for com.google.common that internal Error Prone does: b/386402967. + */ + @SuppressWarnings("IdentifierName") public static void close(@Nullable Closeable closeable, boolean swallowIOException) throws IOException { if (closeable == null) { diff --git a/android/guava/src/com/google/common/io/Flushables.java b/android/guava/src/com/google/common/io/Flushables.java index 412a09bbfe82..7e5e11275c0a 100644 --- a/android/guava/src/com/google/common/io/Flushables.java +++ b/android/guava/src/com/google/common/io/Flushables.java @@ -48,6 +48,7 @@ private Flushables() {} * an {@code IOException}. * @see Closeables#close */ + @SuppressWarnings("IdentifierName") // See Closeables.close public static void flush(Flushable flushable, boolean swallowIOException) throws IOException { try { flushable.flush(); diff --git a/guava-testlib/test/com/google/common/testing/AbstractPackageSanityTestsTest.java b/guava-testlib/test/com/google/common/testing/AbstractPackageSanityTestsTest.java index 6ddcde40c359..9712d8aa0112 100644 --- a/guava-testlib/test/com/google/common/testing/AbstractPackageSanityTestsTest.java +++ b/guava-testlib/test/com/google/common/testing/AbstractPackageSanityTestsTest.java @@ -110,6 +110,7 @@ static class EmptyTestSuite {} static class Foo {} + @SuppressWarnings("IdentifierName") // We're testing that we ignore classes with underscores. static class Foo_Bar {} public static class PublicFoo {} diff --git a/guava-testlib/test/com/google/common/testing/NullPointerTesterTest.java b/guava-testlib/test/com/google/common/testing/NullPointerTesterTest.java index d4549004c609..fb537b1dbc00 100644 --- a/guava-testlib/test/com/google/common/testing/NullPointerTesterTest.java +++ b/guava-testlib/test/com/google/common/testing/NullPointerTesterTest.java @@ -88,32 +88,32 @@ public static void staticOneArgShouldThrowNpeButDoesnt(String s) { // should catch as failure } - public static void staticOneArgCheckForNullCorrectlyDoesNotThrowNPE(@CheckForNull String s) { + public static void staticOneArgCheckForNullCorrectlyDoesNotThrowNpe(@CheckForNull String s) { // null? no problem } - public static void staticOneArgJsr305NullableCorrectlyDoesNotThrowNPE( + public static void staticOneArgJsr305NullableCorrectlyDoesNotThrowNpe( @javax.annotation.Nullable String s) { // null? no problem } - public static void staticOneArgNullableCorrectlyDoesNotThrowNPE(@Nullable String s) { + public static void staticOneArgNullableCorrectlyDoesNotThrowNpe(@Nullable String s) { // null? no problem } - public static void staticOneArgCheckForNullCorrectlyThrowsOtherThanNPE(@CheckForNull String s) { + public static void staticOneArgCheckForNullCorrectlyThrowsOtherThanNpe(@CheckForNull String s) { throw new FooException(); // ok, as long as it's not NullPointerException } - public static void staticOneArgNullableCorrectlyThrowsOtherThanNPE(@Nullable String s) { + public static void staticOneArgNullableCorrectlyThrowsOtherThanNpe(@Nullable String s) { throw new FooException(); // ok, as long as it's not NullPointerException } - public static void staticOneArgCheckForNullThrowsNPE(@CheckForNull String s) { + public static void staticOneArgCheckForNullThrowsNpe(@CheckForNull String s) { checkNotNull(s); // doesn't check if you said you'd accept null, but you don't } - public static void staticOneArgNullableThrowsNPE(@Nullable String s) { + public static void staticOneArgNullableThrowsNpe(@Nullable String s) { checkNotNull(s); // doesn't check if you said you'd accept null, but you don't } @@ -129,27 +129,27 @@ public void oneArgShouldThrowNpeButDoesnt(String s) { // should catch as failure } - public void oneArgCheckForNullCorrectlyDoesNotThrowNPE(@CheckForNull String s) { + public void oneArgCheckForNullCorrectlyDoesNotThrowNpe(@CheckForNull String s) { // null? no problem } - public void oneArgNullableCorrectlyDoesNotThrowNPE(@Nullable String s) { + public void oneArgNullableCorrectlyDoesNotThrowNpe(@Nullable String s) { // null? no problem } - public void oneArgCheckForNullCorrectlyThrowsOtherThanNPE(@CheckForNull String s) { + public void oneArgCheckForNullCorrectlyThrowsOtherThanNpe(@CheckForNull String s) { throw new FooException(); // ok, as long as it's not NullPointerException } - public void oneArgNullableCorrectlyThrowsOtherThanNPE(@Nullable String s) { + public void oneArgNullableCorrectlyThrowsOtherThanNpe(@Nullable String s) { throw new FooException(); // ok, as long as it's not NullPointerException } - public void oneArgCheckForNullThrowsNPE(@CheckForNull String s) { + public void oneArgCheckForNullThrowsNpe(@CheckForNull String s) { checkNotNull(s); // doesn't check if you said you'd accept null, but you don't } - public void oneArgNullableThrowsNPE(@Nullable String s) { + public void oneArgNullableThrowsNpe(@Nullable String s) { checkNotNull(s); // doesn't check if you said you'd accept null, but you don't } } @@ -157,23 +157,23 @@ public void oneArgNullableThrowsNPE(@Nullable String s) { private static final ImmutableSet STATIC_ONE_ARG_METHODS_SHOULD_PASS = ImmutableSet.of( "staticOneArgCorrectlyThrowsNpe", - "staticOneArgCheckForNullCorrectlyDoesNotThrowNPE", - "staticOneArgCheckForNullCorrectlyThrowsOtherThanNPE", - "staticOneArgCheckForNullThrowsNPE", - "staticOneArgNullableCorrectlyDoesNotThrowNPE", - "staticOneArgNullableCorrectlyThrowsOtherThanNPE", - "staticOneArgNullableThrowsNPE"); + "staticOneArgCheckForNullCorrectlyDoesNotThrowNpe", + "staticOneArgCheckForNullCorrectlyThrowsOtherThanNpe", + "staticOneArgCheckForNullThrowsNpe", + "staticOneArgNullableCorrectlyDoesNotThrowNpe", + "staticOneArgNullableCorrectlyThrowsOtherThanNpe", + "staticOneArgNullableThrowsNpe"); private static final ImmutableSet STATIC_ONE_ARG_METHODS_SHOULD_FAIL = ImmutableSet.of("staticOneArgThrowsOtherThanNpe", "staticOneArgShouldThrowNpeButDoesnt"); private static final ImmutableSet NONSTATIC_ONE_ARG_METHODS_SHOULD_PASS = ImmutableSet.of( "oneArgCorrectlyThrowsNpe", - "oneArgCheckForNullCorrectlyDoesNotThrowNPE", - "oneArgCheckForNullCorrectlyThrowsOtherThanNPE", - "oneArgCheckForNullThrowsNPE", - "oneArgNullableCorrectlyDoesNotThrowNPE", - "oneArgNullableCorrectlyThrowsOtherThanNPE", - "oneArgNullableThrowsNPE"); + "oneArgCheckForNullCorrectlyDoesNotThrowNpe", + "oneArgCheckForNullCorrectlyThrowsOtherThanNpe", + "oneArgCheckForNullThrowsNpe", + "oneArgNullableCorrectlyDoesNotThrowNpe", + "oneArgNullableCorrectlyThrowsOtherThanNpe", + "oneArgNullableThrowsNpe"); private static final ImmutableSet NONSTATIC_ONE_ARG_METHODS_SHOULD_FAIL = ImmutableSet.of("oneArgThrowsOtherThanNpe", "oneArgShouldThrowNpeButDoesnt"); @@ -581,21 +581,21 @@ public void testGoodClass() { shouldPass(new PassObject()); } - private static class FailOneArgDoesntThrowNPE extends PassObject { + private static class FailOneArgDoesntThrowNpe extends PassObject { @Override public void oneArg(String s) { - // Fail: missing NPE for s + // Fail: missing NPE for s } } public void testFailOneArgDoesntThrowNpe() { - shouldFail(new FailOneArgDoesntThrowNPE()); + shouldFail(new FailOneArgDoesntThrowNpe()); } private static class FailOneArgThrowsWrongType extends PassObject { @Override public void oneArg(String s) { - doThrow(s); // Fail: throwing non-NPE exception for null s + doThrow(s); // Fail: throwing non-NPE exception for null s } } @@ -603,18 +603,18 @@ public void testFailOneArgThrowsWrongType() { shouldFail(new FailOneArgThrowsWrongType()); } - private static class PassOneNullableArgThrowsNPE extends PassObject { + private static class PassOneNullableArgThrowsNpe extends PassObject { @Override public void oneNullableArg(@Nullable String s) { checkNotNull(s); // ok to throw NPE } } - public void testPassOneNullableArgThrowsNPE() { - shouldPass(new PassOneNullableArgThrowsNPE()); + public void testPassOneNullableArgThrowsNpe() { + shouldPass(new PassOneNullableArgThrowsNpe()); } - private static class FailTwoArgsFirstArgDoesntThrowNPE extends PassObject { + private static class FailTwoArgsFirstArgDoesntThrowNpe extends PassObject { @Override public void twoArg(String s, Integer i) { // Fail: missing NPE for s @@ -622,14 +622,14 @@ public void twoArg(String s, Integer i) { } } - public void testFailTwoArgsFirstArgDoesntThrowNPE() { - shouldFail(new FailTwoArgsFirstArgDoesntThrowNPE()); + public void testFailTwoArgsFirstArgDoesntThrowNpe() { + shouldFail(new FailTwoArgsFirstArgDoesntThrowNpe()); } private static class FailTwoArgsFirstArgThrowsWrongType extends PassObject { @Override public void twoArg(String s, Integer i) { - doThrow(s); // Fail: throwing non-NPE exception for null s + doThrow(s); // Fail: throwing non-NPE exception for null s i.intValue(); } } @@ -638,7 +638,7 @@ public void testFailTwoArgsFirstArgThrowsWrongType() { shouldFail(new FailTwoArgsFirstArgThrowsWrongType()); } - private static class FailTwoArgsSecondArgDoesntThrowNPE extends PassObject { + private static class FailTwoArgsSecondArgDoesntThrowNpe extends PassObject { @Override public void twoArg(String s, Integer i) { checkNotNull(s); @@ -646,15 +646,15 @@ public void twoArg(String s, Integer i) { } } - public void testFailTwoArgsSecondArgDoesntThrowNPE() { - shouldFail(new FailTwoArgsSecondArgDoesntThrowNPE()); + public void testFailTwoArgsSecondArgDoesntThrowNpe() { + shouldFail(new FailTwoArgsSecondArgDoesntThrowNpe()); } private static class FailTwoArgsSecondArgThrowsWrongType extends PassObject { @Override public void twoArg(String s, Integer i) { checkNotNull(s); - doThrow(i); // Fail: throwing non-NPE exception for null i + doThrow(i); // Fail: throwing non-NPE exception for null i } } @@ -662,21 +662,21 @@ public void testFailTwoArgsSecondArgThrowsWrongType() { shouldFail(new FailTwoArgsSecondArgThrowsWrongType()); } - private static class FailTwoMixedArgsFirstArgDoesntThrowNPE extends PassObject { + private static class FailTwoMixedArgsFirstArgDoesntThrowNpe extends PassObject { @Override public void twoMixedArgs(String s, @Nullable Integer i) { // Fail: missing NPE for s } } - public void testFailTwoMixedArgsFirstArgDoesntThrowNPE() { - shouldFail(new FailTwoMixedArgsFirstArgDoesntThrowNPE()); + public void testFailTwoMixedArgsFirstArgDoesntThrowNpe() { + shouldFail(new FailTwoMixedArgsFirstArgDoesntThrowNpe()); } private static class FailTwoMixedArgsFirstArgThrowsWrongType extends PassObject { @Override public void twoMixedArgs(String s, @Nullable Integer i) { - doThrow(s); // Fail: throwing non-NPE exception for null s + doThrow(s); // Fail: throwing non-NPE exception for null s } } @@ -684,7 +684,7 @@ public void testFailTwoMixedArgsFirstArgThrowsWrongType() { shouldFail(new FailTwoMixedArgsFirstArgThrowsWrongType()); } - private static class PassTwoMixedArgsNullableArgThrowsNPE extends PassObject { + private static class PassTwoMixedArgsNullableArgThrowsNpe extends PassObject { @Override public void twoMixedArgs(String s, @Nullable Integer i) { checkNotNull(s); @@ -692,8 +692,8 @@ public void twoMixedArgs(String s, @Nullable Integer i) { } } - public void testPassTwoMixedArgsNullableArgThrowsNPE() { - shouldPass(new PassTwoMixedArgsNullableArgThrowsNPE()); + public void testPassTwoMixedArgsNullableArgThrowsNpe() { + shouldPass(new PassTwoMixedArgsNullableArgThrowsNpe()); } private static class PassTwoMixedArgSecondNullableArgThrowsOther extends PassObject { @@ -708,21 +708,21 @@ public void testPassTwoMixedArgSecondNullableArgThrowsOther() { shouldPass(new PassTwoMixedArgSecondNullableArgThrowsOther()); } - private static class FailTwoMixedArgsSecondArgDoesntThrowNPE extends PassObject { + private static class FailTwoMixedArgsSecondArgDoesntThrowNpe extends PassObject { @Override public void twoMixedArgs(@Nullable Integer i, String s) { // Fail: missing NPE for null s } } - public void testFailTwoMixedArgsSecondArgDoesntThrowNPE() { - shouldFail(new FailTwoMixedArgsSecondArgDoesntThrowNPE()); + public void testFailTwoMixedArgsSecondArgDoesntThrowNpe() { + shouldFail(new FailTwoMixedArgsSecondArgDoesntThrowNpe()); } private static class FailTwoMixedArgsSecondArgThrowsWrongType extends PassObject { @Override public void twoMixedArgs(@Nullable Integer i, String s) { - doThrow(s); // Fail: throwing non-NPE exception for null s + doThrow(s); // Fail: throwing non-NPE exception for null s } } @@ -730,15 +730,15 @@ public void testFailTwoMixedArgsSecondArgThrowsWrongType() { shouldFail(new FailTwoMixedArgsSecondArgThrowsWrongType()); } - private static class PassTwoNullableArgsFirstThrowsNPE extends PassObject { + private static class PassTwoNullableArgsFirstThrowsNpe extends PassObject { @Override public void twoNullableArgs(@Nullable String s, @Nullable Integer i) { checkNotNull(s); // ok to throw NPE? } } - public void testPassTwoNullableArgsFirstThrowsNPE() { - shouldPass(new PassTwoNullableArgsFirstThrowsNPE()); + public void testPassTwoNullableArgsFirstThrowsNpe() { + shouldPass(new PassTwoNullableArgsFirstThrowsNpe()); } private static class PassTwoNullableArgsFirstThrowsOther extends PassObject { @@ -752,15 +752,15 @@ public void testPassTwoNullableArgsFirstThrowsOther() { shouldPass(new PassTwoNullableArgsFirstThrowsOther()); } - private static class PassTwoNullableArgsSecondThrowsNPE extends PassObject { + private static class PassTwoNullableArgsSecondThrowsNpe extends PassObject { @Override public void twoNullableArgs(@Nullable String s, @Nullable Integer i) { i.intValue(); // ok to throw NPE? } } - public void testPassTwoNullableArgsSecondThrowsNPE() { - shouldPass(new PassTwoNullableArgsSecondThrowsNPE()); + public void testPassTwoNullableArgsSecondThrowsNpe() { + shouldPass(new PassTwoNullableArgsSecondThrowsNpe()); } private static class PassTwoNullableArgsSecondThrowsOther extends PassObject { diff --git a/guava-tests/benchmark/com/google/common/util/concurrent/ExecutionListBenchmark.java b/guava-tests/benchmark/com/google/common/util/concurrent/ExecutionListBenchmark.java index c7e1de2c3f35..227ad99be874 100644 --- a/guava-tests/benchmark/com/google/common/util/concurrent/ExecutionListBenchmark.java +++ b/guava-tests/benchmark/com/google/common/util/concurrent/ExecutionListBenchmark.java @@ -89,7 +89,7 @@ public Object getImpl() { @Override ExecutionListWrapper newExecutionList() { return new ExecutionListWrapper() { - final ExecutionListCAS list = new ExecutionListCAS(); + final ExecutionListUsingCompareAndSwap list = new ExecutionListUsingCompareAndSwap(); @Override public void add(Runnable runnable, Executor executor) { @@ -581,8 +581,8 @@ private static final class RunnableExecutorPair { // A version of the list that uses compare and swap to manage the stack without locks. @SuppressWarnings({"SunApi", "removal"}) // b/345822163 - private static final class ExecutionListCAS { - static final Logger log = Logger.getLogger(ExecutionListCAS.class.getName()); + private static final class ExecutionListUsingCompareAndSwap { + static final Logger log = Logger.getLogger(ExecutionListUsingCompareAndSwap.class.getName()); private static final Unsafe UNSAFE; private static final long HEAD_OFFSET; @@ -596,7 +596,9 @@ private static final class ExecutionListCAS { static { try { UNSAFE = getUnsafe(); - HEAD_OFFSET = UNSAFE.objectFieldOffset(ExecutionListCAS.class.getDeclaredField("head")); + HEAD_OFFSET = + UNSAFE.objectFieldOffset( + ExecutionListUsingCompareAndSwap.class.getDeclaredField("head")); } catch (Exception ex) { throw new Error(ex); } diff --git a/guava-tests/test/com/google/common/base/PredicatesTest.java b/guava-tests/test/com/google/common/base/PredicatesTest.java index 26fd6bb5909b..cafa435a1133 100644 --- a/guava-tests/test/com/google/common/base/PredicatesTest.java +++ b/guava-tests/test/com/google/common/base/PredicatesTest.java @@ -717,7 +717,7 @@ public void testIn_serialization() { } public void testIn_handlesNullPointerException() { - class CollectionThatThrowsNPE extends ArrayList { + class CollectionThatThrowsNullPointerException extends ArrayList { @J2ktIncompatible // Kotlin doesn't support companions for inner classes private static final long serialVersionUID = 1L; @@ -727,13 +727,13 @@ public boolean contains(@Nullable Object element) { return super.contains(element); } } - Collection nums = new CollectionThatThrowsNPE<>(); + Collection nums = new CollectionThatThrowsNullPointerException<>(); Predicate<@Nullable Integer> isFalse = Predicates.in(nums); assertFalse(isFalse.apply(null)); } public void testIn_handlesClassCastException() { - class CollectionThatThrowsCCE extends ArrayList { + class CollectionThatThrowsClassCastException extends ArrayList { @J2ktIncompatible // Kotlin doesn't support companions for inner classes private static final long serialVersionUID = 1L; @@ -742,7 +742,7 @@ public boolean contains(@Nullable Object element) { throw new ClassCastException(""); } } - Collection nums = new CollectionThatThrowsCCE<>(); + Collection nums = new CollectionThatThrowsClassCastException<>(); nums.add(3); Predicate isThree = Predicates.in(nums); assertFalse(isThree.apply(3)); diff --git a/guava-tests/test/com/google/common/base/SuppliersTest.java b/guava-tests/test/com/google/common/base/SuppliersTest.java index b894146330f9..10cd0b040e2a 100644 --- a/guava-tests/test/com/google/common/base/SuppliersTest.java +++ b/guava-tests/test/com/google/common/base/SuppliersTest.java @@ -107,11 +107,11 @@ private void memoizeTest(CountingSupplier countingSupplier) { } public void testMemoize_redudantly() { - memoize_redudantlyTest(new CountingSupplier()); - memoize_redudantlyTest(new SerializableCountingSupplier()); + memoizeRedudantlyTest(new CountingSupplier()); + memoizeRedudantlyTest(new SerializableCountingSupplier()); } - private void memoize_redudantlyTest(CountingSupplier countingSupplier) { + private void memoizeRedudantlyTest(CountingSupplier countingSupplier) { Supplier memoizedSupplier = Suppliers.memoize(countingSupplier); assertSame(memoizedSupplier, Suppliers.memoize(memoizedSupplier)); } diff --git a/guava-tests/test/com/google/common/collect/OrderingTest.java b/guava-tests/test/com/google/common/collect/OrderingTest.java index dfe3373a0b86..f2338011e98c 100644 --- a/guava-tests/test/com/google/common/collect/OrderingTest.java +++ b/guava-tests/test/com/google/common/collect/OrderingTest.java @@ -358,7 +358,7 @@ public void testReverseOfReverseSameAsForward() { } private enum StringLengthFunction implements Function { - StringLength; + STRING_LENGTH; @Override public Integer apply(String string) { @@ -370,35 +370,35 @@ public Integer apply(String string) { public void testOnResultOf_natural() { Comparator comparator = - Ordering.natural().onResultOf(StringLengthFunction.StringLength); + Ordering.natural().onResultOf(StringLengthFunction.STRING_LENGTH); assertTrue(comparator.compare("to", "be") == 0); assertTrue(comparator.compare("or", "not") < 0); assertTrue(comparator.compare("that", "to") > 0); new EqualsTester() .addEqualityGroup( - comparator, Ordering.natural().onResultOf(StringLengthFunction.StringLength)) + comparator, Ordering.natural().onResultOf(StringLengthFunction.STRING_LENGTH)) .addEqualityGroup(DECREASING_INTEGER) .testEquals(); reserializeAndAssert(comparator); - assertEquals("Ordering.natural().onResultOf(StringLength)", comparator.toString()); + assertEquals("Ordering.natural().onResultOf(STRING_LENGTH)", comparator.toString()); } public void testOnResultOf_chained() { Comparator comparator = - DECREASING_INTEGER.onResultOf(StringLengthFunction.StringLength); + DECREASING_INTEGER.onResultOf(StringLengthFunction.STRING_LENGTH); assertTrue(comparator.compare("to", "be") == 0); assertTrue(comparator.compare("not", "or") < 0); assertTrue(comparator.compare("to", "that") > 0); new EqualsTester() .addEqualityGroup( - comparator, DECREASING_INTEGER.onResultOf(StringLengthFunction.StringLength)) + comparator, DECREASING_INTEGER.onResultOf(StringLengthFunction.STRING_LENGTH)) .addEqualityGroup(DECREASING_INTEGER.onResultOf(Functions.constant(1))) .addEqualityGroup(Ordering.natural()) .testEquals(); reserializeAndAssert(comparator); - assertEquals("Ordering.natural().reverse().onResultOf(StringLength)", comparator.toString()); + assertEquals("Ordering.natural().reverse().onResultOf(STRING_LENGTH)", comparator.toString()); } public void testLexicographical() { diff --git a/guava-tests/test/com/google/common/collect/QueuesTest.java b/guava-tests/test/com/google/common/collect/QueuesTest.java index 53d7509dee99..277e9eceb1f3 100644 --- a/guava-tests/test/com/google/common/collect/QueuesTest.java +++ b/guava-tests/test/com/google/common/collect/QueuesTest.java @@ -125,11 +125,11 @@ private void testMultipleProducers(BlockingQueue q) throws InterruptedEx public void testDrainTimesOut() throws Exception { for (BlockingQueue q : blockingQueues()) { - testDrainTimesOut(q); + checkDrainTimesOut(q); } } - private void testDrainTimesOut(BlockingQueue q) throws Exception { + private void checkDrainTimesOut(BlockingQueue q) throws Exception { for (boolean interruptibly : new boolean[] {true, false}) { assertEquals(0, Queues.drain(q, ImmutableList.of(), 1, 10, MILLISECONDS)); @@ -157,11 +157,11 @@ private void testDrainTimesOut(BlockingQueue q) throws Exception { public void testZeroElements() throws Exception { for (BlockingQueue q : blockingQueues()) { - testZeroElements(q); + checkZeroElements(q); } } - private void testZeroElements(BlockingQueue q) throws InterruptedException { + private void checkZeroElements(BlockingQueue q) throws InterruptedException { for (boolean interruptibly : new boolean[] {true, false}) { // asking to drain zero elements assertEquals(0, drain(q, ImmutableList.of(), 0, 10, MILLISECONDS, interruptibly)); @@ -170,21 +170,21 @@ private void testZeroElements(BlockingQueue q) throws InterruptedExcepti public void testEmpty() throws Exception { for (BlockingQueue q : blockingQueues()) { - testEmpty(q); + checkEmpty(q); } } - private void testEmpty(BlockingQueue q) { + private void checkEmpty(BlockingQueue q) { assertDrained(q); } public void testNegativeMaxElements() throws Exception { for (BlockingQueue q : blockingQueues()) { - testNegativeMaxElements(q); + checkNegativeMaxElements(q); } } - private void testNegativeMaxElements(BlockingQueue q) throws InterruptedException { + private void checkNegativeMaxElements(BlockingQueue q) throws InterruptedException { @SuppressWarnings("unused") // https://errorprone.info/bugpattern/FutureReturnValueIgnored Future possiblyIgnoredError = threadPool.submit(new Producer(q, 1)); @@ -199,11 +199,11 @@ private void testNegativeMaxElements(BlockingQueue q) throws Interrupted public void testDrain_throws() throws Exception { for (BlockingQueue q : blockingQueues()) { - testDrain_throws(q); + checkDrainThrows(q); } } - private void testDrain_throws(BlockingQueue q) { + private void checkDrainThrows(BlockingQueue q) { @SuppressWarnings("unused") // https://errorprone.info/bugpattern/FutureReturnValueIgnored Future possiblyIgnoredError = threadPool.submit(new Interrupter(currentThread())); try { @@ -215,11 +215,11 @@ private void testDrain_throws(BlockingQueue q) { public void testDrainUninterruptibly_doesNotThrow() throws Exception { for (BlockingQueue q : blockingQueues()) { - testDrainUninterruptibly_doesNotThrow(q); + testDrainUninterruptiblyDoesNotThrow(q); } } - private void testDrainUninterruptibly_doesNotThrow(final BlockingQueue q) { + private void testDrainUninterruptiblyDoesNotThrow(final BlockingQueue q) { final Thread mainThread = currentThread(); @SuppressWarnings("unused") // https://errorprone.info/bugpattern/FutureReturnValueIgnored Future possiblyIgnoredError = diff --git a/guava-tests/test/com/google/common/collect/StreamsTest.java b/guava-tests/test/com/google/common/collect/StreamsTest.java index 9fb842c10807..a7d0a2a30a8f 100644 --- a/guava-tests/test/com/google/common/collect/StreamsTest.java +++ b/guava-tests/test/com/google/common/collect/StreamsTest.java @@ -327,15 +327,15 @@ public void testMapWithIndex_unsizedSource() { } public void testMapWithIndex_closeIsPropagated_sizedSource() { - testMapWithIndex_closeIsPropagated(Stream.of("a", "b", "c")); + checkMapWithIndexCloseIsPropagated(Stream.of("a", "b", "c")); } public void testMapWithIndex_closeIsPropagated_unsizedSource() { - testMapWithIndex_closeIsPropagated( + checkMapWithIndexCloseIsPropagated( Stream.<@Nullable Object>of((Object) null).flatMap(unused -> Stream.of("a", "b", "c"))); } - private void testMapWithIndex_closeIsPropagated(Stream source) { + private void checkMapWithIndexCloseIsPropagated(Stream source) { AtomicInteger stringsCloseCount = new AtomicInteger(); Stream strings = source.onClose(stringsCloseCount::incrementAndGet); Stream withIndex = Streams.mapWithIndex(strings, (str, i) -> str + ":" + i); @@ -352,15 +352,15 @@ public void testMapWithIndex_intStream() { } public void testMapWithIndex_intStream_closeIsPropagated_sized() { - testMapWithIndex_intStream_closeIsPropagated(IntStream.of(1, 2, 3)); + checkMapWithIndexIntStreamCloseIsPropagated(IntStream.of(1, 2, 3)); } public void testMapWithIndex_intStream_closeIsPropagated_unsized() { - testMapWithIndex_intStream_closeIsPropagated( + checkMapWithIndexIntStreamCloseIsPropagated( IntStream.of(0).flatMap(unused -> IntStream.of(1, 2, 3))); } - private void testMapWithIndex_intStream_closeIsPropagated(IntStream source) { + private void checkMapWithIndexIntStreamCloseIsPropagated(IntStream source) { AtomicInteger intStreamCloseCount = new AtomicInteger(); IntStream intStream = source.onClose(intStreamCloseCount::incrementAndGet); Stream withIndex = Streams.mapWithIndex(intStream, (str, i) -> str + ":" + i); @@ -377,15 +377,15 @@ public void testMapWithIndex_longStream() { } public void testMapWithIndex_longStream_closeIsPropagated_sized() { - testMapWithIndex_longStream_closeIsPropagated(LongStream.of(1, 2, 3)); + checkMapWithIndexLongStreamCloseIsPropagated(LongStream.of(1, 2, 3)); } public void testMapWithIndex_longStream_closeIsPropagated_unsized() { - testMapWithIndex_longStream_closeIsPropagated( + checkMapWithIndexLongStreamCloseIsPropagated( LongStream.of(0).flatMap(unused -> LongStream.of(1, 2, 3))); } - private void testMapWithIndex_longStream_closeIsPropagated(LongStream source) { + private void checkMapWithIndexLongStreamCloseIsPropagated(LongStream source) { AtomicInteger longStreamCloseCount = new AtomicInteger(); LongStream longStream = source.onClose(longStreamCloseCount::incrementAndGet); Stream withIndex = Streams.mapWithIndex(longStream, (str, i) -> str + ":" + i); @@ -404,15 +404,15 @@ public void testMapWithIndex_doubleStream() { } public void testMapWithIndex_doubleStream_closeIsPropagated_sized() { - testMapWithIndex_doubleStream_closeIsPropagated(DoubleStream.of(1, 2, 3)); + checkMapWithIndexDoubleStreamCloseIsPropagated(DoubleStream.of(1, 2, 3)); } public void testMapWithIndex_doubleStream_closeIsPropagated_unsized() { - testMapWithIndex_doubleStream_closeIsPropagated( + checkMapWithIndexDoubleStreamCloseIsPropagated( DoubleStream.of(0).flatMap(unused -> DoubleStream.of(1, 2, 3))); } - private void testMapWithIndex_doubleStream_closeIsPropagated(DoubleStream source) { + private void checkMapWithIndexDoubleStreamCloseIsPropagated(DoubleStream source) { AtomicInteger doubleStreamCloseCount = new AtomicInteger(); DoubleStream doubleStream = source.onClose(doubleStreamCloseCount::incrementAndGet); Stream withIndex = Streams.mapWithIndex(doubleStream, (str, i) -> str + ":" + i); diff --git a/guava-tests/test/com/google/common/math/BigDecimalMathTest.java b/guava-tests/test/com/google/common/math/BigDecimalMathTest.java index bb383a0d891d..ba78c5dba7cc 100644 --- a/guava-tests/test/com/google/common/math/BigDecimalMathTest.java +++ b/guava-tests/test/com/google/common/math/BigDecimalMathTest.java @@ -181,13 +181,15 @@ public void testRoundToDouble_twoToThe54PlusFour() { } public void testRoundToDouble_maxDouble() { - BigDecimal maxDoubleAsBD = new BigDecimal(Double.MAX_VALUE); - new RoundToDoubleTester(maxDoubleAsBD).setExpectation(Double.MAX_VALUE, values()).test(); + BigDecimal maxDoubleAsBigDecimal = new BigDecimal(Double.MAX_VALUE); + new RoundToDoubleTester(maxDoubleAsBigDecimal) + .setExpectation(Double.MAX_VALUE, values()) + .test(); } public void testRoundToDouble_maxDoublePlusOne() { - BigDecimal maxDoubleAsBD = new BigDecimal(Double.MAX_VALUE).add(BigDecimal.ONE); - new RoundToDoubleTester(maxDoubleAsBD) + BigDecimal maxDoubleAsBigDecimal = new BigDecimal(Double.MAX_VALUE).add(BigDecimal.ONE); + new RoundToDoubleTester(maxDoubleAsBigDecimal) .setExpectation(Double.MAX_VALUE, DOWN, FLOOR, HALF_EVEN, HALF_UP, HALF_DOWN) .setExpectation(Double.POSITIVE_INFINITY, UP, CEILING) .roundUnnecessaryShouldThrow() @@ -247,13 +249,15 @@ public void testRoundToDouble_negativeTwoToThe54MinusFour() { } public void testRoundToDouble_minDouble() { - BigDecimal minDoubleAsBD = new BigDecimal(-Double.MAX_VALUE); - new RoundToDoubleTester(minDoubleAsBD).setExpectation(-Double.MAX_VALUE, values()).test(); + BigDecimal minDoubleAsBigDecimal = new BigDecimal(-Double.MAX_VALUE); + new RoundToDoubleTester(minDoubleAsBigDecimal) + .setExpectation(-Double.MAX_VALUE, values()) + .test(); } public void testRoundToDouble_minDoubleMinusOne() { - BigDecimal minDoubleAsBD = new BigDecimal(-Double.MAX_VALUE).subtract(BigDecimal.ONE); - new RoundToDoubleTester(minDoubleAsBD) + BigDecimal minDoubleAsBigDecimal = new BigDecimal(-Double.MAX_VALUE).subtract(BigDecimal.ONE); + new RoundToDoubleTester(minDoubleAsBigDecimal) .setExpectation(-Double.MAX_VALUE, DOWN, CEILING, HALF_EVEN, HALF_UP, HALF_DOWN) .setExpectation(Double.NEGATIVE_INFINITY, UP, FLOOR) .roundUnnecessaryShouldThrow() diff --git a/guava-tests/test/com/google/common/math/BigIntegerMathTest.java b/guava-tests/test/com/google/common/math/BigIntegerMathTest.java index e60cf683dfbc..f710ecdaa683 100644 --- a/guava-tests/test/com/google/common/math/BigIntegerMathTest.java +++ b/guava-tests/test/com/google/common/math/BigIntegerMathTest.java @@ -621,16 +621,18 @@ public void testRoundToDouble_twoToThe54PlusFour() { @J2ktIncompatible @GwtIncompatible public void testRoundToDouble_maxDouble() { - BigInteger maxDoubleAsBI = DoubleMath.roundToBigInteger(Double.MAX_VALUE, UNNECESSARY); - new RoundToDoubleTester(maxDoubleAsBI).setExpectation(Double.MAX_VALUE, values()).test(); + BigInteger maxDoubleAsBigInteger = DoubleMath.roundToBigInteger(Double.MAX_VALUE, UNNECESSARY); + new RoundToDoubleTester(maxDoubleAsBigInteger) + .setExpectation(Double.MAX_VALUE, values()) + .test(); } @J2ktIncompatible @GwtIncompatible public void testRoundToDouble_maxDoublePlusOne() { - BigInteger maxDoubleAsBI = + BigInteger maxDoubleAsBigInteger = DoubleMath.roundToBigInteger(Double.MAX_VALUE, UNNECESSARY).add(BigInteger.ONE); - new RoundToDoubleTester(maxDoubleAsBI) + new RoundToDoubleTester(maxDoubleAsBigInteger) .setExpectation(Double.MAX_VALUE, DOWN, FLOOR, HALF_EVEN, HALF_UP, HALF_DOWN) .setExpectation(Double.POSITIVE_INFINITY, UP, CEILING) .roundUnnecessaryShouldThrow() @@ -706,16 +708,18 @@ public void testRoundToDouble_negativeTwoToThe54MinusFour() { @J2ktIncompatible @GwtIncompatible public void testRoundToDouble_minDouble() { - BigInteger minDoubleAsBI = DoubleMath.roundToBigInteger(-Double.MAX_VALUE, UNNECESSARY); - new RoundToDoubleTester(minDoubleAsBI).setExpectation(-Double.MAX_VALUE, values()).test(); + BigInteger minDoubleAsBigInteger = DoubleMath.roundToBigInteger(-Double.MAX_VALUE, UNNECESSARY); + new RoundToDoubleTester(minDoubleAsBigInteger) + .setExpectation(-Double.MAX_VALUE, values()) + .test(); } @J2ktIncompatible @GwtIncompatible public void testRoundToDouble_minDoubleMinusOne() { - BigInteger minDoubleAsBI = + BigInteger minDoubleAsBigInteger = DoubleMath.roundToBigInteger(-Double.MAX_VALUE, UNNECESSARY).subtract(BigInteger.ONE); - new RoundToDoubleTester(minDoubleAsBI) + new RoundToDoubleTester(minDoubleAsBigInteger) .setExpectation(-Double.MAX_VALUE, DOWN, CEILING, HALF_EVEN, HALF_UP, HALF_DOWN) .setExpectation(Double.NEGATIVE_INFINITY, UP, FLOOR) .roundUnnecessaryShouldThrow() diff --git a/guava-tests/test/com/google/common/net/InetAddressesTest.java b/guava-tests/test/com/google/common/net/InetAddressesTest.java index 3f442deaab98..03425f0abebf 100644 --- a/guava-tests/test/com/google/common/net/InetAddressesTest.java +++ b/guava-tests/test/com/google/common/net/InetAddressesTest.java @@ -735,6 +735,7 @@ public void testIsMaximum() throws UnknownHostException { assertTrue(InetAddresses.isMaximum(address)); } + @SuppressWarnings("IdentifierName") // the best we could do for adjacent digit blocks public void testIncrementIPv4() throws UnknownHostException { InetAddress address_66_0 = InetAddress.getByName("172.24.66.0"); InetAddress address_66_255 = InetAddress.getByName("172.24.66.255"); @@ -753,6 +754,7 @@ public void testIncrementIPv4() throws UnknownHostException { assertThrows(IllegalArgumentException.class, () -> InetAddresses.increment(address_ffffff)); } + @SuppressWarnings("IdentifierName") // the best we could do for adjacent digit blocks public void testIncrementIPv6() throws UnknownHostException { InetAddress addressV6_66_0 = InetAddress.getByName("2001:db8::6600"); InetAddress addressV6_66_ff = InetAddress.getByName("2001:db8::66ff"); diff --git a/guava-tests/test/com/google/common/reflect/AbstractInvocationHandlerTest.java b/guava-tests/test/com/google/common/reflect/AbstractInvocationHandlerTest.java index 7a02d07db059..5684dda5c6e8 100644 --- a/guava-tests/test/com/google/common/reflect/AbstractInvocationHandlerTest.java +++ b/guava-tests/test/com/google/common/reflect/AbstractInvocationHandlerTest.java @@ -55,10 +55,6 @@ interface A {} interface B {} public void testEquals() { - class AB implements A, B {} - class BA implements B, A {} - AB ab = new AB(); - BA ba = new BA(); new EqualsTester() .addEqualityGroup(newDelegatingList(LIST1)) // Actually, this violates List#equals contract. diff --git a/guava-tests/test/com/google/common/reflect/TypeTokenTest.java b/guava-tests/test/com/google/common/reflect/TypeTokenTest.java index 4acb5a1086ed..cfaf9f6ffdd1 100644 --- a/guava-tests/test/com/google/common/reflect/TypeTokenTest.java +++ b/guava-tests/test/com/google/common/reflect/TypeTokenTest.java @@ -584,9 +584,9 @@ private abstract static class Third extends Second {} private abstract static class Fourth extends Third {} - private static class ConcreteIS extends Fourth {} + private static class ConcreteIntegerString extends Fourth {} - private static class ConcreteSI extends Fourth {} + private static class ConcreteStringInteger extends Fourth {} public void testAssignableClassToClass() { @SuppressWarnings("rawtypes") // To test TypeToken @@ -759,8 +759,8 @@ public void testAssignableClassToType() { assertFalse(tokenL.isSupertypeOf(List.class)); TypeToken> tokenF = new TypeToken>() {}; - assertTrue(tokenF.isSupertypeOf(ConcreteIS.class)); - assertFalse(tokenF.isSupertypeOf(ConcreteSI.class)); + assertTrue(tokenF.isSupertypeOf(ConcreteIntegerString.class)); + assertFalse(tokenF.isSupertypeOf(ConcreteStringInteger.class)); } public void testAssignableClassToArrayType() { @@ -775,8 +775,8 @@ public void testAssignableParameterizedTypeToType() { assertFalse(tokenL.isSupertypeOf(IntegerList.class.getGenericInterfaces()[0])); TypeToken> tokenF = new TypeToken>() {}; - assertTrue(tokenF.isSupertypeOf(ConcreteIS.class.getGenericSuperclass())); - assertFalse(tokenF.isSupertypeOf(ConcreteSI.class.getGenericSuperclass())); + assertTrue(tokenF.isSupertypeOf(ConcreteIntegerString.class.getGenericSuperclass())); + assertFalse(tokenF.isSupertypeOf(ConcreteStringInteger.class.getGenericSuperclass())); } public void testGenericArrayTypeToArrayType() { @@ -798,8 +798,8 @@ public void testAssignableTokenToType() { assertFalse(tokenF.isSupertypeOf(new TypeToken>() {})); assertTrue(tokenF.isSupertypeOf(new TypeToken>() {})); assertFalse(tokenF.isSupertypeOf(new TypeToken>() {})); - assertTrue(tokenF.isSupertypeOf(new TypeToken() {})); - assertFalse(tokenF.isSupertypeOf(new TypeToken() {})); + assertTrue(tokenF.isSupertypeOf(new TypeToken() {})); + assertFalse(tokenF.isSupertypeOf(new TypeToken() {})); } public void testAssignableWithWildcards() { diff --git a/guava-tests/test/com/google/common/reflect/TypesTest.java b/guava-tests/test/com/google/common/reflect/TypesTest.java index 42ac44f5bbda..785b3a65872a 100644 --- a/guava-tests/test/com/google/common/reflect/TypesTest.java +++ b/guava-tests/test/com/google/common/reflect/TypesTest.java @@ -84,10 +84,10 @@ class LocalClass {} } public void testNewParameterizedType_staticLocalClass() { - doTestNewParameterizedType_staticLocalClass(); + doTestNewParameterizedTypeStaticLocalClass(); } - private static void doTestNewParameterizedType_staticLocalClass() { + private static void doTestNewParameterizedTypeStaticLocalClass() { class LocalClass {} Type jvmType = new LocalClass() {}.getClass().getGenericSuperclass(); Type ourType = Types.newParameterizedType(LocalClass.class, String.class); diff --git a/guava-tests/test/com/google/common/util/concurrent/FuturesTest.java b/guava-tests/test/com/google/common/util/concurrent/FuturesTest.java index aa900d6a0802..683abc29c47e 100644 --- a/guava-tests/test/com/google/common/util/concurrent/FuturesTest.java +++ b/guava-tests/test/com/google/common/util/concurrent/FuturesTest.java @@ -3337,7 +3337,7 @@ public void testSuccessfulAsList_resultCancelledRacingInputDone() throws Excepti Logger exceptionLogger = Logger.getLogger(AbstractFuture.class.getName()); exceptionLogger.addHandler(listenerLoggerHandler); try { - doTestSuccessfulAsList_resultCancelledRacingInputDone(); + doTestSuccessfulAsListResultCancelledRacingInputDone(); assertWithMessage("Nothing should be logged") .that(listenerLoggerHandler.getStoredLogRecords()) @@ -3347,7 +3347,7 @@ public void testSuccessfulAsList_resultCancelledRacingInputDone() throws Excepti } } - private static void doTestSuccessfulAsList_resultCancelledRacingInputDone() throws Exception { + private static void doTestSuccessfulAsListResultCancelledRacingInputDone() throws Exception { // Simple (combined.cancel -> input.cancel -> setOneValue): successfulAsList(ImmutableList.of(SettableFuture.create())).cancel(true); diff --git a/guava-tests/test/com/google/common/util/concurrent/JSR166TestCase.java b/guava-tests/test/com/google/common/util/concurrent/JSR166TestCase.java index d95939b56c0f..341cfa83b099 100644 --- a/guava-tests/test/com/google/common/util/concurrent/JSR166TestCase.java +++ b/guava-tests/test/com/google/common/util/concurrent/JSR166TestCase.java @@ -100,12 +100,15 @@ * tests. * */ -// We call threadUnexpectedException, which does the right thing for errors. -@SuppressWarnings("AssertionFailureIgnored") +@SuppressWarnings({ + // We call threadUnexpectedException, which does the right thing for errors. + "AssertionFailureIgnored", + // We're following the upstream naming to reduce diffs. + "IdentifierName", + "ConstantCaseForConstants", +}) @NullUnmarked abstract class JSR166TestCase extends TestCase { - private static final boolean useSecurityManager = Boolean.getBoolean("jsr166.useSecurityManager"); - protected static final boolean expensiveTests = Boolean.getBoolean("jsr166.expensiveTests"); /** diff --git a/guava/src/com/google/common/base/Throwables.java b/guava/src/com/google/common/base/Throwables.java index 1ac398a8f8c7..319828d8990b 100644 --- a/guava/src/com/google/common/base/Throwables.java +++ b/guava/src/com/google/common/base/Throwables.java @@ -454,7 +454,7 @@ private static Object invokeAccessibleNonThrowingMethod( /** Access to some fancy internal JVM internals. */ @J2ktIncompatible @GwtIncompatible // java.lang.reflect - private static final @Nullable Object jla = getJLA(); + private static final @Nullable Object jla = getJla(); /** * The "getStackTraceElementMethod" method, only available on some JDKs so we use reflection to @@ -479,7 +479,7 @@ private static Object invokeAccessibleNonThrowingMethod( @SuppressWarnings("removal") // b/318391980 @J2ktIncompatible @GwtIncompatible // java.lang.reflect - private static @Nullable Object getJLA() { + private static @Nullable Object getJla() { try { /* * We load sun.misc.* classes using reflection since Android doesn't support these classes and diff --git a/guava/src/com/google/common/collect/TreeRangeSet.java b/guava/src/com/google/common/collect/TreeRangeSet.java index 2ee5b08ffa67..11f585c35ef3 100644 --- a/guava/src/com/google/common/collect/TreeRangeSet.java +++ b/guava/src/com/google/common/collect/TreeRangeSet.java @@ -187,31 +187,31 @@ public void add(Range rangeToAdd) { Cut lbToAdd = rangeToAdd.lowerBound; Cut ubToAdd = rangeToAdd.upperBound; - Entry, Range> entryBelowLB = rangesByLowerBound.lowerEntry(lbToAdd); - if (entryBelowLB != null) { + Entry, Range> entryBelowLb = rangesByLowerBound.lowerEntry(lbToAdd); + if (entryBelowLb != null) { // { < - Range rangeBelowLB = entryBelowLB.getValue(); - if (rangeBelowLB.upperBound.compareTo(lbToAdd) >= 0) { + Range rangeBelowLb = entryBelowLb.getValue(); + if (rangeBelowLb.upperBound.compareTo(lbToAdd) >= 0) { // { < }, and we will need to coalesce - if (rangeBelowLB.upperBound.compareTo(ubToAdd) >= 0) { + if (rangeBelowLb.upperBound.compareTo(ubToAdd) >= 0) { // { < > } - ubToAdd = rangeBelowLB.upperBound; + ubToAdd = rangeBelowLb.upperBound; /* * TODO(cpovirk): can we just "return;" here? Or, can we remove this if() entirely? If * not, add tests to demonstrate the problem with each approach */ } - lbToAdd = rangeBelowLB.lowerBound; + lbToAdd = rangeBelowLb.lowerBound; } } - Entry, Range> entryBelowUB = rangesByLowerBound.floorEntry(ubToAdd); - if (entryBelowUB != null) { + Entry, Range> entryBelowUb = rangesByLowerBound.floorEntry(ubToAdd); + if (entryBelowUb != null) { // { > - Range rangeBelowUB = entryBelowUB.getValue(); - if (rangeBelowUB.upperBound.compareTo(ubToAdd) >= 0) { + Range rangeBelowUb = entryBelowUb.getValue(); + if (rangeBelowUb.upperBound.compareTo(ubToAdd) >= 0) { // { > }, and we need to coalesce - ubToAdd = rangeBelowUB.upperBound; + ubToAdd = rangeBelowUb.upperBound; } } @@ -232,32 +232,32 @@ public void remove(Range rangeToRemove) { // We will use { } to illustrate ranges currently in the range set, and < > // to illustrate rangeToRemove. - Entry, Range> entryBelowLB = rangesByLowerBound.lowerEntry(rangeToRemove.lowerBound); - if (entryBelowLB != null) { + Entry, Range> entryBelowLb = rangesByLowerBound.lowerEntry(rangeToRemove.lowerBound); + if (entryBelowLb != null) { // { < - Range rangeBelowLB = entryBelowLB.getValue(); - if (rangeBelowLB.upperBound.compareTo(rangeToRemove.lowerBound) >= 0) { + Range rangeBelowLb = entryBelowLb.getValue(); + if (rangeBelowLb.upperBound.compareTo(rangeToRemove.lowerBound) >= 0) { // { < }, and we will need to subdivide if (rangeToRemove.hasUpperBound() - && rangeBelowLB.upperBound.compareTo(rangeToRemove.upperBound) >= 0) { + && rangeBelowLb.upperBound.compareTo(rangeToRemove.upperBound) >= 0) { // { < > } replaceRangeWithSameLowerBound( - Range.create(rangeToRemove.upperBound, rangeBelowLB.upperBound)); + Range.create(rangeToRemove.upperBound, rangeBelowLb.upperBound)); } replaceRangeWithSameLowerBound( - Range.create(rangeBelowLB.lowerBound, rangeToRemove.lowerBound)); + Range.create(rangeBelowLb.lowerBound, rangeToRemove.lowerBound)); } } - Entry, Range> entryBelowUB = rangesByLowerBound.floorEntry(rangeToRemove.upperBound); - if (entryBelowUB != null) { + Entry, Range> entryBelowUb = rangesByLowerBound.floorEntry(rangeToRemove.upperBound); + if (entryBelowUb != null) { // { > - Range rangeBelowUB = entryBelowUB.getValue(); + Range rangeBelowUb = entryBelowUb.getValue(); if (rangeToRemove.hasUpperBound() - && rangeBelowUB.upperBound.compareTo(rangeToRemove.upperBound) >= 0) { + && rangeBelowUb.upperBound.compareTo(rangeToRemove.upperBound) >= 0) { // { > } replaceRangeWithSameLowerBound( - Range.create(rangeToRemove.upperBound, rangeBelowUB.upperBound)); + Range.create(rangeToRemove.upperBound, rangeBelowUb.upperBound)); } } diff --git a/guava/src/com/google/common/hash/Hashing.java b/guava/src/com/google/common/hash/Hashing.java index 3f91ddcfcf7d..d4b7456f5866 100644 --- a/guava/src/com/google/common/hash/Hashing.java +++ b/guava/src/com/google/common/hash/Hashing.java @@ -109,6 +109,7 @@ public static HashFunction goodFastHash(int minimumBits) { * #murmur3_32_fixed(int)} instead. */ @Deprecated + @SuppressWarnings("IdentifierName") // the best we could do for adjacent digit blocks public static HashFunction murmur3_32(int seed) { return new Murmur3_32HashFunction(seed, /* supplementaryPlaneFix= */ false); } @@ -127,6 +128,7 @@ public static HashFunction murmur3_32(int seed) { * #murmur3_32_fixed()} instead. */ @Deprecated + @SuppressWarnings("IdentifierName") // the best we could do for adjacent digit blocks public static HashFunction murmur3_32() { return Murmur3_32HashFunction.MURMUR3_32; } @@ -143,6 +145,7 @@ public static HashFunction murmur3_32() { * * @since 31.0 */ + @SuppressWarnings("IdentifierName") // the best we could do for adjacent digit blocks public static HashFunction murmur3_32_fixed(int seed) { return new Murmur3_32HashFunction(seed, /* supplementaryPlaneFix= */ true); } @@ -159,6 +162,7 @@ public static HashFunction murmur3_32_fixed(int seed) { * * @since 31.0 */ + @SuppressWarnings("IdentifierName") // the best we could do for adjacent digit blocks public static HashFunction murmur3_32_fixed() { return Murmur3_32HashFunction.MURMUR3_32_FIXED; } @@ -170,6 +174,7 @@ public static HashFunction murmur3_32_fixed() { * *

The exact C++ equivalent is the MurmurHash3_x64_128 function (Murmur3F). */ + @SuppressWarnings("IdentifierName") // the best we could do for adjacent digit blocks public static HashFunction murmur3_128(int seed) { return new Murmur3_128HashFunction(seed); } @@ -181,6 +186,7 @@ public static HashFunction murmur3_128(int seed) { * *

The exact C++ equivalent is the MurmurHash3_x64_128 function (Murmur3F). */ + @SuppressWarnings("IdentifierName") // the best we could do for adjacent digit blocks public static HashFunction murmur3_128() { return Murmur3_128HashFunction.MURMUR3_128; } diff --git a/guava/src/com/google/common/hash/Murmur3_128HashFunction.java b/guava/src/com/google/common/hash/Murmur3_128HashFunction.java index c340f0297661..3ce78e8614c6 100644 --- a/guava/src/com/google/common/hash/Murmur3_128HashFunction.java +++ b/guava/src/com/google/common/hash/Murmur3_128HashFunction.java @@ -41,6 +41,7 @@ * @author Dimitris Andreou */ @Immutable +@SuppressWarnings("IdentifierName") // the best we could do for adjacent digit blocks final class Murmur3_128HashFunction extends AbstractHashFunction implements Serializable { static final HashFunction MURMUR3_128 = new Murmur3_128HashFunction(0); diff --git a/guava/src/com/google/common/hash/Murmur3_32HashFunction.java b/guava/src/com/google/common/hash/Murmur3_32HashFunction.java index a40c2fbeb00e..4ed25af7291e 100644 --- a/guava/src/com/google/common/hash/Murmur3_32HashFunction.java +++ b/guava/src/com/google/common/hash/Murmur3_32HashFunction.java @@ -51,6 +51,7 @@ * @author Kurt Alfred Kluever */ @Immutable +@SuppressWarnings("IdentifierName") // the best we could do for adjacent digit blocks final class Murmur3_32HashFunction extends AbstractHashFunction implements Serializable { static final HashFunction MURMUR3_32 = new Murmur3_32HashFunction(0, /* supplementaryPlaneFix= */ false); diff --git a/guava/src/com/google/common/io/Closeables.java b/guava/src/com/google/common/io/Closeables.java index 3a225edfbd3a..e9c580af36a6 100644 --- a/guava/src/com/google/common/io/Closeables.java +++ b/guava/src/com/google/common/io/Closeables.java @@ -69,6 +69,16 @@ private Closeables() {} * @throws IOException if {@code swallowIOException} is false and {@code close} throws an {@code * IOException}. */ + /* + * The proper capitalization would be "swallowIoException." However: + * + * - It might be preferable to be consistent with the JDK precedent (which they stuck with even + * for "UncheckedIOException"). + * + * - If we change the name, some of our callers break because our Android Lint ParameterName check + * doesn't make the exception for com.google.common that internal Error Prone does: b/386402967. + */ + @SuppressWarnings("IdentifierName") public static void close(@Nullable Closeable closeable, boolean swallowIOException) throws IOException { if (closeable == null) { diff --git a/guava/src/com/google/common/io/Flushables.java b/guava/src/com/google/common/io/Flushables.java index 412a09bbfe82..7e5e11275c0a 100644 --- a/guava/src/com/google/common/io/Flushables.java +++ b/guava/src/com/google/common/io/Flushables.java @@ -48,6 +48,7 @@ private Flushables() {} * an {@code IOException}. * @see Closeables#close */ + @SuppressWarnings("IdentifierName") // See Closeables.close public static void flush(Flushable flushable, boolean swallowIOException) throws IOException { try { flushable.flush();