Author: xgong
Date: Wed May 28 17:06:04 2014
New Revision: 1598070
URL: http://svn.apache.org/r1598070
Log:
HADOOP-10625. Trim configuration names when putting/getting them
Modified:
hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/CHANGES.txt
hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/Configuration.java
hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfiguration.java
Modified:
hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/CHANGES.txt
URL:
http://svn.apache.org/viewvc/hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/CHANGES.txt?rev=1598070&r1=1598069&r2=1598070&view=diff
==============================================================================
---
hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/CHANGES.txt
(original)
+++
hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/CHANGES.txt
Wed May 28 17:06:04 2014
@@ -150,6 +150,9 @@ Release 2.5.0 - UNRELEASED
HADOOP-10489. UserGroupInformation#getTokens and UserGroupInformation
#addToken can lead to ConcurrentModificationException (Robert Kanter via
atm)
+ HADOOP-10625. Trim configuration names when putting/getting them
+ to properties. (Wangda Tan via xgong)
+
Release 2.4.1 - UNRELEASED
INCOMPATIBLE CHANGES
Modified:
hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/Configuration.java
URL:
http://svn.apache.org/viewvc/hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/Configuration.java?rev=1598070&r1=1598069&r2=1598070&view=diff
==============================================================================
---
hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/Configuration.java
(original)
+++
hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/Configuration.java
Wed May 28 17:06:04 2014
@@ -566,6 +566,9 @@ public class Configuration implements It
*/
private String[] handleDeprecation(DeprecationContext deprecations,
String name) {
+ if (null != name) {
+ name = name.trim();
+ }
ArrayList<String > names = new ArrayList<String>();
if (isDeprecated(name)) {
DeprecatedKeyInfo keyInfo = deprecations.getDeprecatedKeyMap().get(name);
@@ -837,12 +840,12 @@ public class Configuration implements It
/**
* Get the value of the <code>name</code> property, <code>null</code> if
* no such property exists. If the key is deprecated, it returns the value of
- * the first key which replaces the deprecated key and is not null
+ * the first key which replaces the deprecated key and is not null.
*
* Values are processed for <a href="#VariableExpansion">variable
expansion</a>
* before being returned.
*
- * @param name the property name.
+ * @param name the property name, will be trimmed before get value.
* @return the value of the <code>name</code> or its replacing property,
* or null if no such property exists.
*/
@@ -946,7 +949,8 @@ public class Configuration implements It
/**
* Set the <code>value</code> of the <code>name</code> property. If
* <code>name</code> is deprecated or there is a deprecated name associated
to it,
- * it sets the value to both names.
+ * it sets the value to both names. Name will be trimmed before put into
+ * configuration.
*
* @param name property name.
* @param value property value.
@@ -958,7 +962,8 @@ public class Configuration implements It
/**
* Set the <code>value</code> of the <code>name</code> property. If
* <code>name</code> is deprecated, it also sets the <code>value</code> to
- * the keys that replace the deprecated key.
+ * the keys that replace the deprecated key. Name will be trimmed before put
+ * into configuration.
*
* @param name property name.
* @param value property value.
@@ -973,6 +978,7 @@ public class Configuration implements It
Preconditions.checkArgument(
value != null,
"The value of property " + name + " must not be null");
+ name = name.trim();
DeprecationContext deprecations = deprecationContext.get();
if (deprecations.getDeprecatedKeyMap().isEmpty()) {
getProps();
@@ -1058,7 +1064,7 @@ public class Configuration implements It
* If no such property exists,
* then <code>defaultValue</code> is returned.
*
- * @param name property name.
+ * @param name property name, will be trimmed before get value.
* @param defaultValue default value.
* @return property value, or <code>defaultValue</code> if the property
* doesn't exist.
Modified:
hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfiguration.java
URL:
http://svn.apache.org/viewvc/hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfiguration.java?rev=1598070&r1=1598069&r2=1598070&view=diff
==============================================================================
---
hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfiguration.java
(original)
+++
hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfiguration.java
Wed May 28 17:06:04 2014
@@ -49,7 +49,7 @@ import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IOUtils;
import org.apache.hadoop.net.NetUtils;
import static org.apache.hadoop.util.PlatformName.IBM_JAVA;
-import org.codehaus.jackson.map.ObjectMapper;
+import org.codehaus.jackson.map.ObjectMapper;
public class TestConfiguration extends TestCase {
@@ -1003,6 +1003,14 @@ public class TestConfiguration extends T
String resource;
}
+ public void testGetSetTrimmedNames() throws IOException {
+ Configuration conf = new Configuration(false);
+ conf.set(" name", "value");
+ assertEquals("value", conf.get("name"));
+ assertEquals("value", conf.get(" name"));
+ assertEquals("value", conf.getRaw(" name "));
+ }
+
public void testDumpConfiguration () throws IOException {
StringWriter outWriter = new StringWriter();
Configuration.dumpConfiguration(conf, outWriter);