From a5c5f7ee950f4bcda447651e63ff58418d031843 Mon Sep 17 00:00:00 2001 From: cpovirk Date: Tue, 20 Jun 2023 08:19:26 -0700 Subject: [PATCH] Partial rollback of cl/441881361 to fix https://github.com/google/guava/issues/6565 Fixes https://github.com/google/guava/pull/6565 RELNOTES=`cache`: Fixed `BootstrapMethodError` when [using `CacheBuilder` from a custom system class loader](https://github.com/google/guava/issues/6565). PiperOrigin-RevId: 541928922 --- .../com/google/common/cache/CacheBuilder.java | 23 +++++++++++++------ .../com/google/common/cache/CacheBuilder.java | 23 +++++++++++++------ 2 files changed, 32 insertions(+), 14 deletions(-) diff --git a/android/guava/src/com/google/common/cache/CacheBuilder.java b/android/guava/src/com/google/common/cache/CacheBuilder.java index f52243e4d4ff..69b095d7e307 100644 --- a/android/guava/src/com/google/common/cache/CacheBuilder.java +++ b/android/guava/src/com/google/common/cache/CacheBuilder.java @@ -228,15 +228,24 @@ public CacheStats snapshot() { static final CacheStats EMPTY_STATS = new CacheStats(0, 0, 0, 0, 0, 0); /* - * We avoid using a method reference here for now: Inside Google, CacheBuilder is used from the - * implementation of a custom ClassLoader that is sometimes used as a system classloader. That's a - * problem because method-reference linking tries to look up the system classloader, and it fails - * because there isn't one yet. + * We avoid using a method reference or lambda here for now: * - * I would have guessed that a lambda would produce the same problem, but maybe it's safe because - * the lambda implementation is generated as a method in the _same class_ as the usage? + * - method reference: Inside Google, CacheBuilder is used from the implementation of a custom + * ClassLoader that is sometimes used as a system classloader. That's a problem because + * method-reference linking tries to look up the system classloader, and it fails because there + * isn't one yet. + * + * - lambda: Outside Google, we got a report of a similar problem in + * https://github.com/google/guava/issues/6565 */ - static final Supplier CACHE_STATS_COUNTER = () -> new SimpleStatsCounter(); + @SuppressWarnings("AnonymousToLambda") + static final Supplier CACHE_STATS_COUNTER = + new Supplier() { + @Override + public StatsCounter get() { + return new SimpleStatsCounter(); + } + }; enum NullListener implements RemovalListener { INSTANCE; diff --git a/guava/src/com/google/common/cache/CacheBuilder.java b/guava/src/com/google/common/cache/CacheBuilder.java index 35e9196e12ac..6e6458651397 100644 --- a/guava/src/com/google/common/cache/CacheBuilder.java +++ b/guava/src/com/google/common/cache/CacheBuilder.java @@ -229,15 +229,24 @@ public CacheStats snapshot() { static final CacheStats EMPTY_STATS = new CacheStats(0, 0, 0, 0, 0, 0); /* - * We avoid using a method reference here for now: Inside Google, CacheBuilder is used from the - * implementation of a custom ClassLoader that is sometimes used as a system classloader. That's a - * problem because method-reference linking tries to look up the system classloader, and it fails - * because there isn't one yet. + * We avoid using a method reference or lambda here for now: * - * I would have guessed that a lambda would produce the same problem, but maybe it's safe because - * the lambda implementation is generated as a method in the _same class_ as the usage? + * - method reference: Inside Google, CacheBuilder is used from the implementation of a custom + * ClassLoader that is sometimes used as a system classloader. That's a problem because + * method-reference linking tries to look up the system classloader, and it fails because there + * isn't one yet. + * + * - lambda: Outside Google, we got a report of a similar problem in + * https://github.com/google/guava/issues/6565 */ - static final Supplier CACHE_STATS_COUNTER = () -> new SimpleStatsCounter(); + @SuppressWarnings("AnonymousToLambda") + static final Supplier CACHE_STATS_COUNTER = + new Supplier() { + @Override + public StatsCounter get() { + return new SimpleStatsCounter(); + } + }; enum NullListener implements RemovalListener { INSTANCE;