diff --git a/android/guava/src/com/google/common/cache/CacheBuilder.java b/android/guava/src/com/google/common/cache/CacheBuilder.java index 69b095d7e307..5d21c5b1833f 100644 --- a/android/guava/src/com/google/common/cache/CacheBuilder.java +++ b/android/guava/src/com/google/common/cache/CacheBuilder.java @@ -271,7 +271,10 @@ public long read() { } }; - private static final Logger logger = Logger.getLogger(CacheBuilder.class.getName()); + // We use a holder class to delay initialization: https://github.com/google/guava/issues/6566 + private static final class LoggerHolder { + static final Logger logger = Logger.getLogger(CacheBuilder.class.getName()); + } static final int UNSET_INT = -1; @@ -950,7 +953,8 @@ private void checkWeightWithWeigher() { checkState(maximumWeight != UNSET_INT, "weigher requires maximumWeight"); } else { if (maximumWeight == UNSET_INT) { - logger.log(Level.WARNING, "ignoring weigher specified without maximumWeight"); + LoggerHolder.logger.log( + Level.WARNING, "ignoring weigher specified without maximumWeight"); } } } diff --git a/guava/src/com/google/common/cache/CacheBuilder.java b/guava/src/com/google/common/cache/CacheBuilder.java index 6e6458651397..bbb2b185b5f5 100644 --- a/guava/src/com/google/common/cache/CacheBuilder.java +++ b/guava/src/com/google/common/cache/CacheBuilder.java @@ -272,7 +272,10 @@ public long read() { } }; - private static final Logger logger = Logger.getLogger(CacheBuilder.class.getName()); + // We use a holder class to delay initialization: https://github.com/google/guava/issues/6566 + private static final class LoggerHolder { + static final Logger logger = Logger.getLogger(CacheBuilder.class.getName()); + } static final int UNSET_INT = -1; @@ -1056,7 +1059,8 @@ private void checkWeightWithWeigher() { checkState(maximumWeight != UNSET_INT, "weigher requires maximumWeight"); } else { if (maximumWeight == UNSET_INT) { - logger.log(Level.WARNING, "ignoring weigher specified without maximumWeight"); + LoggerHolder.logger.log( + Level.WARNING, "ignoring weigher specified without maximumWeight"); } } }