diff --git a/core/src/main/java/org/elasticsearch/common/settings/loader/JsonSettingsLoader.java b/core/src/main/java/org/elasticsearch/common/settings/loader/JsonSettingsLoader.java index 29a20e6a7ab..02f7a5c37a0 100644 --- a/core/src/main/java/org/elasticsearch/common/settings/loader/JsonSettingsLoader.java +++ b/core/src/main/java/org/elasticsearch/common/settings/loader/JsonSettingsLoader.java @@ -27,8 +27,8 @@ import org.elasticsearch.common.xcontent.XContentType; */ public class JsonSettingsLoader extends XContentSettingsLoader { - public JsonSettingsLoader(boolean guardAgainstNullValuedSettings) { - super(guardAgainstNullValuedSettings); + public JsonSettingsLoader(boolean allowNullValues) { + super(allowNullValues); } @Override diff --git a/core/src/main/java/org/elasticsearch/common/settings/loader/SettingsLoaderFactory.java b/core/src/main/java/org/elasticsearch/common/settings/loader/SettingsLoaderFactory.java index dc4240b239e..caf9d907c32 100644 --- a/core/src/main/java/org/elasticsearch/common/settings/loader/SettingsLoaderFactory.java +++ b/core/src/main/java/org/elasticsearch/common/settings/loader/SettingsLoaderFactory.java @@ -36,14 +36,14 @@ public final class SettingsLoaderFactory { */ public static SettingsLoader loaderFromResource(String resourceName) { if (resourceName.endsWith(".json")) { - return new JsonSettingsLoader(true); + return new JsonSettingsLoader(false); } else if (resourceName.endsWith(".yml") || resourceName.endsWith(".yaml")) { - return new YamlSettingsLoader(true); + return new YamlSettingsLoader(false); } else if (resourceName.endsWith(".properties")) { return new PropertiesSettingsLoader(); } else { // lets default to the json one - return new JsonSettingsLoader(true); + return new JsonSettingsLoader(false); } } @@ -52,10 +52,10 @@ public final class SettingsLoaderFactory { */ public static SettingsLoader loaderFromSource(String source) { if (source.indexOf('{') != -1 && source.indexOf('}') != -1) { - return new JsonSettingsLoader(false); + return new JsonSettingsLoader(true); } if (source.indexOf(':') != -1) { - return new YamlSettingsLoader(false); + return new YamlSettingsLoader(true); } return new PropertiesSettingsLoader(); } diff --git a/core/src/main/java/org/elasticsearch/common/settings/loader/XContentSettingsLoader.java b/core/src/main/java/org/elasticsearch/common/settings/loader/XContentSettingsLoader.java index 463dfb83f3e..3875c1ef85a 100644 --- a/core/src/main/java/org/elasticsearch/common/settings/loader/XContentSettingsLoader.java +++ b/core/src/main/java/org/elasticsearch/common/settings/loader/XContentSettingsLoader.java @@ -38,10 +38,10 @@ public abstract class XContentSettingsLoader implements SettingsLoader { public abstract XContentType contentType(); - private final boolean guardAgainstNullValuedSettings; + private final boolean allowNullValues; - XContentSettingsLoader(boolean guardAgainstNullValuedSettings) { - this.guardAgainstNullValuedSettings = guardAgainstNullValuedSettings; + XContentSettingsLoader(boolean allowNullValues) { + this.allowNullValues = allowNullValues; } @Override @@ -160,7 +160,7 @@ public abstract class XContentSettingsLoader implements SettingsLoader { ); } - if (guardAgainstNullValuedSettings && currentValue == null) { + if (currentValue == null && !allowNullValues) { throw new ElasticsearchParseException( "null-valued setting found for key [{}] found at line number [{}], column number [{}]", key, diff --git a/core/src/main/java/org/elasticsearch/common/settings/loader/YamlSettingsLoader.java b/core/src/main/java/org/elasticsearch/common/settings/loader/YamlSettingsLoader.java index 6768b00d8e4..12cde976691 100644 --- a/core/src/main/java/org/elasticsearch/common/settings/loader/YamlSettingsLoader.java +++ b/core/src/main/java/org/elasticsearch/common/settings/loader/YamlSettingsLoader.java @@ -30,8 +30,8 @@ import java.util.Map; */ public class YamlSettingsLoader extends XContentSettingsLoader { - public YamlSettingsLoader(boolean guardAgainstNullValuedSettings) { - super(guardAgainstNullValuedSettings); + public YamlSettingsLoader(boolean allowNullValues) { + super(allowNullValues); } @Override diff --git a/core/src/test/java/org/elasticsearch/common/settings/SettingsTests.java b/core/src/test/java/org/elasticsearch/common/settings/SettingsTests.java index 39dc93c3181..eb6cc56816f 100644 --- a/core/src/test/java/org/elasticsearch/common/settings/SettingsTests.java +++ b/core/src/test/java/org/elasticsearch/common/settings/SettingsTests.java @@ -201,8 +201,8 @@ public class SettingsTests extends ESTestCase { assertThat(settings.getAsArray("value"), arrayContaining("2", "3")); settings = settingsBuilder() - .put(new YamlSettingsLoader(true).load("value: 1")) - .put(new YamlSettingsLoader(true).load("value: [ 2, 3 ]")) + .put(new YamlSettingsLoader(false).load("value: 1")) + .put(new YamlSettingsLoader(false).load("value: [ 2, 3 ]")) .build(); assertThat(settings.getAsArray("value"), arrayContaining("2", "3")); diff --git a/core/src/test/java/org/elasticsearch/common/settings/loader/JsonSettingsLoaderTests.java b/core/src/test/java/org/elasticsearch/common/settings/loader/JsonSettingsLoaderTests.java index df5e71a1178..9750205145e 100644 --- a/core/src/test/java/org/elasticsearch/common/settings/loader/JsonSettingsLoaderTests.java +++ b/core/src/test/java/org/elasticsearch/common/settings/loader/JsonSettingsLoaderTests.java @@ -65,7 +65,7 @@ public class JsonSettingsLoaderTests extends ESTestCase { public void testNullValuedSettingThrowsException() { final String json = "{\"foo\":null}"; - final ElasticsearchParseException e = expectThrows(ElasticsearchParseException.class, () -> new JsonSettingsLoader(true).load(json)); + final ElasticsearchParseException e = expectThrows(ElasticsearchParseException.class, () -> new JsonSettingsLoader(false).load(json)); assertThat(e.toString(), containsString("null-valued setting found for key [foo] found at line number [1], column number [8]")); } } diff --git a/core/src/test/java/org/elasticsearch/common/settings/loader/YamlSettingsLoaderTests.java b/core/src/test/java/org/elasticsearch/common/settings/loader/YamlSettingsLoaderTests.java index 077cb5088f7..a4536ec21b9 100644 --- a/core/src/test/java/org/elasticsearch/common/settings/loader/YamlSettingsLoaderTests.java +++ b/core/src/test/java/org/elasticsearch/common/settings/loader/YamlSettingsLoaderTests.java @@ -89,7 +89,7 @@ public class YamlSettingsLoaderTests extends ESTestCase { public void testNullValuedSettingThrowsException() { final String yaml = "foo:"; - final ElasticsearchParseException e = expectThrows(ElasticsearchParseException.class, () -> new YamlSettingsLoader(true).load(yaml)); + final ElasticsearchParseException e = expectThrows(ElasticsearchParseException.class, () -> new YamlSettingsLoader(false).load(yaml)); assertThat(e.toString(), containsString("null-valued setting found for key [foo] found at line number [1], column number [5]")); } }