Skip to content

Commit

Permalink
Add work-around for google/error-prone#434
Browse files Browse the repository at this point in the history
  • Loading branch information
ben-manes committed Jul 17, 2016
1 parent 30426c4 commit 2330458
Show file tree
Hide file tree
Showing 30 changed files with 110 additions and 105 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ void generate() throws IOException {
factory = TypeSpec.classBuilder("LocalCacheFactory")
.addModifiers(Modifier.FINAL)
.addAnnotation(AnnotationSpec.builder(SuppressWarnings.class)
.addMember("value", "{$S, $S, $S}", "unchecked", "unused", "PMD")
.addMember("value", "{$S, $S, $S, $S}", "unchecked", "unused", "PMD", "MissingOverride")
.build());
addClassJavaDoc();
generateLocalCaches();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ public NodeFactoryGenerator(Path directory) {
void generate() throws IOException {
nodeFactory = TypeSpec.enumBuilder("NodeFactory")
.addAnnotation(AnnotationSpec.builder(SuppressWarnings.class)
.addMember("value", "{$S, $S, $S}", "unchecked", "GuardedByChecker", "PMD")
.addMember("value", "{$S, $S, $S, $S}", "unchecked", "PMD",
"GuardedByChecker", "MissingOverride")
.build());
addClassJavaDoc();
addNodeStateStatics();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ protected final MethodSpec newGetter(Strength strength, TypeName varType,
.returns(varType);
String type;
if (varType.isPrimitive()) {
type = (varType == TypeName.INT) ? "Int" : "Long";
type = varType.equals(TypeName.INT) ? "Int" : "Long";
} else {
type = "Object";
}
Expand Down Expand Up @@ -113,7 +113,7 @@ protected final MethodSpec newSetter(TypeName varType, String varName, Visibilit
String methodName = "set" + Character.toUpperCase(varName.charAt(0)) + varName.substring(1);
String type;
if (varType.isPrimitive()) {
type = (varType == TypeName.INT) ? "Int" : "Long";
type = varType.equals(TypeName.INT) ? "Int" : "Long";
} else {
type = "Object";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
* <li>When an entry is evicted from the cache, {@code evictionCount} is incremented and the
* weight added to {@code evictionWeight}.
* <li>No stats are modified when a cache entry is invalidated or manually removed.
* <li>No stats are modified on a query to {@link Cache#getIfPresent}.
* <li>No stats are modified by non-computing operations invoked on the
* {@linkplain Cache#asMap asMap} view of the cache.
* </ul>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1373,6 +1373,7 @@ public void equals_null(Map<Integer, Integer> map, CacheContext context) {

@CheckNoWriter @CheckNoStats
@Test(dataProvider = "caches")
@SuppressWarnings("SelfEquals")
@CacheSpec(removalListener = { Listener.DEFAULT, Listener.REJECTING })
public void equals_self(Map<Integer, Integer> map, CacheContext context) {
assertThat(map.equals(map), is(true));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.nullValue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;

Expand All @@ -40,7 +41,6 @@
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

import org.mockito.Matchers;
import org.mockito.Mockito;
import org.testng.annotations.Listeners;
import org.testng.annotations.Test;
Expand Down Expand Up @@ -117,8 +117,8 @@ public void scheduleDrainBuffers() {
cache.scheduleDrainBuffers();
assertThat(cache.drainStatus, is(end));

if (start != end) {
Mockito.verify(executor).execute(Matchers.any());
if (!start.equals(end)) {
Mockito.verify(executor).execute(any());
Mockito.reset(executor);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public void async_concurrent_bounded(
Threads.runTest(cache, asyncOperations);
}

@SuppressWarnings({"unchecked", "rawtypes", "SizeGreaterThanOrEqualsZero"})
@SuppressWarnings({"unchecked", "rawtypes", "SizeGreaterThanOrEqualsZero", "SelfEquals"})
List<BiConsumer<LoadingCache<Integer, Integer>, Integer>> operations = ImmutableList.of(
// LoadingCache
(cache, key) -> cache.get(key),
Expand Down Expand Up @@ -142,7 +142,7 @@ public void async_concurrent_bounded(
(cache, key) -> cache.asMap().values().toArray(new Object[cache.asMap().size()]),
(cache, key) -> cache.asMap().entrySet().toArray(new Entry[cache.asMap().size()]),
(cache, key) -> cache.hashCode(),
(cache, key) -> cache.equals(cache),
(cache, key) -> { cache.equals(cache); },
(cache, key) -> cache.toString(),
(cache, key) -> { // expensive so do it less frequently
int random = ThreadLocalRandom.current().nextInt();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
* @author [email protected] (Ben Manes)
*/
@Listeners(CacheValidationListener.class)
@SuppressWarnings("BoxedPrimitiveConstructor")
@Test(groups = "slow", dataProviderClass = CacheProvider.class)
public final class ReferenceTest {
// These tests require that the JVM uses -XX:SoftRefLRUPolicyMSPerMB=0 so that soft references
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.anyLong;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ public <K, V> LoadingCache<K, V> build(CacheLoader<K, V> loader) {
cache = new GuavaLoadingCache<>(guava.build(
com.google.common.cache.CacheLoader.asyncReloading(
new SingleLoader<>(loader), executor.delegate())),
ticker(), isRecordingStats());
ticker, isRecordingStats());
}
this.cache = cache;
return cache;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ public static <K, V> Cache<K, V> newCache(CacheContext context) {
}

/** Fills the cache up to the population size. */
@SuppressWarnings("unchecked")
@SuppressWarnings({"unchecked", "BoxedPrimitiveConstructor"})
private void populate(CacheContext context, Cache<Integer, Integer> cache) {
if (context.population.size() == 0) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
package com.github.benmanes.caffeine.cache.testing;

import static java.util.Objects.requireNonNull;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;

Expand Down
22 changes: 11 additions & 11 deletions gradle/dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ ext {
commons_compress: '1.12',
commons_lang3: '3.4',
config: '1.3.0',
error_prone_annotations: '2.0.9',
error_prone_annotations: '2.0.10',
flip_tables: '1.0.2',
guava: '19.0',
javapoet: '1.7.0',
jcache: '1.0.0',
jsr305: '3.0.1',
stream: '2.9.3',
stream: '2.9.4',
univocity_parsers: '2.1.2',
ycsb: '0.10.0-RC1',
ycsb: '0.10.0',
xz: '1.5',
]
test_versions = [
Expand All @@ -47,7 +47,7 @@ ext {
jcache_tck: '1.0.1',
jctools: '1.2.1',
junit: '4.12',
mockito: '2.0.71-beta',
mockito: '2.0.86-beta',
pax_exam: '4.9.1',
testng: '6.9.12',
truth: '0.24',
Expand All @@ -56,18 +56,18 @@ ext {
cache2k: '0.26-BETA',
concurrentlinkedhashmap: '1.4.2',
ehcache2: '2.10.2.2.21',
ehcache3: '3.0.2',
elastic_search: '5.0.0-alpha3',
infinispan: '9.0.0.Alpha2',
jackrabbit: '1.5.3',
ehcache3: '3.1.0',
elastic_search: '5.0.0-alpha4',
infinispan: '9.0.0.Alpha3',
jackrabbit: '1.5.5',
jamm: '0.3.1',
java_object_layout: '0.5',
koloboke: '0.6.8',
slf4j: '1.7.21',
tcache: '0.9.0',
tcache: '0.9.4',
]
plugin_versions = [
checkstyle: '6.19',
checkstyle: '7.0',
coveralls: '2.6.3',
extra_conf: '3.1.0',
error_prone: '0.0.8',
Expand All @@ -77,7 +77,7 @@ ext {
semantic_versioning: '1.1.0',
shadow: '1.2.3',
stats: '0.2.0',
versions: '0.12.0',
versions: '0.13.0',
]

libraries = [
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Fri Aug 28 14:05:59 PDT 2015
#Fri Jul 15 22:30:08 PDT 2016
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-rc-2-bin.zip
46 changes: 25 additions & 21 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,30 @@
##
##############################################################################

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS="-noverify"
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null

APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"

Expand All @@ -30,6 +48,7 @@ die ( ) {
cygwin=false
msys=false
darwin=false
nonstop=false
case "`uname`" in
CYGWIN* )
cygwin=true
Expand All @@ -40,26 +59,11 @@ case "`uname`" in
MINGW* )
msys=true
;;
NONSTOP* )
nonstop=true
;;
esac

# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >&-
APP_HOME="`pwd -P`"
cd "$SAVED" >&-

CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar

# Determine the Java command to use to start the JVM.
Expand All @@ -85,7 +89,7 @@ location of your Java installation."
fi

# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
Expand Down
8 changes: 4 additions & 4 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal

@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS=

set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS=

@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome

Expand Down Expand Up @@ -46,7 +46,7 @@ echo location of your Java installation.
goto fail

:init
@rem Get command-line arguments, handling Windowz variants
@rem Get command-line arguments, handling Windows variants

if not "%OS%" == "Windows_NT" goto win9xME_args
if "%@eval[2+2]" == "4" goto 4NT_args
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
*
* @author Charles Fry
*/
@SuppressWarnings("JUnit3FloatingPointComparisonWithoutDelta")
public class CacheStatsTest extends TestCase {

public void testEmpty() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
/**
* @author Charles Fry
*/
@SuppressWarnings("JUnit3FloatingPointComparisonWithoutDelta")
public class LocalLoadingCacheTest extends TestCase {

private static <K, V> LoadingCache<K, V> makeCache(
Expand Down
10 changes: 5 additions & 5 deletions guava/src/test/java/jsr166/ConcurrentHashMapTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
import java.util.Set;
import java.util.concurrent.ConcurrentMap;

import com.github.benmanes.caffeine.cache.Caffeine;

import junit.framework.Test;
import junit.framework.TestSuite;

import com.github.benmanes.caffeine.cache.Caffeine;

@SuppressWarnings({"rawtypes", "unchecked"})
public class ConcurrentHashMapTest extends JSR166TestCase {
public static void main(String[] args) {
Expand Down Expand Up @@ -674,16 +674,16 @@ public void testSetValueWriteThrough() {
ConcurrentMap map = map();
assertTrue(map.isEmpty());
for (int i = 0; i < 20; i++) {
map.put(new Integer(i), new Integer(i));
map.put(i, i);
}
assertFalse(map.isEmpty());
Map.Entry entry1 = (Map.Entry)map.entrySet().iterator().next();
// Unless it happens to be first (in which case remainder of
// test is skipped), remove a possibly-colliding key from map
// which, under some implementations, may cause entry1 to be
// cloned in map
if (!entry1.getKey().equals(new Integer(16))) {
map.remove(new Integer(16));
if (!entry1.getKey().equals(16)) {
map.remove(16);
entry1.setValue("XYZ");
assertTrue(map.containsValue("XYZ")); // fails if write-through broken
}
Expand Down
Loading

0 comments on commit 2330458

Please sign in to comment.