Skip to content

Commit

Permalink
Add Coverity build scan
Browse files Browse the repository at this point in the history
Fixed minor compilation errors in their static analysis. But the plugin
assumes a commercial installation for local analysis. The open-source
portal doesn't seem to accept the emit-db due to not having a
build-log.txt file. So more debugging is required to figure out how to
integrate with Coverity Scan. Despite that, merging since the changes
were benign and we might get it working in the future.
  • Loading branch information
ben-manes committed Nov 7, 2016
1 parent 4750631 commit fe68b00
Show file tree
Hide file tree
Showing 15 changed files with 63 additions and 99 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
apply plugin: 'com.github.mjdetullio.gradle.coverity'
apply plugin: 'com.github.ben-manes.versions'
apply plugin: 'com.github.kt3k.coveralls'
apply plugin: 'jacoco'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public static long objectFieldOffset(Class<?> clazz, String fieldName) {
static Unsafe load(String openJdk, String android) throws NoSuchMethodException,
SecurityException, InstantiationException, IllegalAccessException,
IllegalArgumentException, InvocationTargetException {
Field field = null;
Field field;
try {
// try OpenJDK field name
field = Unsafe.class.getDeclaredField(openJdk);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import com.github.benmanes.caffeine.cache.Policy.Eviction;
import com.github.benmanes.caffeine.cache.Policy.Expiration;
import com.github.benmanes.caffeine.cache.stats.StatsCounter;
import com.github.benmanes.caffeine.cache.testing.FakeTicker;
import com.google.common.testing.FakeTicker;
import com.google.common.util.concurrent.MoreExecutors;

/**
Expand Down Expand Up @@ -449,7 +449,7 @@ public void ticker_twice() {

@Test
public void ticker() {
Ticker ticker = new FakeTicker();
Ticker ticker = new FakeTicker()::read;
Caffeine<?, ?> builder = Caffeine.newBuilder().ticker(ticker);
assertThat(builder.ticker, is(ticker));
builder.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.nullValue;

import java.io.Serializable;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
Expand Down Expand Up @@ -61,6 +62,7 @@
import com.google.common.base.MoreObjects;
import com.google.common.cache.CacheBuilder;
import com.google.common.collect.ImmutableSet;
import com.google.common.testing.FakeTicker;

/**
* The cache configuration context for a test case.
Expand Down Expand Up @@ -134,7 +136,7 @@ public CacheContext(InitialCapacity initialCapacity, Stats stats, CacheWeigher w
this.isAsyncLoading = isAsyncLoading;
this.writer = requireNonNull(writer);
this.cacheWriter = writer.get();
this.ticker = new FakeTicker();
this.ticker = new SerializableFakeTicker();
this.implementation = requireNonNull(implementation);
this.original = new LinkedHashMap<>();
this.initialSize = -1;
Expand Down Expand Up @@ -371,14 +373,13 @@ public FakeTicker ticker() {
}

public <K, V> LoadingCache<K, V> build(CacheLoader<K, V> loader) {
LoadingCache<K, V> cache = null;
LoadingCache<K, V> cache;
if (isCaffeine()) {
cache = isAsync() ? caffeine.buildAsync(loader).synchronous() : caffeine.build(loader);
} else {
cache = new GuavaLoadingCache<>(guava.build(
com.google.common.cache.CacheLoader.asyncReloading(
new SingleLoader<>(loader), executor)),
ticker, isRecordingStats());
new SingleLoader<>(loader), executor)), ticker, isRecordingStats());
}
this.cache = cache;
return cache;
Expand Down Expand Up @@ -440,4 +441,7 @@ public String toString() {
.add("implementation", implementation)
.toString();
}

@SuppressWarnings("serial")
static final class SerializableFakeTicker extends FakeTicker implements Serializable {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
*/
package com.github.benmanes.caffeine.cache.testing;

import java.io.Serializable;
import java.util.concurrent.TimeUnit;

import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import com.github.benmanes.caffeine.cache.RandomSeedEnforcer;
import com.github.benmanes.caffeine.cache.Ticker;
import com.github.benmanes.caffeine.cache.testing.CacheSpec.CacheExecutor;
import com.github.benmanes.caffeine.cache.testing.CacheSpec.CacheWeigher;
import com.github.benmanes.caffeine.cache.testing.CacheSpec.Expire;
Expand All @@ -34,6 +36,7 @@
* @author [email protected] (Ben Manes)
*/
public final class CaffeineCacheFromContext {
interface SerializableTicker extends Ticker, Serializable {}

private CaffeineCacheFromContext() {}

Expand Down Expand Up @@ -65,7 +68,8 @@ public static <K, V> Cache<K, V> newCaffeineCache(CacheContext context) {
builder.refreshAfterWrite(context.refresh.timeNanos(), TimeUnit.NANOSECONDS);
}
if (context.expires() || context.refreshes()) {
builder.ticker(context.ticker());
SerializableTicker ticker = context.ticker()::read;
builder.ticker(ticker);
}
if (context.keyStrength == ReferenceType.WEAK) {
builder.weakKeys();
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@
import com.github.benmanes.caffeine.cache.LoadingCache;
import com.github.benmanes.caffeine.cache.Policy;
import com.github.benmanes.caffeine.cache.RemovalCause;
import com.github.benmanes.caffeine.cache.Ticker;
import com.github.benmanes.caffeine.cache.stats.CacheStats;
import com.github.benmanes.caffeine.cache.testing.CacheSpec.CacheWeigher;
import com.github.benmanes.caffeine.cache.testing.CacheSpec.Expire;
import com.github.benmanes.caffeine.cache.testing.CacheSpec.InitialCapacity;
import com.github.benmanes.caffeine.cache.testing.CacheSpec.Listener;
import com.github.benmanes.caffeine.cache.testing.CacheSpec.Maximum;
import com.github.benmanes.caffeine.cache.testing.CacheSpec.ReferenceType;
import com.google.common.base.Ticker;
import com.google.common.cache.AbstractCache.SimpleStatsCounter;
import com.google.common.cache.AbstractCache.StatsCounter;
import com.google.common.cache.CacheBuilder;
Expand Down Expand Up @@ -113,7 +113,7 @@ public static <K, V> Cache<K, V> newGuavaCache(CacheContext context) {
builder.removalListener(new GuavaRemovalListener<>(
translateZeroExpire, context.removalListener));
}
Ticker ticker = (context.ticker == null) ? Ticker.systemTicker() : context.ticker;
Ticker ticker = (context.ticker == null) ? Ticker.systemTicker() : context.ticker();
if (context.loader == null) {
context.cache = new GuavaCache<>(builder.<Integer, Integer>build(),
ticker, context.isRecordingStats());
Expand Down
2 changes: 2 additions & 0 deletions gradle/dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ ext {
plugin_versions = [
checkstyle: '7.2',
coveralls: '2.6.3',
coverity: '1.0.10',
extra_conf: '3.1.0',
error_prone: '0.0.8',
huntbugs_core: '0.0.11',
Expand Down Expand Up @@ -164,6 +165,7 @@ ext {
transitive = false
},
coveralls: "org.kt3k.gradle.plugin:coveralls-gradle-plugin:${plugin_versions.coveralls}",
coverity: "gradle.plugin.com.github.mjdetullio.gradle:coverity-plugin:${plugin_versions.coverity}",
extra_conf: "com.netflix.nebula:gradle-extra-configurations-plugin:${plugin_versions.extra_conf}",
error_prone: "net.ltgt.gradle:gradle-errorprone-plugin:${plugin_versions.error_prone}",
huntbugs: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ private CaffeinatedGuava() {}
* @return a cache exposed under the Guava APIs
*/
@Nonnull
public static <K1 extends K, K, V1 extends V, V> Cache<K1, V1> build(
public static <K, V, K1 extends K, V1 extends V> Cache<K1, V1> build(
@Nonnull Caffeine<K, V> builder) {
return new CaffeinatedGuavaCache<>(builder.build());
}
Expand All @@ -55,7 +55,7 @@ public static <K1 extends K, K, V1 extends V, V> Cache<K1, V1> build(
* @return a cache exposed under the Guava APIs
*/
@Nonnull
public static <K1 extends K, K, V1 extends V, V> LoadingCache<K1, V1> build(
public static <K, V, K1 extends K, V1 extends V> LoadingCache<K1, V1> build(
@Nonnull Caffeine<K, V> builder, @Nonnull CacheLoader<? super K1, V1> loader) {
@SuppressWarnings("unchecked")
CacheLoader<K1, V1> castedLoader = (CacheLoader<K1, V1>) loader;
Expand All @@ -72,7 +72,7 @@ public static <K1 extends K, K, V1 extends V, V> LoadingCache<K1, V1> build(
* @return a cache exposed under the Guava APIs
*/
@Nonnull
public static <K1 extends K, K, V1 extends V, V> LoadingCache<K1, V1> build(
public static <K, V, K1 extends K, V1 extends V> LoadingCache<K1, V1> build(
@Nonnull Caffeine<K, V> builder,
@Nonnull com.github.benmanes.caffeine.cache.CacheLoader<? super K1, V1> loader) {
return new CaffeinatedGuavaLoadingCache<>(builder.build(loader));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
import com.google.common.testing.FakeTicker;
import com.google.common.util.concurrent.MoreExecutors;

import junit.framework.TestCase;
Expand Down Expand Up @@ -148,7 +149,7 @@ public void testExpireAfterAccess() {
final Cache<Integer, Integer> cache = CaffeinatedGuava.build(Caffeine.newBuilder()
.expireAfterAccess(1000, TimeUnit.MILLISECONDS)
.executor(MoreExecutors.directExecutor())
.ticker(fakeTicker));
.ticker(fakeTicker::read));

cache.put(0, 10);
cache.put(2, 30);
Expand All @@ -165,7 +166,7 @@ public void testExpireAfterWrite() {
final Cache<Integer, Integer> cache = CaffeinatedGuava.build(Caffeine.newBuilder()
.expireAfterWrite(1000, TimeUnit.MILLISECONDS)
.executor(MoreExecutors.directExecutor())
.ticker(fakeTicker));
.ticker(fakeTicker::read));

cache.put(10, 100);
cache.put(20, 200);
Expand Down Expand Up @@ -193,7 +194,7 @@ public void testExpireAfterWriteAndAccess() {
.expireAfterWrite(1000, TimeUnit.MILLISECONDS)
.expireAfterAccess(500, TimeUnit.MILLISECONDS)
.executor(MoreExecutors.directExecutor())
.ticker(fakeTicker));
.ticker(fakeTicker::read));

cache.put(10, 100);
cache.put(20, 200);
Expand Down Expand Up @@ -291,7 +292,7 @@ public void onRemoval(Integer key, Integer value, RemovalCause cause) {
.executor(MoreExecutors.directExecutor())
.removalListener(countingListener)
.initialCapacity(100)
.ticker(fakeTicker)
.ticker(fakeTicker::read)
.maximumSize(2));

// Enforce full initialization of internal structures
Expand Down Expand Up @@ -390,7 +391,7 @@ public void testAsMap_containsValue() {
Cache<Integer, Integer> cache = CaffeinatedGuava.build(Caffeine.newBuilder()
.expireAfterWrite(20000, TimeUnit.MILLISECONDS)
.executor(MoreExecutors.directExecutor())
.ticker(fakeTicker));
.ticker(fakeTicker::read));

cache.put(654, 2675);
fakeTicker.advance(10000, TimeUnit.MILLISECONDS);
Expand All @@ -408,7 +409,7 @@ public void testAsMap_containsKey() {
Cache<Integer, Integer> cache = CaffeinatedGuava.build(Caffeine.newBuilder()
.expireAfterWrite(20000, TimeUnit.MILLISECONDS)
.executor(MoreExecutors.directExecutor())
.ticker(fakeTicker));
.ticker(fakeTicker::read));

cache.put(654, 2675);
fakeTicker.advance(10000, TimeUnit.MILLISECONDS);
Expand All @@ -426,7 +427,7 @@ public void testAsMapValues_contains() {
Cache<Integer, Integer> cache = CaffeinatedGuava.build(Caffeine.newBuilder()
.expireAfterWrite(1000, TimeUnit.MILLISECONDS)
.executor(MoreExecutors.directExecutor())
.ticker(fakeTicker));
.ticker(fakeTicker::read));

cache.put(10, 20);
fakeTicker.advance(500, TimeUnit.MILLISECONDS);
Expand All @@ -444,7 +445,7 @@ public void testAsMapKeySet() {
Cache<Integer, Integer> cache = CaffeinatedGuava.build(Caffeine.newBuilder()
.expireAfterWrite(1000, TimeUnit.MILLISECONDS)
.executor(MoreExecutors.directExecutor())
.ticker(fakeTicker));
.ticker(fakeTicker::read));

cache.put(10, 20);
fakeTicker.advance(500, TimeUnit.MILLISECONDS);
Expand All @@ -466,7 +467,7 @@ public void testAsMapKeySet_contains() {
Cache<Integer, Integer> cache = CaffeinatedGuava.build(Caffeine.newBuilder()
.expireAfterWrite(1000, TimeUnit.MILLISECONDS)
.executor(MoreExecutors.directExecutor())
.ticker(fakeTicker));
.ticker(fakeTicker::read));

cache.put(10, 20);
fakeTicker.advance(500, TimeUnit.MILLISECONDS);
Expand All @@ -484,7 +485,7 @@ public void testAsMapEntrySet() {
Cache<Integer, Integer> cache = CaffeinatedGuava.build(Caffeine.newBuilder()
.expireAfterWrite(1000, TimeUnit.MILLISECONDS)
.executor(MoreExecutors.directExecutor())
.ticker(fakeTicker));
.ticker(fakeTicker::read));

cache.put(10, 20);
fakeTicker.advance(500, TimeUnit.MILLISECONDS);
Expand All @@ -504,7 +505,7 @@ public void testAsMapValues_iteratorRemove() {
Cache<Integer, Integer> cache = CaffeinatedGuava.build(Caffeine.newBuilder()
.expireAfterWrite(1000, TimeUnit.MILLISECONDS)
.executor(MoreExecutors.directExecutor())
.ticker(fakeTicker));
.ticker(fakeTicker::read));

cache.put(10, 20);
Iterator<Integer> iterator = cache.asMap().values().iterator();
Expand Down
Loading

0 comments on commit fe68b00

Please sign in to comment.