Update after last review

We check for null. Test added as well.
This commit is contained in:
David Pilato 2016-03-13 15:27:54 +01:00
parent e9e1e25998
commit 25531b7299
2 changed files with 18 additions and 1 deletions

View File

@ -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));
}

View File

@ -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"));
}
}
}