You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2019/07/02 15:09:54 UTC
[commons-configuration] branch master updated: [CONFIGURATION-750]
XMLPropertyListConfiguration cannot set arrays in the correct plist form.
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-configuration.git
The following commit(s) were added to refs/heads/master by this push:
new 6108d46 [CONFIGURATION-750] XMLPropertyListConfiguration cannot set arrays in the correct plist form.
6108d46 is described below
commit 6108d46ede3c99b85bced3c65ea568f81bd1f472
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Tue Jul 2 11:09:49 2019 -0400
[CONFIGURATION-750] XMLPropertyListConfiguration cannot set arrays in
the correct plist form.
---
src/changes/changes.xml | 3 ++
.../plist/XMLPropertyListConfiguration.java | 30 ++++++++++-------
.../plist/TestXMLPropertyListConfiguration.java | 38 +++++++++++++++++++---
3 files changed, 56 insertions(+), 15 deletions(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 4d88b0a..7b5858d 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -27,6 +27,9 @@
<body>
<release version="2.6" date="2019-MM-DD"
description="Minor release with new features and updated dependencies.">
+ <action dev="ggregory" type="fix" issue="CONFIGURATION-750" due-to="Jason Pickens, Gary Gregory, Emmanuel Bourg">
+ XMLPropertyListConfiguration cannot set arrays in the correct plist form.
+ </action>
</release>
<release version="2.5" date="2019-05-23"
description="Minor release with new features and updated dependencies.">
diff --git a/src/main/java/org/apache/commons/configuration2/plist/XMLPropertyListConfiguration.java b/src/main/java/org/apache/commons/configuration2/plist/XMLPropertyListConfiguration.java
index 332c15a..7569d88 100644
--- a/src/main/java/org/apache/commons/configuration2/plist/XMLPropertyListConfiguration.java
+++ b/src/main/java/org/apache/commons/configuration2/plist/XMLPropertyListConfiguration.java
@@ -170,22 +170,30 @@ public class XMLPropertyListConfiguration extends BaseHierarchicalConfiguration
super(new InMemoryNodeModel(root));
}
+ private void setPropertyDirect(final String key, final Object value) {
+ setDetailEvents(false);
+ try
+ {
+ clearProperty(key);
+ addPropertyDirect(key, value);
+ }
+ finally
+ {
+ setDetailEvents(true);
+ }
+ }
+
@Override
protected void setPropertyInternal(final String key, final Object value)
{
// special case for byte arrays, they must be stored as is in the configuration
- if (value instanceof byte[])
+ if (value instanceof byte[] || value instanceof List)
{
- setDetailEvents(false);
- try
- {
- clearProperty(key);
- addPropertyDirect(key, value);
- }
- finally
- {
- setDetailEvents(true);
- }
+ setPropertyDirect(key, value);
+ }
+ else if (value instanceof Object[])
+ {
+ setPropertyDirect(key, Arrays.asList((Object[]) value));
}
else
{
diff --git a/src/test/java/org/apache/commons/configuration2/plist/TestXMLPropertyListConfiguration.java b/src/test/java/org/apache/commons/configuration2/plist/TestXMLPropertyListConfiguration.java
index a9d9172..54c93f1 100644
--- a/src/test/java/org/apache/commons/configuration2/plist/TestXMLPropertyListConfiguration.java
+++ b/src/test/java/org/apache/commons/configuration2/plist/TestXMLPropertyListConfiguration.java
@@ -483,11 +483,11 @@ public class TestXMLPropertyListConfiguration
}
/**
- * Tests whether a list can be saved correctly. This test is related to
+ * Tests whether a list can be added correctly. This test is related to
* CONFIGURATION-427.
*/
@Test
- public void testSaveList() throws ConfigurationException
+ public void testAddList() throws ConfigurationException
{
final List<String> elems =
Arrays.asList("element1", "element2", "anotherElement");
@@ -498,11 +498,11 @@ public class TestXMLPropertyListConfiguration
}
/**
- * Tests whether an array can be saved correctly. This test is related to
+ * Tests whether an array can be added correctly. This test is related to
* CONFIGURATION-427.
*/
@Test
- public void testSaveArray() throws ConfigurationException
+ public void testAddArray() throws ConfigurationException
{
final Object[] elems = {
"arrayElem1", "arrayElem2", "arrayElem3"
@@ -514,6 +514,36 @@ public class TestXMLPropertyListConfiguration
}
/**
+ * Tests whether a list can be set correctly. This test is related to
+ * CONFIGURATION-750.
+ */
+ @Test
+ public void testSetList() throws ConfigurationException
+ {
+ final List<String> elems =
+ Arrays.asList("element1", "element2", "anotherElement");
+ config = new XMLPropertyListConfiguration();
+ config.setProperty("array", elems);
+
+ checkArrayProperty(elems);
+ }
+
+ /**
+ * Tests whether an array can be set correctly. This test is related to
+ * CONFIGURATION-750.
+ */
+ @Test
+ public void testSetArray() throws ConfigurationException {
+ final Object[] elems = {
+ "arrayElem1", "arrayElem2", "arrayElem3"
+ };
+ config = new XMLPropertyListConfiguration();
+ config.setProperty("array", elems);
+
+ checkArrayProperty(Arrays.asList(elems));
+ }
+
+ /**
* Tests a direct invocation of the write() method. This test is
* related to CONFIGURATION-641.
*/