commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Oliver Heger (JIRA)" <>
Subject [jira] [Commented] (CONFIGURATION-570) Passing SystemConfiguration() into PropertiesConfiguration() can cause a ConcurrentModificationException
Date Mon, 10 Mar 2014 20:38:45 GMT


Oliver Heger commented on CONFIGURATION-570:

This is an interesting report. I am also not sure how to handle it.

First of all, you have entered 1.6 as affected version. The current version is 1.10. There
has been some work on {{SystemConfiguration}}, but to be honest, I doubt that the problem
is solved in this version.

IMHO, situation is similar to the synchronized collections provided by the JDK (which can
be obtained via Collections.synchronizedSet/Map etc.). Here the Javadocs explicitly state
that iteration over the elements has to be manually synced. We could think about creating
a snapshot for the iteration, but this would affect every caller - a manual synchronization
in opposite can be added if needed dependent on the current use case.

Another thought: There is an alternative way for accessing system properties. In configuration
files you can use a special method for variable interpolation to access system properties.
Details can be found here:
Maybe this makes the append operation unnecessary?

> Passing SystemConfiguration() into PropertiesConfiguration() can cause a ConcurrentModificationException
> --------------------------------------------------------------------------------------------------------
>                 Key: CONFIGURATION-570
>                 URL:
>             Project: Commons Configuration
>          Issue Type: Bug
>    Affects Versions: 1.6
>            Reporter: John Vines
> This was encountered in a release of Accumulo. I'm not sure if this is in the realm of
commons configuration, but I figured I should put in a ticket-
> A. just in case it is or
> B. So others can be aware of this issue
> We had a piece of code which interpolates java properties (SystemConfiguration) with
other variables. This code worked as follows
> {code}
>       PropertiesConfiguration pconf = new PropertiesConfiguration();
>       pconf.append(new SystemConfiguration());
>       pconf.addProperty("hack_default_value", this.defaultValue);
>       String v = pconf.getString("hack_default_value");
> {code}
> However, after we added a monitor thread which calls System.setProperty before this code
is hit, we would occasionally get a ConcurrentModificationException.
> I traced it down to pconf.append doing an iteration over the Configuration (AbstractConfiguration,
line 1233 in 1.6). The configuration being passed in, SystemConfiguration, is just a MapConfiguration
from the result of System.getProperties. This is an exact copy of the map the System maintains.
> There are two accessors to that map, setProperty and setProperties in System. Set property
basically just falls to Properties.setProperty, while setProperties will copy the existing
properties, add new ones, and then replace the object. We are using setProperty in our code.
> Properties.setProperty is a synchronized call, so we resolved it by replacing our code
> {code}
>       PropertiesConfiguration pconf = new PropertiesConfiguration();
>       Properties systemProperties = System.getProperties();
>       synchronized (systemProperties) {
>         pconf.append(new MapConfiguration(systemProperties));
>       }
>       pconf.addProperty("hack_default_value", this.defaultValue);
>       String v = pconf.getString("hack_default_value");
> {code}
> I'm not quite sure if/how it should be handled in commons configuration. I'm thinking
if it IS in the scope of this project, then SystemConfiguration should create a snapshot of
System.getProperties. Or a new Configuration/configuration flag should be added to create
a snapshot of it instead of the map directly.

This message was sent by Atlassian JIRA

View raw message