What about using the "short and sweet" solution from 2.0? I attach a possible unit test.
</nk> --- Norbert Kiesel Systems Architect | Engineering MetricStream 2600 E. Bayshore Road | Palo Alto, CA - 94303 +1-650-620-2954 | [email protected] | www.metricstream.com ________________________________________ From: Gary Gregory <[email protected]> Sent: Monday, January 11, 2016 10:49 AM To: Commons Users List Subject: Re: [configuration] 1.10 regression / backwards-incompatible change in MapConfiguration.convertPropertiesToMap ? And a new unit test of course. Gary On Mon, Jan 11, 2016 at 10:49 AM, Gary Gregory <[email protected]> wrote: > Sounds like we need a different fix for > https://issues.apache.org/jira/browse/CONFIGURATION-556 and another > release ... > > Gary > > On Sun, Jan 10, 2016 at 11:42 AM, Norbert Kiesel <[email protected] > > wrote: > >> Any chance we will see a 1.11? >> >> At least 1.10 release notes should be updated to note this, no? Right now >> it claims to be 100 backwards compatible. >> >> On Jan 10, 2016 11:34 AM, Oliver Heger <[email protected]> >> wrote: >> Hi, >> >> Am 07.01.2016 um 20:33 schrieb Norbert Kiesel: >> > Hi, >> > >> > >> > we just tried to upgrade from commons-configuration-1.9 to >> commons-configuration-1.10 and hit a blocking problem. It manifests itself >> as: >> > >> > java.lang.UnsupportedOperationException >> > at java.util.AbstractMap.put(AbstractMap.java:209) >> > at >> org.apache.commons.configuration.MapConfiguration.addPropertyDirect(MapConfiguration.java:186) >> > at >> org.apache.commons.configuration.AbstractConfiguration.addPropertyValues(AbstractConfiguration.java:423) >> > at >> org.apache.commons.configuration.AbstractConfiguration.addProperty(AbstractConfiguration.java:393) >> > at >> org.apache.commons.configuration.AbstractConfiguration.setProperty(AbstractConfiguration.java:486) >> > >> > >> > >> > Looks like this happens because the map was created using the >> `MapConfiguration(Properties props)` constructor. In 1.9, this creates a >> HashMap and fills it with the properties. In 1.10, this now uses an >> AbstractMap that only overrides `entrySet` which makes this a read-only map. >> > >> > >> > Our code then tries to add more properties, which produces the above >> exception. >> > >> > >> > Are we doing something wrong here or is this really a regression in >> 1.10? >> > >> >> This seems to be a regression in 1.10, unfortunately. According to SVN >> history, the code in MapConfiguration has been patched to fix >> CONFIGURATION-556 [1]. The fact that the MapConfiguration can no longer >> be updated is probably an undesired side effect. >> >> I assume that this will work again with version 2.0. In this version, >> MapConfiguration just stores the Properties object passed to the >> constructor. So updates are not a problem. >> >> Oliver >> >> [1] https://issues.apache.org/jira/browse/CONFIGURATION-556 >> >> > >> > >> > >> > </nk> >> > >> > --- >> > >> > >> > Norbert Kiesel >> > Systems Architect | Engineering >> > MetricStream >> > 2600 E. Bayshore Road | Palo Alto, CA - 94303 >> > +1-650-620-2954 | [email protected] | www.metricstream.com< >> http://www.metricstream.com> >> > >> > Confidentiality Notice:This email and any files transmitted with it are >> confidential and intended solely for the use of the individual or entity to >> whom they are addressed. This message contains confidential information and >> is intended only for the individual named. If you are not the named >> addressee you should not disseminate, distribute or copy this e-mail. >> Please notify the sender immediately by e-mail if you have received this >> e-mail by mistake and delete this e-mail from your system. If you are not >> the intended recipient you are notified that disclosing, copying, >> distributing or taking any action in reliance on the contents of this >> information is strictly prohibited >> > >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: [email protected] >> For additional commands, e-mail: [email protected] >> >> > > > -- > E-Mail: [email protected] | [email protected] > Java Persistence with Hibernate, Second Edition > <http://www.manning.com/bauer3/> > JUnit in Action, Second Edition <http://www.manning.com/tahchiev/> > Spring Batch in Action <http://www.manning.com/templier/> > Blog: http://garygregory.wordpress.com > Home: http://garygregory.com/ > Tweet! http://twitter.com/GaryGregory > -- E-Mail: [email protected] | [email protected] Java Persistence with Hibernate, Second Edition <http://www.manning.com/bauer3/> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/> Spring Batch in Action <http://www.manning.com/templier/> Blog: http://garygregory.wordpress.com Home: http://garygregory.com/ Tweet! http://twitter.com/GaryGregory Confidentiality Notice:This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system. If you are not the intended recipient you are notified that disclosing, copying, distributing or taking any action in reliance on the contents of this information is strictly prohibited
From 129dc1f8f703af762ad04235cd73f55485e6a313 Mon Sep 17 00:00:00 2001 From: Norbert Kiesel <[email protected]> Date: Mon, 11 Jan 2016 11:57:06 -0800 Subject: [PATCH] Unit test for 1.10 regression --- .../TestMapConfigurationRegression.java | 39 +++++++++++++++++++--- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git src/test/java/org/apache/commons/configuration/TestMapConfigurationRegression.java src/test/java/org/apache/commons/configuration/TestMapConfigurationRegression.java index 124df61..13593d5 100644 --- src/test/java/org/apache/commons/configuration/TestMapConfigurationRegression.java +++ src/test/java/org/apache/commons/configuration/TestMapConfigurationRegression.java @@ -19,6 +19,7 @@ package org.apache.commons.configuration; import java.util.Collections; import java.util.Map; +import java.util.Properties; import java.util.UUID; import org.junit.Assert; @@ -27,13 +28,41 @@ import org.junit.Test; public class TestMapConfigurationRegression { @Test - public void testMapConfigurationRegression() + public void testMapConfigurationRegressionMap() { - final String key = UUID.randomUUID().toString(); - final String value = UUID.randomUUID().toString(); - final Map<String, String> map = Collections.singletonMap(key, value); + final String key1 = UUID.randomUUID().toString(); + final String value1 = UUID.randomUUID().toString(); + final Map<String, String> map = Collections.singletonMap(key1, value1); final MapConfiguration mc = new MapConfiguration(map); Assert.assertEquals(1, mc.getMap().size()); - Assert.assertEquals(value, mc.getString(key)); + Assert.assertEquals(value1, mc.getString(key1)); + + // Make sure the resulting configuration is modifiable + final String key2 = UUID.randomUUID().toString(); + final String value2 = UUID.randomUUID().toString(); + mc.getMap().put(key2, value2); + Assert.assertEquals(2, mc.getMap().size()); + Assert.assertEquals(value1, mc.getString(key1)); + Assert.assertEquals(value2, mc.getString(key2)); + } + + @Test + public void testMapConfigurationRegressionProperties() + { + final String key1 = UUID.randomUUID().toString(); + final String value1 = UUID.randomUUID().toString(); + final Properties props = new Properties(); + props.setProperty(key1, value1); + final MapConfiguration mc = new MapConfiguration(props); + Assert.assertEquals(1, mc.getMap().size()); + Assert.assertEquals(value1, mc.getString(key1)); + + // Make sure the resulting configuration is modifiable + final String key2 = UUID.randomUUID().toString(); + final String value2 = UUID.randomUUID().toString(); + mc.getMap().put(key2, value2); + Assert.assertEquals(2, mc.getMap().size()); + Assert.assertEquals(value1, mc.getString(key1)); + Assert.assertEquals(value2, mc.getString(key2)); } } -- 2.7.0.rc3
--------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
