HADOOP-6243. Fix a NullPointerException in processing deprecated keys. Contributed by Sreekanth Ramakrishnan.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@812455 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Hemanth Yamijala 2009-09-08 10:56:15 +00:00
parent d09ade4d0b
commit 4a4dd27571
4 changed files with 31 additions and 81 deletions

View File

@ -984,6 +984,9 @@ Trunk (unreleased changes)
HADOOP-6229. Attempt to make a directory under an existing file on
LocalFileSystem should throw an Exception. (Boris Shkolnik via tomwhite)
HADOOP-6243. Fix a NullPointerException in processing deprecated keys.
(Sreekanth Ramakrishnan via yhemanth)
Release 0.20.1 - Unreleased
INCOMPATIBLE CHANGES

View File

@ -485,11 +485,4 @@
IP address.
</description>
</property>
<property>
<name>hadoop.conf.extra.classes</name>
<value>org.apache.hadoop.mapred.JobConf</value>
<final>true</final>
</property>
</configuration>

View File

@ -336,6 +336,12 @@ public class Configuration implements Iterable<Map.Entry<String,String>>,
}
addDefaultResource("core-default.xml");
addDefaultResource("core-site.xml");
//Add code for managing deprecated key mapping
//for example
//addDeprecation("oldKey1",new String[]{"newkey1","newkey2"});
//adds deprecation for oldKey1 to two new keys(newkey1, newkey2).
//so get or set of oldKey1 will correctly populate/access values of
//newkey1 and newkey2
}
private Properties properties;
@ -1364,56 +1370,8 @@ public class Configuration implements Iterable<Map.Entry<String,String>>,
loadResource(properties, resource, quiet);
}
// process for deprecation.
processDeprecation();
}
/**
* Flag to ensure that the classes mentioned in the value of the property
* <code>hadoop.conf.extra.classes</code> are loaded only once for
* all instances of <code>Configuration</code>
*/
private static AtomicBoolean loadedDeprecation = new AtomicBoolean(false);
private static final String extraConfKey = "hadoop.conf.extra.classes";
/**
* adds all the deprecations to the deprecatedKeyMap and updates the values of
* the appropriate keys
*/
private void processDeprecation() {
populateDeprecationMapping();
processDeprecatedKeys();
}
/**
* Loads all the classes in mapred and hdfs that extend Configuration and that
* have deprecations to be added into deprecatedKeyMap
*/
private synchronized void populateDeprecationMapping() {
if (!loadedDeprecation.get()) {
// load classes from mapred and hdfs which extend Configuration and have
// deprecations added in their static blocks
String classnames = substituteVars(properties.getProperty(extraConfKey));
if (classnames == null) {
return;
}
String[] classes = StringUtils.getStrings(classnames);
for (String className : classes) {
try {
Class.forName(className);
} catch (ClassNotFoundException e) {
LOG.warn(className + " is not in the classpath");
}
}
// make deprecatedKeyMap unmodifiable in order to prevent changes to
// it in user's code.
deprecatedKeyMap = Collections.unmodifiableMap(deprecatedKeyMap);
// ensure that deprecation processing is done only once for all
// instances of this object
loadedDeprecation.set(true);
}
}
/**
* Updates the keys that are replacing the deprecated keys and removes the
* deprecated keys from memory.

View File

@ -81,9 +81,7 @@ public class TestConfigurationDeprecation {
out.write("</property>\n");
}
static class MyConf extends Configuration {
static {
// add deprecation mappings.
private void addDeprecationToConfiguration() {
Configuration.addDeprecation("old.key1", new String[]{"new.key1"});
Configuration.addDeprecation("old.key2", new String[]{"new.key2"});
Configuration.addDeprecation("old.key3", new String[]{"new.key3"});
@ -105,7 +103,6 @@ public class TestConfigurationDeprecation {
Configuration.addDeprecation("E", new String[]{"F"});
Configuration.addDeprecation("G", new String[]{"H","I"});
}
}
/**
* This test is to check the precedence order between being final and
@ -123,8 +120,6 @@ public class TestConfigurationDeprecation {
public void testDeprecation() throws IOException {
out=new BufferedWriter(new FileWriter(CONFIG));
startConfig();
appendProperty("hadoop.conf.extra.classes", MyConf.class.getName()
+ ",myconf1");
// load keys with default values. Some of them are set to final to
// test the precedence order between deprecation and being final
appendProperty("new.key1","default.value1",true);
@ -145,6 +140,7 @@ public class TestConfigurationDeprecation {
appendProperty("new.key16","default.value16");
endConfig();
Path fileResource = new Path(CONFIG);
addDeprecationToConfiguration();
conf.addResource(fileResource);
out=new BufferedWriter(new FileWriter(CONFIG2));