ソースを参照

Update after last review

We check for null. Test added as well.
David Pilato 9 年 前
コミット
25531b7299

+ 6 - 1
core/src/main/java/org/elasticsearch/common/settings/Setting.java

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

+ 12 - 0
core/src/test/java/org/elasticsearch/common/settings/SettingTests.java

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