You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by oh...@apache.org on 2016/12/01 20:56:25 UTC
svn commit: r1772268 - in /commons/proper/configuration/trunk/src:
main/java/org/apache/commons/configuration2/plist/XMLPropertyListConfiguration.java
test/java/org/apache/commons/configuration2/plist/TestXMLPropertyListConfiguration.java
Author: oheger
Date: Thu Dec 1 20:56:25 2016
New Revision: 1772268
URL: http://svn.apache.org/viewvc?rev=1772268&view=rev
Log:
[CONFIGURATION-641] Improved exception when storing XMLPropertyListConfiguration.
It is now checked whether the locator has been correctly initialized.
If not, an exception with a helpful message is thrown.
Modified:
commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/plist/XMLPropertyListConfiguration.java
commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration2/plist/TestXMLPropertyListConfiguration.java
Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/plist/XMLPropertyListConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/plist/XMLPropertyListConfiguration.java?rev=1772268&r1=1772267&r2=1772268&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/plist/XMLPropertyListConfiguration.java (original)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/plist/XMLPropertyListConfiguration.java Thu Dec 1 20:56:25 2016
@@ -261,6 +261,12 @@ public class XMLPropertyListConfiguratio
@Override
public void write(Writer out) throws ConfigurationException
{
+ if (locator == null)
+ {
+ throw new ConfigurationException("Save operation not properly "
+ + "initialized! Do not call write(Writer) directly,"
+ + " but use a FileHandler to save a configuration.");
+ }
PrintWriter writer = new PrintWriter(out);
if (locator.getEncoding() != null)
Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration2/plist/TestXMLPropertyListConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration2/plist/TestXMLPropertyListConfiguration.java?rev=1772268&r1=1772267&r2=1772268&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration2/plist/TestXMLPropertyListConfiguration.java (original)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration2/plist/TestXMLPropertyListConfiguration.java Thu Dec 1 20:56:25 2016
@@ -23,18 +23,19 @@ import static org.junit.Assert.assertFal
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
import java.io.StringWriter;
+import java.io.Writer;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Iterator;
import java.util.List;
import java.util.TimeZone;
-import junitx.framework.ArrayAssert;
-import junitx.framework.ListAssert;
-import junitx.framework.ObjectAssert;
import org.apache.commons.configuration2.Configuration;
import org.apache.commons.configuration2.ConfigurationAssert;
import org.apache.commons.configuration2.ConfigurationComparator;
@@ -46,6 +47,10 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
+import junitx.framework.ArrayAssert;
+import junitx.framework.ListAssert;
+import junitx.framework.ObjectAssert;
+
/**
* @author Emmanuel Bourg
* @version $Id$
@@ -508,4 +513,30 @@ public class TestXMLPropertyListConfigur
checkArrayProperty(Arrays.asList(elems));
}
+
+ /**
+ * Tests a direct invocation of the write() method. This test is
+ * related to CONFIGURATION-641.
+ */
+ @Test
+ public void testWriteCalledDirectly() throws IOException
+ {
+ config = new XMLPropertyListConfiguration();
+ config.addProperty("foo", "bar");
+
+ Writer out = new FileWriter(folder.newFile());
+ try
+ {
+ config.write(out);
+ fail("No exception thrown!");
+ }
+ catch (ConfigurationException e)
+ {
+ assertThat(e.getMessage(), containsString("FileHandler"));
+ }
+ finally
+ {
+ out.close();
+ }
+ }
}