Skip to content

Commit a667c38

Browse files
cpovirkGoogle Java Core Libraries
authored and
Google Java Core Libraries
committedJun 21, 2023
Partial rollback of cl/441881361 to fix #6565
Fixes #6565 RELNOTES=`cache`: Fixed `BootstrapMethodError` when [using `CacheBuilder` from a custom system class loader](#6565). PiperOrigin-RevId: 542257300
1 parent 36e7fcf commit a667c38

File tree

2 files changed

+32
-14
lines changed

2 files changed

+32
-14
lines changed
 

‎android/guava/src/com/google/common/cache/CacheBuilder.java

+16-7
Original file line numberDiff line numberDiff line change
@@ -228,15 +228,24 @@ public CacheStats snapshot() {
228228
static final CacheStats EMPTY_STATS = new CacheStats(0, 0, 0, 0, 0, 0);
229229

230230
/*
231-
* We avoid using a method reference here for now: Inside Google, CacheBuilder is used from the
232-
* implementation of a custom ClassLoader that is sometimes used as a system classloader. That's a
233-
* problem because method-reference linking tries to look up the system classloader, and it fails
234-
* because there isn't one yet.
231+
* We avoid using a method reference or lambda here for now:
235232
*
236-
* I would have guessed that a lambda would produce the same problem, but maybe it's safe because
237-
* the lambda implementation is generated as a method in the _same class_ as the usage?
233+
* - method reference: Inside Google, CacheBuilder is used from the implementation of a custom
234+
* ClassLoader that is sometimes used as a system classloader. That's a problem because
235+
* method-reference linking tries to look up the system classloader, and it fails because there
236+
* isn't one yet.
237+
*
238+
* - lambda: Outside Google, we got a report of a similar problem in
239+
* https://github.com/google/guava/issues/6565
238240
*/
239-
static final Supplier<StatsCounter> CACHE_STATS_COUNTER = () -> new SimpleStatsCounter();
241+
@SuppressWarnings("AnonymousToLambda")
242+
static final Supplier<StatsCounter> CACHE_STATS_COUNTER =
243+
new Supplier<StatsCounter>() {
244+
@Override
245+
public StatsCounter get() {
246+
return new SimpleStatsCounter();
247+
}
248+
};
240249

241250
enum NullListener implements RemovalListener<Object, Object> {
242251
INSTANCE;

‎guava/src/com/google/common/cache/CacheBuilder.java

+16-7
Original file line numberDiff line numberDiff line change
@@ -229,15 +229,24 @@ public CacheStats snapshot() {
229229
static final CacheStats EMPTY_STATS = new CacheStats(0, 0, 0, 0, 0, 0);
230230

231231
/*
232-
* We avoid using a method reference here for now: Inside Google, CacheBuilder is used from the
233-
* implementation of a custom ClassLoader that is sometimes used as a system classloader. That's a
234-
* problem because method-reference linking tries to look up the system classloader, and it fails
235-
* because there isn't one yet.
232+
* We avoid using a method reference or lambda here for now:
236233
*
237-
* I would have guessed that a lambda would produce the same problem, but maybe it's safe because
238-
* the lambda implementation is generated as a method in the _same class_ as the usage?
234+
* - method reference: Inside Google, CacheBuilder is used from the implementation of a custom
235+
* ClassLoader that is sometimes used as a system classloader. That's a problem because
236+
* method-reference linking tries to look up the system classloader, and it fails because there
237+
* isn't one yet.
238+
*
239+
* - lambda: Outside Google, we got a report of a similar problem in
240+
* https://github.com/google/guava/issues/6565
239241
*/
240-
static final Supplier<StatsCounter> CACHE_STATS_COUNTER = () -> new SimpleStatsCounter();
242+
@SuppressWarnings("AnonymousToLambda")
243+
static final Supplier<StatsCounter> CACHE_STATS_COUNTER =
244+
new Supplier<StatsCounter>() {
245+
@Override
246+
public StatsCounter get() {
247+
return new SimpleStatsCounter();
248+
}
249+
};
241250

242251
enum NullListener implements RemovalListener<Object, Object> {
243252
INSTANCE;

0 commit comments

Comments
 (0)