Reverse meaning of XContentSettingsLoader flag
The sole constructor of XContentSettingsLoader accepts a boolean flag that indicates whether or not null values parsed from the source should be rejected or not. Previously a true value for this flag meant that null values should be rejected. With this commit, the meaning of this flag is reversed so that a true value means that null values should be accepted (note that this is needed due to the way that settings are unset via the cluster update settings API). The name of this flag has been changed from guardAgainstNullValuedSettings to allowNullValues, for clarity.
This commit is contained in:
parent
4aa5426361
commit
4d27328a83
|
@ -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
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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"));
|
||||
|
||||
|
|
|
@ -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]"));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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]"));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue