From 160b6fd4966f5189f988eaf0f094867fb2155c04 Mon Sep 17 00:00:00 2001 From: Todd Lipcon Date: Wed, 26 Jan 2011 06:59:14 +0000 Subject: [PATCH] HADOOP-7118. Fix NPE in Configuration.writeXml. Contributed by Todd Lipcon git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1063613 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES.txt | 2 ++ src/java/org/apache/hadoop/conf/Configuration.java | 1 + .../org/apache/hadoop/conf/TestConfiguration.java | 11 +++++++++++ 3 files changed, 14 insertions(+) diff --git a/CHANGES.txt b/CHANGES.txt index 74d4265a97..18504560f6 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 6b7df16694..c05acf3620 100644 --- a/src/java/org/apache/hadoop/conf/Configuration.java +++ b/src/java/org/apache/hadoop/conf/Configuration.java @@ -1620,6 +1620,7 @@ private synchronized Document asXmlDocument() throws IOException { 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 52c887f308..fc9deef34f 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 void testToString() throws IOException { 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");