Skip to content

Commit

Permalink
Partial rollback of cl/441881361 to fix #6565
Browse files Browse the repository at this point in the history
Fixes #6565

RELNOTES=`cache`: Fixed `BootstrapMethodError` when [using `CacheBuilder` from a custom system class loader](#6565).
PiperOrigin-RevId: 542257300
  • Loading branch information
cpovirk authored and Google Java Core Libraries committed Jun 21, 2023
1 parent 36e7fcf commit a667c38
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 14 deletions.
23 changes: 16 additions & 7 deletions android/guava/src/com/google/common/cache/CacheBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<StatsCounter> CACHE_STATS_COUNTER = () -> new SimpleStatsCounter();
@SuppressWarnings("AnonymousToLambda")
static final Supplier<StatsCounter> CACHE_STATS_COUNTER =
new Supplier<StatsCounter>() {
@Override
public StatsCounter get() {
return new SimpleStatsCounter();
}
};

enum NullListener implements RemovalListener<Object, Object> {
INSTANCE;
Expand Down
23 changes: 16 additions & 7 deletions guava/src/com/google/common/cache/CacheBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<StatsCounter> CACHE_STATS_COUNTER = () -> new SimpleStatsCounter();
@SuppressWarnings("AnonymousToLambda")
static final Supplier<StatsCounter> CACHE_STATS_COUNTER =
new Supplier<StatsCounter>() {
@Override
public StatsCounter get() {
return new SimpleStatsCounter();
}
};

enum NullListener implements RemovalListener<Object, Object> {
INSTANCE;
Expand Down

0 comments on commit a667c38

Please sign in to comment.