Skip to content

Commit

Permalink
Upgrade ErrorProne and fix warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
ben-manes committed Feb 24, 2019
1 parent 801e532 commit 2ba24a9
Show file tree
Hide file tree
Showing 16 changed files with 29 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
* @param <V> the type of mapped values
*/
@SuppressWarnings({"all", "unchecked", "rawtypes", "serial",
"JdkObsolete", "UnnecessaryParentheses"})
"JdkObsolete", "UnnecessaryParentheses", "UnusedNestedClass", "UnusedVariable"})
public class ConcurrentHashMapV7<K, V> extends AbstractMap<K, V>
implements ConcurrentMap<K, V>, Serializable {
private static final long serialVersionUID = 7249069246763182397L;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,7 @@ Object writeReplace() {
return new SerializationProxy<>(this);
}

@SuppressWarnings("UnusedVariable")
private void readObject(ObjectInputStream stream) throws InvalidObjectException {
throw new InvalidObjectException("Proxy required");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3354,6 +3354,7 @@ public Policy<K, V> policy() {
: policy;
}

@SuppressWarnings("UnusedVariable")
private void readObject(ObjectInputStream stream) throws InvalidObjectException {
throw new InvalidObjectException("Proxy required");
}
Expand Down Expand Up @@ -3694,6 +3695,7 @@ public boolean hasBulkLoader() {
return hasBulkLoader;
}

@SuppressWarnings("UnusedVariable")
private void readObject(ObjectInputStream stream) throws InvalidObjectException {
throw new InvalidObjectException("Proxy required");
}
Expand Down Expand Up @@ -3757,6 +3759,7 @@ public Policy<K, V> policy() {
return policy;
}

@SuppressWarnings("UnusedVariable")
private void readObject(ObjectInputStream stream) throws InvalidObjectException {
throw new InvalidObjectException("Proxy required");
}
Expand Down Expand Up @@ -3814,6 +3817,7 @@ public Policy<K, V> policy() {
return policy;
}

@SuppressWarnings("UnusedVariable")
private void readObject(ObjectInputStream stream) throws InvalidObjectException {
throw new InvalidObjectException("Proxy required");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -870,6 +870,7 @@ public Policy<K, V> policy() {
return (policy == null) ? (policy = new UnboundedPolicy<>(cache.isRecordingStats)) : policy;
}

@SuppressWarnings("UnusedVariable")
private void readObject(ObjectInputStream stream) throws InvalidObjectException {
throw new InvalidObjectException("Proxy required");
}
Expand Down Expand Up @@ -959,6 +960,7 @@ Object writeReplace() {
return proxy;
}

@SuppressWarnings("UnusedVariable")
private void readObject(ObjectInputStream stream) throws InvalidObjectException {
throw new InvalidObjectException("Proxy required");
}
Expand Down Expand Up @@ -1001,6 +1003,7 @@ public Policy<K, V> policy() {
return (policy == null) ? (policy = new UnboundedPolicy<>(cache.isRecordingStats)) : policy;
}

@SuppressWarnings("UnusedVariable")
private void readObject(ObjectInputStream stream) throws InvalidObjectException {
throw new InvalidObjectException("Proxy required");
}
Expand Down Expand Up @@ -1049,6 +1052,7 @@ public Policy<K, V> policy() {
return (policy == null) ? (policy = new UnboundedPolicy<>(cache.isRecordingStats)) : policy;
}

@SuppressWarnings("UnusedVariable")
private void readObject(ObjectInputStream stream) throws InvalidObjectException {
throw new InvalidObjectException("Proxy required");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,7 @@ public void containsKey(Map<Integer, Integer> 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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Long, Long> cache, CacheContext context) {
public void testCache(Cache<Long, Long> cache, CacheContext context) {
for (long j = 0; j < 300; ++j) {
cache.get(1L, Function.identity());
cache.get(j, Function.identity());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public void after() {
}

@Test
@SuppressWarnings("FutureReturnValueIgnored")
public void readDuringCreate() {
// Loaded value and waiting at expireAfterCreate (expire: infinite)
cache.get(key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ protected ConcurrentMap<K, V> delegate() {
return cache.asMap();
}

@SuppressWarnings("UnusedVariable")
private void readObject(ObjectInputStream stream) throws InvalidObjectException {
statsCounter = new SimpleStatsCounter();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}
}

Expand Down
4 changes: 2 additions & 2 deletions gradle/dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ private void checkNothingLogged() {
assertTrue(logHandler.getStoredLogRecords().isEmpty());
}

@SuppressWarnings("UnusedVariable")
private void checkLoggedCause(Throwable t) {
//assertSame(t, popLoggedThrowable().getCause());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 2ba24a9

Please sign in to comment.