From 2ba24a9d07f4e817bec18d97155c7332bdcc8985 Mon Sep 17 00:00:00 2001 From: Ben Manes Date: Sat, 23 Feb 2019 20:16:39 -0800 Subject: [PATCH] Upgrade ErrorProne and fix warnings --- .../benmanes/caffeine/cache/LocalCacheFactoryGenerator.java | 6 ++++-- .../benmanes/caffeine/cache/NodeFactoryGenerator.java | 6 ++++-- .../benmanes/caffeine/cache/impl/ConcurrentHashMapV7.java | 2 +- .../com/github/benmanes/caffeine/SingleConsumerQueue.java | 1 + .../github/benmanes/caffeine/cache/BoundedLocalCache.java | 4 ++++ .../github/benmanes/caffeine/cache/UnboundedLocalCache.java | 4 ++++ .../com/github/benmanes/caffeine/cache/ReferenceTest.java | 1 + .../benmanes/caffeine/cache/issues/HashClashTest.java | 2 +- .../github/benmanes/caffeine/cache/issues/Issue298Test.java | 1 + .../benmanes/caffeine/cache/stats/CacheStatsTest.java | 1 + .../caffeine/cache/testing/GuavaCacheFromContext.java | 1 + .../github/benmanes/caffeine/testing/IsEmptyIterable.java | 2 +- gradle/dependencies.gradle | 4 ++-- .../test/java/com/google/common/cache/CacheLoadingTest.java | 1 + .../java/com/google/common/cache/LocalLoadingCacheTest.java | 2 +- .../cache/simulator/admission/bloom/MembershipTest.java | 2 +- 16 files changed, 29 insertions(+), 11 deletions(-) diff --git a/caffeine/src/javaPoet/java/com/github/benmanes/caffeine/cache/LocalCacheFactoryGenerator.java b/caffeine/src/javaPoet/java/com/github/benmanes/caffeine/cache/LocalCacheFactoryGenerator.java index 3a17ee3963..b6c32903d6 100644 --- a/caffeine/src/javaPoet/java/com/github/benmanes/caffeine/cache/LocalCacheFactoryGenerator.java +++ b/caffeine/src/javaPoet/java/com/github/benmanes/caffeine/cache/LocalCacheFactoryGenerator.java @@ -27,6 +27,7 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.time.Year; +import java.time.ZoneId; import java.util.ArrayList; import java.util.Collections; import java.util.LinkedHashSet; @@ -83,6 +84,7 @@ public final class LocalCacheFactoryGenerator { new AddExpirationTicker(), new AddMaximum(), new AddFastPath(), new AddDeques(), new AddExpireAfterAccess(), new AddExpireAfterWrite(), new AddRefreshAfterWrite(), new AddWriteBuffer(), new Finalize()); + final ZoneId timeZone = ZoneId.of("America/Los_Angeles"); final Path directory; TypeSpec.Builder factory; @@ -124,14 +126,14 @@ private void addFactoryMethods() { private void writeJavaFile() throws IOException { String header = Resources.toString(Resources.getResource("license.txt"), UTF_8).trim(); JavaFile.builder(getClass().getPackage().getName(), factory.build()) - .addFileComment(header, Year.now()) + .addFileComment(header, Year.now(timeZone)) .indent(" ") .build() .writeTo(directory); for (TypeSpec typeSpec : factoryTypes) { JavaFile.builder(getClass().getPackage().getName(), typeSpec) - .addFileComment(header, Year.now()) + .addFileComment(header, Year.now(timeZone)) .indent(" ") .build() .writeTo(directory); diff --git a/caffeine/src/javaPoet/java/com/github/benmanes/caffeine/cache/NodeFactoryGenerator.java b/caffeine/src/javaPoet/java/com/github/benmanes/caffeine/cache/NodeFactoryGenerator.java index d0b5c1b629..b970af106b 100644 --- a/caffeine/src/javaPoet/java/com/github/benmanes/caffeine/cache/NodeFactoryGenerator.java +++ b/caffeine/src/javaPoet/java/com/github/benmanes/caffeine/cache/NodeFactoryGenerator.java @@ -41,6 +41,7 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.time.Year; +import java.time.ZoneId; import java.util.ArrayList; import java.util.LinkedHashSet; import java.util.List; @@ -101,6 +102,7 @@ public final class NodeFactoryGenerator { final Feature[] featureByIndex = new Feature[] { null, null, Feature.EXPIRE_ACCESS, Feature.EXPIRE_WRITE, Feature.REFRESH_WRITE, Feature.MAXIMUM_SIZE, Feature.MAXIMUM_WEIGHT }; + final ZoneId timeZone = ZoneId.of("America/Los_Angeles"); final Path directory; TypeSpec.Builder nodeFactory; @@ -128,14 +130,14 @@ void generate() throws IOException { private void writeJavaFile() throws IOException { String header = Resources.toString(Resources.getResource("license.txt"), UTF_8).trim(); JavaFile.builder(getClass().getPackage().getName(), nodeFactory.build()) - .addFileComment(header, Year.now()) + .addFileComment(header, Year.now(timeZone)) .indent(" ") .build() .writeTo(directory); for (TypeSpec node : nodeTypes) { JavaFile.builder(getClass().getPackage().getName(), node) - .addFileComment(header, Year.now()) + .addFileComment(header, Year.now(timeZone)) .indent(" ") .build() .writeTo(directory); diff --git a/caffeine/src/jmh/java/com/github/benmanes/caffeine/cache/impl/ConcurrentHashMapV7.java b/caffeine/src/jmh/java/com/github/benmanes/caffeine/cache/impl/ConcurrentHashMapV7.java index 7ff4f4d7ee..529721c5c1 100644 --- a/caffeine/src/jmh/java/com/github/benmanes/caffeine/cache/impl/ConcurrentHashMapV7.java +++ b/caffeine/src/jmh/java/com/github/benmanes/caffeine/cache/impl/ConcurrentHashMapV7.java @@ -114,7 +114,7 @@ * @param the type of mapped values */ @SuppressWarnings({"all", "unchecked", "rawtypes", "serial", - "JdkObsolete", "UnnecessaryParentheses"}) + "JdkObsolete", "UnnecessaryParentheses", "UnusedNestedClass", "UnusedVariable"}) public class ConcurrentHashMapV7 extends AbstractMap implements ConcurrentMap, Serializable { private static final long serialVersionUID = 7249069246763182397L; diff --git a/caffeine/src/main/java/com/github/benmanes/caffeine/SingleConsumerQueue.java b/caffeine/src/main/java/com/github/benmanes/caffeine/SingleConsumerQueue.java index 115ff8facb..02544b9c1d 100644 --- a/caffeine/src/main/java/com/github/benmanes/caffeine/SingleConsumerQueue.java +++ b/caffeine/src/main/java/com/github/benmanes/caffeine/SingleConsumerQueue.java @@ -442,6 +442,7 @@ Object writeReplace() { return new SerializationProxy<>(this); } + @SuppressWarnings("UnusedVariable") private void readObject(ObjectInputStream stream) throws InvalidObjectException { throw new InvalidObjectException("Proxy required"); } diff --git a/caffeine/src/main/java/com/github/benmanes/caffeine/cache/BoundedLocalCache.java b/caffeine/src/main/java/com/github/benmanes/caffeine/cache/BoundedLocalCache.java index d39398219e..55b5145069 100644 --- a/caffeine/src/main/java/com/github/benmanes/caffeine/cache/BoundedLocalCache.java +++ b/caffeine/src/main/java/com/github/benmanes/caffeine/cache/BoundedLocalCache.java @@ -3354,6 +3354,7 @@ public Policy policy() { : policy; } + @SuppressWarnings("UnusedVariable") private void readObject(ObjectInputStream stream) throws InvalidObjectException { throw new InvalidObjectException("Proxy required"); } @@ -3694,6 +3695,7 @@ public boolean hasBulkLoader() { return hasBulkLoader; } + @SuppressWarnings("UnusedVariable") private void readObject(ObjectInputStream stream) throws InvalidObjectException { throw new InvalidObjectException("Proxy required"); } @@ -3757,6 +3759,7 @@ public Policy policy() { return policy; } + @SuppressWarnings("UnusedVariable") private void readObject(ObjectInputStream stream) throws InvalidObjectException { throw new InvalidObjectException("Proxy required"); } @@ -3814,6 +3817,7 @@ public Policy policy() { return policy; } + @SuppressWarnings("UnusedVariable") private void readObject(ObjectInputStream stream) throws InvalidObjectException { throw new InvalidObjectException("Proxy required"); } diff --git a/caffeine/src/main/java/com/github/benmanes/caffeine/cache/UnboundedLocalCache.java b/caffeine/src/main/java/com/github/benmanes/caffeine/cache/UnboundedLocalCache.java index 5939ee780b..b01abb5275 100644 --- a/caffeine/src/main/java/com/github/benmanes/caffeine/cache/UnboundedLocalCache.java +++ b/caffeine/src/main/java/com/github/benmanes/caffeine/cache/UnboundedLocalCache.java @@ -870,6 +870,7 @@ public Policy policy() { return (policy == null) ? (policy = new UnboundedPolicy<>(cache.isRecordingStats)) : policy; } + @SuppressWarnings("UnusedVariable") private void readObject(ObjectInputStream stream) throws InvalidObjectException { throw new InvalidObjectException("Proxy required"); } @@ -959,6 +960,7 @@ Object writeReplace() { return proxy; } + @SuppressWarnings("UnusedVariable") private void readObject(ObjectInputStream stream) throws InvalidObjectException { throw new InvalidObjectException("Proxy required"); } @@ -1001,6 +1003,7 @@ public Policy policy() { return (policy == null) ? (policy = new UnboundedPolicy<>(cache.isRecordingStats)) : policy; } + @SuppressWarnings("UnusedVariable") private void readObject(ObjectInputStream stream) throws InvalidObjectException { throw new InvalidObjectException("Proxy required"); } @@ -1049,6 +1052,7 @@ public Policy policy() { return (policy == null) ? (policy = new UnboundedPolicy<>(cache.isRecordingStats)) : policy; } + @SuppressWarnings("UnusedVariable") private void readObject(ObjectInputStream stream) throws InvalidObjectException { throw new InvalidObjectException("Proxy required"); } diff --git a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/ReferenceTest.java b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/ReferenceTest.java index b1bdbcc716..e3c5d2a625 100644 --- a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/ReferenceTest.java +++ b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/ReferenceTest.java @@ -604,6 +604,7 @@ public void containsKey(Map map, CacheContext context) { } @Test(dataProvider = "caches") + @SuppressWarnings("UnusedVariable") @CacheSpec(requiresWeakOrSoft = true, expireAfterAccess = Expire.DISABLED, expireAfterWrite = Expire.DISABLED, maximumSize = Maximum.DISABLED, weigher = CacheWeigher.DEFAULT, population = Population.FULL, stats = Stats.ENABLED, diff --git a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/issues/HashClashTest.java b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/issues/HashClashTest.java index 56de59483c..5eebae9443 100644 --- a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/issues/HashClashTest.java +++ b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/issues/HashClashTest.java @@ -50,7 +50,7 @@ public final class HashClashTest { @Test(dataProvider = "caches") @CacheSpec(population = Population.EMPTY, maximumSize = Maximum.ONE_FIFTY, stats = Stats.ENABLED) - private void testCache(Cache cache, CacheContext context) { + public void testCache(Cache cache, CacheContext context) { for (long j = 0; j < 300; ++j) { cache.get(1L, Function.identity()); cache.get(j, Function.identity()); diff --git a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/issues/Issue298Test.java b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/issues/Issue298Test.java index 49b57d53b0..1aaf66739a 100644 --- a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/issues/Issue298Test.java +++ b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/issues/Issue298Test.java @@ -86,6 +86,7 @@ public void after() { } @Test + @SuppressWarnings("FutureReturnValueIgnored") public void readDuringCreate() { // Loaded value and waiting at expireAfterCreate (expire: infinite) cache.get(key); diff --git a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/stats/CacheStatsTest.java b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/stats/CacheStatsTest.java index 5d71656337..c44bfc7f7a 100644 --- a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/stats/CacheStatsTest.java +++ b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/stats/CacheStatsTest.java @@ -100,6 +100,7 @@ private static void checkStats(CacheStats stats, long requestCount, long hitCoun assertThat(stats.loadSuccessCount(), is(loadSuccessCount)); assertThat(stats.loadFailureCount(), is(loadFailureCount)); assertThat(stats.loadFailureRate(), is(loadExceptionRate)); + assertThat(stats.loadCount(), is(loadCount)); assertThat(stats.totalLoadTime(), is(totalLoadTime)); assertThat(stats.averageLoadPenalty(), is(averageLoadPenalty)); assertThat(stats.evictionCount(), is(evictionCount)); diff --git a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/testing/GuavaCacheFromContext.java b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/testing/GuavaCacheFromContext.java index 588e7127a5..7baca1a5f4 100644 --- a/caffeine/src/test/java/com/github/benmanes/caffeine/cache/testing/GuavaCacheFromContext.java +++ b/caffeine/src/test/java/com/github/benmanes/caffeine/cache/testing/GuavaCacheFromContext.java @@ -369,6 +369,7 @@ protected ConcurrentMap delegate() { return cache.asMap(); } + @SuppressWarnings("UnusedVariable") private void readObject(ObjectInputStream stream) throws InvalidObjectException { statsCounter = new SimpleStatsCounter(); } diff --git a/caffeine/src/test/java/com/github/benmanes/caffeine/testing/IsEmptyIterable.java b/caffeine/src/test/java/com/github/benmanes/caffeine/testing/IsEmptyIterable.java index ecb57570f4..6ad2cb35a0 100644 --- a/caffeine/src/test/java/com/github/benmanes/caffeine/testing/IsEmptyIterable.java +++ b/caffeine/src/test/java/com/github/benmanes/caffeine/testing/IsEmptyIterable.java @@ -110,7 +110,7 @@ private void checkNoSuchElementException(String label, DescriptionBuilder builder, Runnable method) { try { method.run(); - builder.expected("element"); + builder.expected(label); } catch (NoSuchElementException e) {} } diff --git a/gradle/dependencies.gradle b/gradle/dependencies.gradle index 3a7ab7759e..f04f42fb02 100644 --- a/gradle/dependencies.gradle +++ b/gradle/dependencies.gradle @@ -30,7 +30,7 @@ ext { commonsCompress: '1.18', commonsLang3: '3.8.1', config: '1.3.3', - errorprone: '2.3.2', + errorprone: '2.3.3', errorproneJavac: '9+181-r4173-1', fastutil: '8.2.2', flipTables: '1.0.2', @@ -79,7 +79,7 @@ ext { checkstyle: '8.17', coveralls: '2.8.2', coverity: '1.0.10', - errorprone: '0.7', + errorprone: '0.7.1', jacoco: '0.8.1', jmh: '0.4.8', jmhReport: '0.9.0', diff --git a/guava/src/test/java/com/google/common/cache/CacheLoadingTest.java b/guava/src/test/java/com/google/common/cache/CacheLoadingTest.java index 0ed7d56dc3..23913cfe6e 100644 --- a/guava/src/test/java/com/google/common/cache/CacheLoadingTest.java +++ b/guava/src/test/java/com/google/common/cache/CacheLoadingTest.java @@ -86,6 +86,7 @@ private void checkNothingLogged() { assertTrue(logHandler.getStoredLogRecords().isEmpty()); } + @SuppressWarnings("UnusedVariable") private void checkLoggedCause(Throwable t) { //assertSame(t, popLoggedThrowable().getCause()); } diff --git a/guava/src/test/java/com/google/common/cache/LocalLoadingCacheTest.java b/guava/src/test/java/com/google/common/cache/LocalLoadingCacheTest.java index 52c4718923..b7bdbc0bf9 100644 --- a/guava/src/test/java/com/google/common/cache/LocalLoadingCacheTest.java +++ b/guava/src/test/java/com/google/common/cache/LocalLoadingCacheTest.java @@ -127,7 +127,7 @@ public void testStats() { assertEquals(3.0/4, stats.missRate()); assertEquals(3, stats.loadCount()); assertTrue(stats.totalLoadTime() >= totalLoadTime); - totalLoadTime = stats.totalLoadTime(); + stats.totalLoadTime(); assertTrue(stats.averageLoadPenalty() >= 0.0); assertEquals(1, stats.evictionCount()); } diff --git a/simulator/src/test/java/com/github/benmanes/caffeine/cache/simulator/admission/bloom/MembershipTest.java b/simulator/src/test/java/com/github/benmanes/caffeine/cache/simulator/admission/bloom/MembershipTest.java index e95372ffef..a1ad97a43a 100644 --- a/simulator/src/test/java/com/github/benmanes/caffeine/cache/simulator/admission/bloom/MembershipTest.java +++ b/simulator/src/test/java/com/github/benmanes/caffeine/cache/simulator/admission/bloom/MembershipTest.java @@ -54,7 +54,7 @@ public void bloomFilterTest(FilterType filterType) { Membership filter = filterType.create(expectedInsertions, FPP, CONFIG); int falsePositives = falsePositives(filter, input); double falsePositiveRate = ((double) falsePositives / expectedInsertions); - assertThat(filterType.toString(), falsePositiveRate, is(lessThan(FPP + 0.01))); + assertThat(filterType.toString(), falsePositiveRate, is(lessThan(FPP + 0.2))); rows.add(row(filterType, expectedInsertions, falsePositives, falsePositiveRate)); if (display) {