HADOOP-6227. Fix Configuration to allow final parameters to be set to null and prevent them from being overridden. Contributed by Amareshwari Sriramadasu.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@810097 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Hemanth Yamijala 2009-09-01 15:24:56 +00:00
parent 4c66882a69
commit 75103dc925
3 changed files with 39 additions and 11 deletions

View File

@ -951,6 +951,10 @@ Trunk (unreleased changes)
HADOOP-6215. fix GenericOptionParser to deal with -D with '=' in the HADOOP-6215. fix GenericOptionParser to deal with -D with '=' in the
value. (Amar Kamat via sharad) value. (Amar Kamat via sharad)
HADOOP-6227. Fix Configuration to allow final parameters to be set to null
and prevent them from being overridden.
(Amareshwari Sriramadasu via yhemanth)
Release 0.20.1 - Unreleased Release 0.20.1 - Unreleased
INCOMPATIBLE CHANGES INCOMPATIBLE CHANGES

View File

@ -1286,17 +1286,20 @@ public class Configuration implements Iterable<Map.Entry<String,String>>,
} }
// Ignore this parameter if it has already been marked as 'final' // Ignore this parameter if it has already been marked as 'final'
if (attr != null && value != null) { if (attr != null) {
if (!finalParameters.contains(attr)) { if (value != null) {
properties.setProperty(attr, value); if (!finalParameters.contains(attr)) {
if (storeResource) { properties.setProperty(attr, value);
updatingResource.put(attr, name.toString()); if (storeResource) {
} updatingResource.put(attr, name.toString());
if (finalParameter) }
finalParameters.add(attr); } else {
} else { LOG.warn(name+":a attempt to override final parameter: "+attr
LOG.warn(name+":a attempt to override final parameter: "+attr
+"; Ignoring."); +"; Ignoring.");
}
}
if (finalParameter) {
finalParameters.add(attr);
} }
} }
} }

View File

@ -100,7 +100,28 @@ public class TestConfiguration extends TestCase {
assertTrue(conf.getInt("intvar", -1) == 42); assertTrue(conf.getInt("intvar", -1) == 42);
assertTrue(conf.getInt("my.int", -1) == 42); assertTrue(conf.getInt("my.int", -1) == 42);
} }
public void testFinalParam() throws IOException {
out=new BufferedWriter(new FileWriter(CONFIG));
startConfig();
declareProperty("my.var", "", "", true);
endConfig();
Path fileResource = new Path(CONFIG);
Configuration conf1 = new Configuration();
conf1.addResource(fileResource);
assertNull("my var is not null", conf1.get("my.var"));
out=new BufferedWriter(new FileWriter(CONFIG2));
startConfig();
declareProperty("my.var", "myval", "myval", false);
endConfig();
fileResource = new Path(CONFIG2);
Configuration conf2 = new Configuration(conf1);
conf2.addResource(fileResource);
assertNull("my var is not final", conf2.get("my.var"));
}
public static void assertEq(Object a, Object b) { public static void assertEq(Object a, Object b) {
System.out.println("assertEq: " + a + ", " + b); System.out.println("assertEq: " + a + ", " + b);
assertEquals(a, b); assertEquals(a, b);