diff --git a/server/src/main/java/org/elasticsearch/common/unit/ByteSizeValue.java b/server/src/main/java/org/elasticsearch/common/unit/ByteSizeValue.java index 5d2bb928ada..41b66539045 100644 --- a/server/src/main/java/org/elasticsearch/common/unit/ByteSizeValue.java +++ b/server/src/main/java/org/elasticsearch/common/unit/ByteSizeValue.java @@ -27,6 +27,8 @@ import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.logging.DeprecationLogger; +import org.elasticsearch.common.logging.LogConfigurator; +import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.xcontent.ToXContentFragment; import org.elasticsearch.common.xcontent.XContentBuilder; @@ -36,7 +38,14 @@ import java.util.Objects; public class ByteSizeValue implements Writeable, Comparable, ToXContentFragment { - private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(ByteSizeValue.class)); + /** + * We have to lazy initialize the deprecation logger as otherwise a static logger here would be constructed before logging is configured + * leading to a runtime failure (see {@link LogConfigurator#checkErrorListener()} ). The premature construction would come from any + * {@link Setting} object constructed in, for example, settings in {@link org.elasticsearch.common.network.NetworkService}. + */ + static class DeprecationLoggerHolder { + static DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(ByteSizeValue.class)); + } public static final ByteSizeValue ZERO = new ByteSizeValue(0, ByteSizeUnit.BYTES); @@ -237,7 +246,7 @@ public class ByteSizeValue implements Writeable, Comparable, ToXC } catch (final NumberFormatException e) { try { final double doubleValue = Double.parseDouble(s); - deprecationLogger.deprecated( + DeprecationLoggerHolder.deprecationLogger.deprecated( "Fractional bytes values are deprecated. Use non-fractional bytes values instead: [{}] found for setting [{}]", initialInput, settingName); return new ByteSizeValue((long) (doubleValue * unit.toBytes(1)));