HADOOP-12117. Potential NPE from Configuration#loadProperty with allowNullValueProperties set. (Contributed by zhihai xu)
(cherry picked from commit 99c8c5839b
)
Conflicts:
hadoop-common-project/hadoop-common/CHANGES.txt
hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfiguration.java
This commit is contained in:
parent
f558429efe
commit
c5c0577248
|
@ -442,6 +442,9 @@ Release 2.8.0 - UNRELEASED
|
|||
HADOOP-12185. NetworkTopology is not efficient adding/getting/removing
|
||||
nodes. (Inigo Goiri via cdouglas)
|
||||
|
||||
HADOOP-12117. Potential NPE from Configuration#loadProperty with
|
||||
allowNullValueProperties set. (zhihai xu via vinayakumarb)
|
||||
|
||||
Release 2.7.2 - UNRELEASED
|
||||
|
||||
INCOMPATIBLE CHANGES
|
||||
|
|
|
@ -2656,14 +2656,14 @@ public class Configuration implements Iterable<Map.Entry<String,String>>,
|
|||
to.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void loadProperty(Properties properties, String name, String attr,
|
||||
String value, boolean finalParameter, String[] source) {
|
||||
if (value != null || allowNullValueProperties) {
|
||||
if (value == null) {
|
||||
value = DEFAULT_STRING_CHECK;
|
||||
}
|
||||
if (!finalParameters.contains(attr)) {
|
||||
if (value==null && allowNullValueProperties) {
|
||||
value = DEFAULT_STRING_CHECK;
|
||||
}
|
||||
properties.setProperty(attr, value);
|
||||
if(source != null) {
|
||||
updatingResource.put(attr, source);
|
||||
|
|
|
@ -1355,6 +1355,19 @@ public class TestConfiguration extends TestCase {
|
|||
// it's expected behaviour.
|
||||
}
|
||||
|
||||
public void testNullValueProperties() throws Exception {
|
||||
Configuration conf = new Configuration();
|
||||
conf.setAllowNullValueProperties(true);
|
||||
out = new BufferedWriter(new FileWriter(CONFIG));
|
||||
startConfig();
|
||||
appendProperty("attr", "value", true);
|
||||
appendProperty("attr", "", true);
|
||||
endConfig();
|
||||
Path fileResource = new Path(CONFIG);
|
||||
conf.addResource(fileResource);
|
||||
assertEquals("value", conf.get("attr"));
|
||||
}
|
||||
|
||||
public static void main(String[] argv) throws Exception {
|
||||
junit.textui.TestRunner.main(new String[]{
|
||||
TestConfiguration.class.getName()
|
||||
|
|
Loading…
Reference in New Issue