Update after last review
We check for null. Test added as well.
This commit is contained in:
parent
e9e1e25998
commit
25531b7299
|
@ -113,6 +113,8 @@ public class Setting<T> extends ToXContentToBytes {
|
|||
private final Function<String, T> parser;
|
||||
private final EnumSet<Property> properties;
|
||||
|
||||
private static final EnumSet<Property> EMPTY_PROPERTIES = EnumSet.noneOf(Property.class);
|
||||
|
||||
/**
|
||||
* Creates a new Setting instance. When no scope is provided, we default to {@link Property#NodeScope}.
|
||||
* @param key the settings key for this setting.
|
||||
|
@ -125,8 +127,11 @@ public class Setting<T> extends ToXContentToBytes {
|
|||
this.key = key;
|
||||
this.defaultValue = defaultValue;
|
||||
this.parser = parser;
|
||||
if (properties == null) {
|
||||
throw new IllegalArgumentException("properties can not be null for setting [" + key + "]");
|
||||
}
|
||||
if (properties.length == 0) {
|
||||
this.properties = EnumSet.noneOf(Property.class);
|
||||
this.properties = EMPTY_PROPERTIES;
|
||||
} else {
|
||||
this.properties = EnumSet.copyOf(Arrays.asList(properties));
|
||||
}
|
||||
|
|
|
@ -445,4 +445,16 @@ public class SettingTests extends ESTestCase {
|
|||
assertThat(setting.hasIndexScope(), is(true));
|
||||
assertThat(setting.hasNodeScope(), is(true));
|
||||
}
|
||||
|
||||
/**
|
||||
* We can't have Null properties
|
||||
*/
|
||||
public void testRejectNullProperties() {
|
||||
try {
|
||||
Setting.simpleString("foo.bar", (Property[]) null);
|
||||
fail();
|
||||
} catch (IllegalArgumentException ex) {
|
||||
assertThat(ex.getMessage(), containsString("properties can not be null for setting"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue