[
https://issues.apache.org/jira/browse/KAFKA-3237?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15145816#comment-15145816
]
Jeremy Custenborder commented on KAFKA-3237:
--------------------------------------------
Correct me if i'm wrong but there is only one
[define|https://github.com/apache/kafka/blob/trunk/clients/src/main/java/org/apache/kafka/common/config/ConfigDef.java#L75]
method that takes a validator. It also looks like the testing of default
values is handled by the constructor of
[ConfigKey|https://github.com/apache/kafka/blob/ab5ac264a71d7f895b21b4acfd93d9581dabd7c1/clients/src/main/java/org/apache/kafka/common/config/ConfigDef.java#L363].
If there is a validator present it's ran against the default. In my case I
want the user to define a value that is present in an enum, that I will hit
with Enum.valueOf() later. I don't want to define a default because it could be
wrong for the user. Setting a validator with the constants from the enum will
give me a nice error message to the user if they omit the setting.
{code}
public ConfigDef define(String name, Type type, Object defaultValue, Validator
validator, Importance importance, String documentation) {
{code}
> ConfigDef validators require a default value
> --------------------------------------------
>
> Key: KAFKA-3237
> URL: https://issues.apache.org/jira/browse/KAFKA-3237
> Project: Kafka
> Issue Type: Bug
> Components: config
> Affects Versions: 0.9.0.0
> Reporter: Jeremy Custenborder
> Priority: Minor
>
> I should be able to add a ConfigDef that has a validator but does has null as
> the default value. This would allow me to have a required property that is
> restricted to certain strings in this example. This exception should be
> thrown upon call to ConfigDef.parse instead.
> {code}
> ConfigDef def = new ConfigDef();
> def.define(key, Type.STRING, null, ValidString.in("ONE", "TWO", "THREE"),
> Importance.HIGH, "docs");
> {code}
> {code}
> Invalid value null for configuration test: String must be one of: ONE, TWO,
> THREE
> org.apache.kafka.common.config.ConfigException: Invalid value null for
> configuration enum_test: String must be one of: ONE, TWO, THREE
> at
> org.apache.kafka.common.config.ConfigDef$ValidString.ensureValid(ConfigDef.java:349)
> at
> org.apache.kafka.common.config.ConfigDef$ConfigKey.<init>(ConfigDef.java:375)
> {code}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)