diff --git a/check_api/src/main/java/com/google/errorprone/dataflow/DataFlow.java b/check_api/src/main/java/com/google/errorprone/dataflow/DataFlow.java index 7cd46c97187..cd89702173c 100644 --- a/check_api/src/main/java/com/google/errorprone/dataflow/DataFlow.java +++ b/check_api/src/main/java/com/google/errorprone/dataflow/DataFlow.java @@ -16,12 +16,11 @@ package com.google.errorprone.dataflow; +import com.github.benmanes.caffeine.cache.CacheLoader; +import com.github.benmanes.caffeine.cache.Caffeine; +import com.github.benmanes.caffeine.cache.LoadingCache; import com.google.auto.value.AutoValue; import com.google.common.base.Preconditions; -import com.google.common.cache.CacheBuilder; -import com.google.common.cache.CacheLoader; -import com.google.common.cache.LoadingCache; -import com.google.common.util.concurrent.UncheckedExecutionException; import com.sun.source.tree.BlockTree; import com.sun.source.tree.ClassTree; import com.sun.source.tree.CompilationUnitTree; @@ -31,7 +30,6 @@ import com.sun.source.tree.Tree; import com.sun.source.tree.VariableTree; import com.sun.source.util.TreePath; -import com.sun.tools.javac.code.Symbol.CompletionFailure; import com.sun.tools.javac.processing.JavacProcessingEnvironment; import com.sun.tools.javac.util.Context; import javax.annotation.Nullable; @@ -73,7 +71,7 @@ public interface Result< * TODO(b/158869538): Write a test that checks these assumptions */ private static final LoadingCache> analysisCache = - CacheBuilder.newBuilder() + Caffeine.newBuilder() .build( new CacheLoader>() { @Override @@ -89,7 +87,7 @@ public interface Result< }); private static final LoadingCache cfgCache = - CacheBuilder.newBuilder() + Caffeine.newBuilder() .maximumSize(1) .build( new CacheLoader() { @@ -171,15 +169,10 @@ private static TreePath findEnclosingMethodOrLambdaOrInitializer(TreePath pa Result methodDataflow(TreePath methodPath, Context context, T transfer) { ProcessingEnvironment env = JavacProcessingEnvironment.instance(context); - ControlFlowGraph cfg; - try { - cfg = cfgCache.getUnchecked(CfgParams.create(methodPath, env)); - } catch (UncheckedExecutionException e) { - throw e.getCause() instanceof CompletionFailure ? (CompletionFailure) e.getCause() : e; - } + ControlFlowGraph cfg = cfgCache.get(CfgParams.create(methodPath, env)); AnalysisParams aparams = AnalysisParams.create(transfer, cfg, env); @SuppressWarnings("unchecked") - Analysis analysis = (Analysis) analysisCache.getUnchecked(aparams); + Analysis analysis = (Analysis) analysisCache.get(aparams); return new Result() { @Override diff --git a/check_api/src/main/java/com/google/errorprone/dataflow/nullnesspropagation/inference/NullnessQualifierInference.java b/check_api/src/main/java/com/google/errorprone/dataflow/nullnesspropagation/inference/NullnessQualifierInference.java index 5131040944e..5c0ceb4fc18 100644 --- a/check_api/src/main/java/com/google/errorprone/dataflow/nullnesspropagation/inference/NullnessQualifierInference.java +++ b/check_api/src/main/java/com/google/errorprone/dataflow/nullnesspropagation/inference/NullnessQualifierInference.java @@ -18,16 +18,15 @@ import static com.google.common.base.Preconditions.checkArgument; +import com.github.benmanes.caffeine.cache.CacheLoader; +import com.github.benmanes.caffeine.cache.Caffeine; +import com.github.benmanes.caffeine.cache.LoadingCache; import com.google.auto.value.AutoValue; -import com.google.common.cache.CacheBuilder; -import com.google.common.cache.CacheLoader; -import com.google.common.cache.LoadingCache; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Streams; import com.google.common.graph.GraphBuilder; import com.google.common.graph.MutableGraph; -import com.google.common.util.concurrent.UncheckedExecutionException; import com.google.errorprone.dataflow.nullnesspropagation.Nullness; import com.google.errorprone.dataflow.nullnesspropagation.NullnessAnnotations; import com.sun.source.tree.ArrayAccessTree; @@ -47,7 +46,6 @@ import com.sun.source.tree.VariableTree; import com.sun.source.util.TreeScanner; import com.sun.tools.javac.code.Symbol; -import com.sun.tools.javac.code.Symbol.CompletionFailure; import com.sun.tools.javac.code.Symbol.MethodSymbol; import com.sun.tools.javac.code.Symbol.TypeVariableSymbol; import com.sun.tools.javac.code.Symbol.VarSymbol; @@ -78,7 +76,7 @@ public class NullnessQualifierInference extends TreeScanner { private static final LoadingCache inferenceCache = - CacheBuilder.newBuilder() + Caffeine.newBuilder() .maximumSize(1) .build( new CacheLoader() { @@ -99,11 +97,7 @@ public static InferredNullability getInferredNullability(Tree methodOrInitialize || methodOrInitializerOrLambda instanceof VariableTree, "Tree `%s` is not a lambda, initializer, or method.", methodOrInitializerOrLambda); - try { - return inferenceCache.getUnchecked(methodOrInitializerOrLambda); - } catch (UncheckedExecutionException e) { - throw e.getCause() instanceof CompletionFailure ? (CompletionFailure) e.getCause() : e; - } + return inferenceCache.get(methodOrInitializerOrLambda); } /**