From 574f0b4c0a56918f2d0fb859b38331533708f8c8 Mon Sep 17 00:00:00 2001 From: Harsh J Date: Fri, 6 Jan 2012 05:42:24 +0000 Subject: [PATCH] HADOOP-4515. Configuration#getBoolean must not be case sensitive. (Sho Shimauchi via harsh) git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1227964 13f79535-47bb-0310-9956-ffa450edef68 --- hadoop-common-project/hadoop-common/CHANGES.txt | 2 ++ .../src/main/java/org/apache/hadoop/conf/Configuration.java | 6 ++++++ .../test/java/org/apache/hadoop/conf/TestConfiguration.java | 6 ++++++ 3 files changed, 14 insertions(+) diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt b/hadoop-common-project/hadoop-common/CHANGES.txt index faf1f3104b..f663dad8cf 100644 --- a/hadoop-common-project/hadoop-common/CHANGES.txt +++ b/hadoop-common-project/hadoop-common/CHANGES.txt @@ -86,6 +86,8 @@ Trunk (unreleased changes) HADOOP-7957. Classes deriving GetGroupsBase should be able to override proxy creation. (jitendra) + HADOOP-4515. Configuration#getBoolean must not be case sensitive. (Sho Shimauchi via harsh) + BUGS HADOOP-7851. Configuration.getClasses() never returns the default value. diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/Configuration.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/Configuration.java index 41514a3f36..79e0793253 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/Configuration.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/Configuration.java @@ -826,6 +826,12 @@ public void setFloat(String name, float value) { */ public boolean getBoolean(String name, boolean defaultValue) { String valueString = getTrimmed(name); + if (null == valueString || "".equals(valueString)) { + return defaultValue; + } + + valueString = valueString.toLowerCase(); + if ("true".equals(valueString)) return true; else if ("false".equals(valueString)) diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfiguration.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfiguration.java index 24d3a691f3..bbe82914b2 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfiguration.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfiguration.java @@ -451,6 +451,9 @@ public void testBooleanValues() throws IOException { appendProperty("test.bool3", " true "); appendProperty("test.bool4", " false "); appendProperty("test.bool5", "foo"); + appendProperty("test.bool6", "TRUE"); + appendProperty("test.bool7", "FALSE"); + appendProperty("test.bool8", ""); endConfig(); Path fileResource = new Path(CONFIG); conf.addResource(fileResource); @@ -459,6 +462,9 @@ public void testBooleanValues() throws IOException { assertEquals(true, conf.getBoolean("test.bool3", false)); assertEquals(false, conf.getBoolean("test.bool4", true)); assertEquals(true, conf.getBoolean("test.bool5", true)); + assertEquals(true, conf.getBoolean("test.bool6", false)); + assertEquals(false, conf.getBoolean("test.bool7", true)); + assertEquals(false, conf.getBoolean("test.bool8", false)); } public void testFloatValues() throws IOException {