kafka-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jun...@apache.org
Subject kafka git commit: kafka-1798; ConfigDef.parseType() should throw exception on invalid boolean value; patched by dokovan; reviewed by Jun Rao
Date Tue, 02 Dec 2014 00:24:44 GMT
Repository: kafka
Updated Branches:
  refs/heads/trunk 74bc8860c -> b24f9c089


kafka-1798; ConfigDef.parseType() should throw exception on invalid boolean value; patched
by dokovan; reviewed by Jun Rao


Project: http://git-wip-us.apache.org/repos/asf/kafka/repo
Commit: http://git-wip-us.apache.org/repos/asf/kafka/commit/b24f9c08
Tree: http://git-wip-us.apache.org/repos/asf/kafka/tree/b24f9c08
Diff: http://git-wip-us.apache.org/repos/asf/kafka/diff/b24f9c08

Branch: refs/heads/trunk
Commit: b24f9c0890302a5149aaaf26dc933bd0a842f1be
Parents: 74bc886
Author: dokovan <dokovan@hotmail.com>
Authored: Mon Dec 1 16:24:31 2014 -0800
Committer: Jun Rao <junrao@gmail.com>
Committed: Mon Dec 1 16:24:31 2014 -0800

----------------------------------------------------------------------
 .../java/org/apache/kafka/common/config/ConfigDef.java    | 10 ++++++++--
 .../org/apache/kafka/common/config/ConfigDefTest.java     |  9 ++++++++-
 2 files changed, 16 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kafka/blob/b24f9c08/clients/src/main/java/org/apache/kafka/common/config/ConfigDef.java
----------------------------------------------------------------------
diff --git a/clients/src/main/java/org/apache/kafka/common/config/ConfigDef.java b/clients/src/main/java/org/apache/kafka/common/config/ConfigDef.java
index 347e252..98cb79b 100644
--- a/clients/src/main/java/org/apache/kafka/common/config/ConfigDef.java
+++ b/clients/src/main/java/org/apache/kafka/common/config/ConfigDef.java
@@ -154,8 +154,14 @@ public class ConfigDef {
                 trimmed = ((String) value).trim();
             switch (type) {
                 case BOOLEAN:
-                    if (value instanceof String)
-                        return Boolean.parseBoolean(trimmed);
+                    if (value instanceof String) {
+                    	if (trimmed.equalsIgnoreCase("true"))
+                    		return true;
+                    	else if (trimmed.equalsIgnoreCase("false"))
+                    		return false;
+                    	else
+                    		throw new ConfigException(name, value, "Expected value to be either
true or false");
+                    }
                     else if (value instanceof Boolean)
                         return value;
                     else

http://git-wip-us.apache.org/repos/asf/kafka/blob/b24f9c08/clients/src/test/java/org/apache/kafka/common/config/ConfigDefTest.java
----------------------------------------------------------------------
diff --git a/clients/src/test/java/org/apache/kafka/common/config/ConfigDefTest.java b/clients/src/test/java/org/apache/kafka/common/config/ConfigDefTest.java
index 7869e46..3c442a2 100644
--- a/clients/src/test/java/org/apache/kafka/common/config/ConfigDefTest.java
+++ b/clients/src/test/java/org/apache/kafka/common/config/ConfigDefTest.java
@@ -38,7 +38,9 @@ public class ConfigDefTest {
                                        .define("d", Type.LIST, Importance.HIGH, "docs")
                                        .define("e", Type.DOUBLE, Importance.HIGH, "docs")
                                        .define("f", Type.CLASS, Importance.HIGH, "docs")
-                                       .define("g", Type.BOOLEAN, Importance.HIGH, "docs");
+                                       .define("g", Type.BOOLEAN, Importance.HIGH, "docs")
+                                       .define("h", Type.BOOLEAN, Importance.HIGH, "docs")
+                                       .define("i", Type.BOOLEAN, Importance.HIGH, "docs");
 
         Properties props = new Properties();
         props.put("a", "1   ");
@@ -47,6 +49,8 @@ public class ConfigDefTest {
         props.put("e", 42.5d);
         props.put("f", String.class.getName());
         props.put("g", "true");
+        props.put("h", "FalSE");
+        props.put("i", "TRUE");
 
         Map<String, Object> vals = def.parse(props);
         assertEquals(1, vals.get("a"));
@@ -56,6 +60,8 @@ public class ConfigDefTest {
         assertEquals(42.5d, vals.get("e"));
         assertEquals(String.class, vals.get("f"));
         assertEquals(true, vals.get("g"));
+        assertEquals(false, vals.get("h"));
+        assertEquals(true, vals.get("i"));
     }
 
     @Test(expected = ConfigException.class)
@@ -85,6 +91,7 @@ public class ConfigDefTest {
         testBadInputs(Type.DOUBLE, "hello", null, new Object());
         testBadInputs(Type.STRING, new Object());
         testBadInputs(Type.LIST, 53, new Object());
+        testBadInputs(Type.BOOLEAN, "hello", "truee", "fals");
     }
 
     private void testBadInputs(Type type, Object... values) {


Mime
View raw message