Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delay initializing the CacheBuilder logger until it is needed. #6580

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions android/guava/src/com/google/common/cache/CacheBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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");
}
}
}
Expand Down
8 changes: 6 additions & 2 deletions guava/src/com/google/common/cache/CacheBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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");
}
}
}
Expand Down