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
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
INCOMPATIBLE CHANGES

View File

@ -1286,19 +1286,22 @@ private void loadResource(Properties properties, Object name, boolean quiet) {
}
// Ignore this parameter if it has already been marked as 'final'
if (attr != null && value != null) {
if (attr != null) {
if (value != null) {
if (!finalParameters.contains(attr)) {
properties.setProperty(attr, value);
if (storeResource) {
updatingResource.put(attr, name.toString());
}
if (finalParameter)
finalParameters.add(attr);
} else {
LOG.warn(name+":a attempt to override final parameter: "+attr
+"; Ignoring.");
}
}
if (finalParameter) {
finalParameters.add(attr);
}
}
}
} catch (IOException e) {

View File

@ -101,6 +101,27 @@ public void testVariableSubstitution() throws IOException {
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) {
System.out.println("assertEq: " + a + ", " + b);
assertEquals(a, b);