Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
*/
public class ConfigDef {

private static final Object NO_DEFAULT_VALUE = new String("");
public static final Object NO_DEFAULT_VALUE = new String("");

private final Map<String, ConfigKey> configKeys = new HashMap<String, ConfigKey>();

Expand Down Expand Up @@ -360,7 +360,7 @@ public ConfigKey(String name, Type type, Object defaultValue, Validator validato
this.defaultValue = defaultValue;
this.validator = validator;
this.importance = importance;
if (this.validator != null)
if (this.validator != null && this.hasDefault())
this.validator.ensureValid(name, defaultValue);
this.documentation = documentation;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,19 @@ public void testSslPasswords() {
assertEquals(Password.HIDDEN, vals.get(SslConfigs.SSL_TRUSTSTORE_PASSWORD_CONFIG).toString());
}

@Test
public void testNullDefaultWithValidator() {
final String key = "enum_test";

ConfigDef def = new ConfigDef();
def.define(key, Type.STRING, ConfigDef.NO_DEFAULT_VALUE, ValidString.in("ONE", "TWO", "THREE"), Importance.HIGH, "docs");

Properties props = new Properties();
props.put(key, "ONE");
Map<String, Object> vals = def.parse(props);
assertEquals("ONE", vals.get(key));
}

private void testValidators(Type type, Validator validator, Object defaultVal, Object[] okValues, Object[] badValues) {
ConfigDef def = new ConfigDef().define("name", type, defaultVal, validator, Importance.HIGH, "docs");

Expand Down