|
@@ -26,6 +26,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;
|
|
|
|
|
@@ -35,7 +37,14 @@ import java.util.Objects;
|
|
|
|
|
|
public class ByteSizeValue implements Writeable, Comparable<ByteSizeValue>, 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);
|
|
|
|
|
@@ -227,7 +236,7 @@ public class ByteSizeValue implements Writeable, Comparable<ByteSizeValue>, 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)));
|