Skip to content

Commit

Permalink
Remove non-null type argument (fixes #530)
Browse files Browse the repository at this point in the history
Checkstyle interprets this as defaulting the type to non-null, but will
also do that implicitly on a raw `extends Object`.

IntelliJ Idea interprets the generic type annotation as requiring that
the type itself is non-nullable, e.g. `String` versus `String?`. This
cannot be expressed in Java, so the warning is impossible to resolve
and can only be suppressed.

As the type argument adds no additional benefit for Checkstyles,
removing may make the signature look odd but better declairs the
intent.
  • Loading branch information
ben-manes committed Apr 10, 2021
1 parent 27163d0 commit 988e2ee
Show file tree
Hide file tree
Showing 16 changed files with 27 additions and 40 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -126,7 +126,7 @@ Snapshots of the development version are available in
[hbase]: https://hbase.apache.org
[cassandra]: http://cassandra.apache.org
[solr]: https://lucene.apache.org/solr
[infinispan]: http://infinispan.org/docs/stable/user_guide/user_guide.html#eviction_strategy
[infinispan]: https://infinispan.org
[neo4j]: https://github.com/neo4j/neo4j
[finagle]: https://github.com/twitter/finagle
[druid]: https://druid.apache.org/docs/latest/configuration/index.html#cache-configuration
Expand Down
Expand Up @@ -15,15 +15,14 @@
*/
package com.github.benmanes.caffeine.cache;

import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;

/**
* A facade for benchmark implementations.
*
* @author ben.manes@gmail.com (Ben Manes)
*/
public interface BasicCache<K extends @NonNull Object, V extends @NonNull Object> {
public interface BasicCache<K extends Object, V extends Object> {

/** Returns the value stored in the cache, or null if not present. */
@Nullable V get(K key);
Expand Down
Expand Up @@ -23,7 +23,6 @@
import java.util.function.BiFunction;
import java.util.function.Function;

import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;

import com.google.errorprone.annotations.CheckReturnValue;
Expand All @@ -40,7 +39,7 @@
* @param <K> the type of keys maintained by this cache
* @param <V> the type of mapped values
*/
public interface AsyncCache<K extends @NonNull Object, V extends @NonNull Object> {
public interface AsyncCache<K extends Object, V extends Object> {

/**
* Returns the future associated with {@code key} in this cache, or {@code null} if there is no
Expand Down
Expand Up @@ -24,8 +24,6 @@
import java.util.function.BiFunction;
import java.util.function.Function;

import org.checkerframework.checker.nullness.qual.NonNull;

import com.google.errorprone.annotations.CheckReturnValue;

/**
Expand All @@ -46,7 +44,7 @@
*/
@FunctionalInterface
@SuppressWarnings("PMD.SignatureDeclareThrowsException")
public interface AsyncCacheLoader<K extends @NonNull Object, V extends @NonNull Object> {
public interface AsyncCacheLoader<K extends Object, V extends Object> {

/**
* Asynchronously computes or retrieves the value corresponding to {@code key}.
Expand Down
Expand Up @@ -18,8 +18,6 @@
import java.util.Map;
import java.util.concurrent.CompletableFuture;

import org.checkerframework.checker.nullness.qual.NonNull;

import com.google.errorprone.annotations.CheckReturnValue;

/**
Expand All @@ -33,7 +31,7 @@
* @param <K> the type of keys maintained by this cache
* @param <V> the type of mapped values
*/
public interface AsyncLoadingCache<K extends @NonNull Object, V extends @NonNull Object>
public interface AsyncLoadingCache<K extends Object, V extends Object>
extends AsyncCache<K, V> {

/**
Expand Down
Expand Up @@ -21,7 +21,6 @@
import java.util.function.Function;

import org.checkerframework.checker.index.qual.NonNegative;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.checkerframework.checker.nullness.qual.PolyNull;

Expand All @@ -40,7 +39,7 @@
* @param <K> the type of keys maintained by this cache
* @param <V> the type of mapped values
*/
public interface Cache<K extends @NonNull Object, V extends @NonNull Object> {
public interface Cache<K extends Object, V extends Object> {

/**
* Returns the value associated with the {@code key} in this cache, or {@code null} if there is no
Expand Down
Expand Up @@ -24,7 +24,6 @@
import java.util.concurrent.Executor;
import java.util.function.Function;

import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;

import com.google.errorprone.annotations.CheckReturnValue;
Expand All @@ -46,8 +45,7 @@
*/
@FunctionalInterface
@SuppressWarnings({"PMD.SignatureDeclareThrowsException", "FunctionalInterfaceMethodChanged"})
public interface CacheLoader<K extends @NonNull Object, V extends @NonNull Object>
extends AsyncCacheLoader<K, V> {
public interface CacheLoader<K extends Object, V extends Object> extends AsyncCacheLoader<K, V> {

/**
* Computes or retrieves the value corresponding to {@code key}.
Expand Down
Expand Up @@ -36,7 +36,6 @@
import java.util.function.Supplier;

import org.checkerframework.checker.index.qual.NonNegative;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;

import com.github.benmanes.caffeine.cache.Async.AsyncEvictionListener;
Expand Down Expand Up @@ -137,7 +136,7 @@
* normally {@code Object} unless it is constrained by using a method like {@code
* #removalListener}
*/
public final class Caffeine<K extends @NonNull Object, V extends @NonNull Object> {
public final class Caffeine<K extends Object, V extends Object> {
static final Logger logger = System.getLogger(Caffeine.class.getName());
static final Supplier<StatsCounter> ENABLED_STATS_COUNTER_SUPPLIER = ConcurrentStatsCounter::new;

Expand Down
Expand Up @@ -16,15 +16,14 @@
package com.github.benmanes.caffeine.cache;

import org.checkerframework.checker.index.qual.NonNegative;
import org.checkerframework.checker.nullness.qual.NonNull;

/**
* Calculates when cache entries expire. A single expiration time is retained so that the lifetime
* of an entry may be extended or reduced by subsequent evaluations.
*
* @author ben.manes@gmail.com (Ben Manes)
*/
public interface Expiry<K extends @NonNull Object, V extends @NonNull Object> {
public interface Expiry<K extends Object, V extends Object> {

/**
* Specifies that the entry should be automatically removed from the cache once the duration has
Expand Down
Expand Up @@ -19,7 +19,6 @@
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionException;

import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;

/**
Expand All @@ -33,8 +32,7 @@
* @param <K> the type of keys maintained by this cache
* @param <V> the type of mapped values
*/
public interface LoadingCache<K extends @NonNull Object, V extends @NonNull Object>
extends Cache<K, V> {
public interface LoadingCache<K extends Object, V extends Object> extends Cache<K, V> {

/**
* Returns the value associated with the {@code key} in this cache, obtaining that value from
Expand Down
Expand Up @@ -24,7 +24,6 @@
import java.util.concurrent.TimeUnit;

import org.checkerframework.checker.index.qual.NonNegative;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;

/**
Expand All @@ -34,7 +33,7 @@
*
* @author ben.manes@gmail.com (Ben Manes)
*/
public interface Policy<K extends @NonNull Object, V extends @NonNull Object> {
public interface Policy<K extends Object, V extends Object> {

/**
* Returns whether the cache statistics are being accumulated.
Expand Down Expand Up @@ -127,7 +126,7 @@ public interface Policy<K extends @NonNull Object, V extends @NonNull Object> {
Optional<FixedRefresh<K, V>> refreshAfterWrite();

/** The low-level operations for a cache with a size-based eviction policy. */
interface Eviction<K extends @NonNull Object, V extends @NonNull Object> {
interface Eviction<K extends Object, V extends Object> {

/**
* Returns whether the cache is bounded by a maximum size or maximum weight.
Expand Down Expand Up @@ -211,7 +210,7 @@ interface Eviction<K extends @NonNull Object, V extends @NonNull Object> {
}

/** The low-level operations for a cache with a fixed expiration policy. */
interface FixedExpiration<K extends @NonNull Object, V extends @NonNull Object> {
interface FixedExpiration<K extends Object, V extends Object> {

/**
* Returns the age of the entry based on the expiration policy. The entry's age is the cache's
Expand Down Expand Up @@ -330,7 +329,7 @@ default void setExpiresAfter(Duration duration) {
}

/** The low-level operations for a cache with a variable expiration policy. */
interface VarExpiration<K extends @NonNull Object, V extends @NonNull Object> {
interface VarExpiration<K extends Object, V extends Object> {

/**
* Returns the duration until the entry should be automatically removed. The expiration policy
Expand Down Expand Up @@ -488,7 +487,7 @@ default void setExpiresAfter(K key, Duration duration) {
}

/** The low-level operations for a cache with a fixed refresh policy. */
interface FixedRefresh<K extends @NonNull Object, V extends @NonNull Object> {
interface FixedRefresh<K extends Object, V extends Object> {

/**
* Returns the age of the entry based on the refresh policy. The entry's age is the cache's
Expand Down
Expand Up @@ -15,7 +15,6 @@
*/
package com.github.benmanes.caffeine.cache;

import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;

/**
Expand All @@ -34,7 +33,7 @@
* {@code Object} if any value is acceptable
*/
@FunctionalInterface
public interface RemovalListener<K extends @NonNull Object, V extends @NonNull Object> {
public interface RemovalListener<K extends Object, V extends Object> {

/**
* Notifies the listener that a removal occurred at some point in the past.
Expand Down
Expand Up @@ -20,7 +20,6 @@
import java.io.Serializable;

import org.checkerframework.checker.index.qual.NonNegative;
import org.checkerframework.checker.nullness.qual.NonNull;

/**
* Calculates the weights of cache entries. The total weight threshold is used to determine when an
Expand All @@ -31,7 +30,7 @@
* @author ben.manes@gmail.com (Ben Manes)
*/
@FunctionalInterface
public interface Weigher<K extends @NonNull Object, V extends @NonNull Object> {
public interface Weigher<K extends Object, V extends Object> {

/**
* Returns the weight of a cache entry. There is no unit for entry weights; rather they are simply
Expand Down
3 changes: 3 additions & 0 deletions checksum.xml
Expand Up @@ -490,6 +490,9 @@
<dependency group='org.checkerframework' module='checkerframework-gradle-plugin' version='0.5.18'>
<sha512>F21E8EBD12D3BAAF1289485AACD4AD9E9965F40EE4D1F21833DAE92277B7DD56FFEB073E187600AB205C42221A3EAD5551A2EAD20F746F9BD497C75E59871603</sha512>
</dependency>
<dependency group='org.checkerframework' module='checkerframework-gradle-plugin' version='0.5.19'>
<sha512>12EE6B6DAB34CB3538CC415E46CC5232BD8A7F750DAAD821F25AAEDDB27450FD490DFC52D96DAAF7D7E65FB138E18BD83CF1CB4375DF1680D09B86B4E2950B20</sha512>
</dependency>
<dependency group='org.codehaus.groovy.modules.http-builder' module='http-builder' version='0.7.1'>
<sha512>BC7BC2A514F8CA104A392ECF8736F4A3D316EE988FA91299D33B0AF46134B38E14E4A5061449D17B2DF7A521643E6C02DFA37CC277ED7CAB7CE83C28C00E9719</sha512>
</dependency>
Expand Down
12 changes: 6 additions & 6 deletions gradle/dependencies.gradle
Expand Up @@ -25,7 +25,7 @@
*/
ext {
versions = [
akka: '2.6.13',
akka: '2.6.14',
cache2k: '2.1.2.Alpha',
checkerFramework: '3.12.0',
coherence: '20.06',
Expand All @@ -50,7 +50,7 @@ ext {
javapoet: '1.13.0',
jcache: '1.1.1',
jmh: '1.29',
joor: '0.9.13',
joor: '0.9.14',
jsr330: '1',
nullaway: '0.8.0',
ohc: '0.6.1',
Expand All @@ -62,7 +62,7 @@ ext {
univocityParsers: '2.9.1',
ycsb: '0.17.0',
xz: '1.9',
zstd: '1.4.9-3',
zstd: '1.4.9-4',
]
testVersions = [
awaitility: '4.0.3',
Expand All @@ -72,7 +72,7 @@ ext {
jcacheTck: '1.1.1',
jctools: '3.3.0',
junit: '4.13.2',
mockito: '3.8.0',
mockito: '3.9.0',
paxExam: '4.13.4',
testng: '7.4.0',
truth: '1.1.2',
Expand All @@ -83,7 +83,7 @@ ext {
]
pluginVersions = [
bnd: '5.3.0',
checkerFramework: '0.5.18',
checkerFramework: '0.5.19',
checkstyle: '8.41.1',
coveralls: '2.8.4',
errorprone: '2.0.1',
Expand All @@ -102,7 +102,7 @@ ext {
versions: '0.38.0',
]
annotationProcessorVersions = [
autoValue: '1.7.5',
autoValue: '1.8',
autoValueBuilder: '2.9.3',
]

Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
@@ -1,4 +1,4 @@
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0-rc-2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0-bin.zip
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
Expand Down

0 comments on commit 988e2ee

Please sign in to comment.