diff --git a/CHANGES.txt b/CHANGES.txt index 74d4265a974..18504560f65 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -455,6 +455,8 @@ Release 0.22.0 - Unreleased HADOOP-7046. Fix Findbugs warning in Configuration. (Po Cheung via shv) + HADOOP-7118. Fix NPE in Configuration.writeXml (todd) + Release 0.21.1 - Unreleased IMPROVEMENTS diff --git a/src/java/org/apache/hadoop/conf/Configuration.java b/src/java/org/apache/hadoop/conf/Configuration.java index 6b7df166946..c05acf36208 100644 --- a/src/java/org/apache/hadoop/conf/Configuration.java +++ b/src/java/org/apache/hadoop/conf/Configuration.java @@ -1620,6 +1620,7 @@ public class Configuration implements Iterable>, Element conf = doc.createElement("configuration"); doc.appendChild(conf); conf.appendChild(doc.createTextNode("\n")); + getProps(); // ensure properties is set for (Enumeration e = properties.keys(); e.hasMoreElements();) { String name = (String)e.nextElement(); Object object = properties.get(name); diff --git a/src/test/core/org/apache/hadoop/conf/TestConfiguration.java b/src/test/core/org/apache/hadoop/conf/TestConfiguration.java index 52c887f308a..fc9deef34ff 100644 --- a/src/test/core/org/apache/hadoop/conf/TestConfiguration.java +++ b/src/test/core/org/apache/hadoop/conf/TestConfiguration.java @@ -18,6 +18,7 @@ package org.apache.hadoop.conf; import java.io.BufferedWriter; +import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileWriter; import java.io.IOException; @@ -255,6 +256,16 @@ public class TestConfiguration extends TestCase { assertEquals(expectedOutput, conf.toString()); } + public void testWriteXml() throws IOException { + Configuration conf = new Configuration(); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + conf.writeXml(baos); + String result = baos.toString(); + assertTrue("Result has proper header", result.startsWith( + "")); + assertTrue("Result has proper footer", result.endsWith("")); + } + public void testIncludes() throws Exception { tearDown(); System.out.println("XXX testIncludes");