From 9b10c116f35d135bc16b1b5510a68aadaa2c3da9 Mon Sep 17 00:00:00 2001 From: jianglai Date: Fri, 2 Nov 2018 14:18:48 -0700 Subject: [PATCH] Do not create a logger during initialization in CidrAddressBlock This is patched from [] We should have done this when we migrated to Flogger. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=219860046 --- java/google/registry/util/CidrAddressBlock.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/java/google/registry/util/CidrAddressBlock.java b/java/google/registry/util/CidrAddressBlock.java index 0737aa8d9..8323fcb97 100644 --- a/java/google/registry/util/CidrAddressBlock.java +++ b/java/google/registry/util/CidrAddressBlock.java @@ -41,7 +41,16 @@ import javax.annotation.Nullable; // TODO(b/21870796): Migrate to Guava version when this is open-sourced. public class CidrAddressBlock implements Iterable, Serializable { - private static final FluentLogger logger = FluentLogger.forEnclosingClass(); + /** + * Wrapper class around a logger instance for {@link CidrAddressBlock}. + * + *

We don't want to have a static instance of {@link Logger} in {@link CidrAddressBlock}, + * because that can cause a race condition, since the logging subsystem might not yet be + * initialized. With this wrapper, the {@link Logger} will be initialized on first use. + */ + static class CidrAddressBlockLogger { + private static final FluentLogger logger = FluentLogger.forEnclosingClass(); + } private final InetAddress ip; @@ -343,7 +352,7 @@ public class CidrAddressBlock implements Iterable, Serializable { // not have been created with an invalid netmask and a valid // netmask should have been successfully applied to "ipAddr" as long // as it represents an address of the same family as "this.ip". - logger.atWarning().withCause(e).log("Error while applying netmask."); + CidrAddressBlockLogger.logger.atWarning().withCause(e).log("Error while applying netmask."); return false; } }