Fix ConcurrentModificationException that occurs when system properties are being modified during a call to ConfigImpl#loadSystemProperties

This commit is contained in:
Michael Pilquist 2013-03-18 16:51:52 -04:00
parent b5b0f17ac1
commit 89956ea7df

View File

@ -10,6 +10,7 @@ import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.Callable;
import com.typesafe.config.Config;
@ -289,8 +290,18 @@ public class ConfigImpl {
}
}
private static Properties getSystemProperties() {
// Avoid ConcurrentModificationException due to parallel setting of system properties by copying properties
final Properties systemProperties = System.getProperties();
final Properties systemPropertiesCopy = new Properties();
synchronized (systemProperties) {
systemPropertiesCopy.putAll(systemProperties);
}
return systemPropertiesCopy;
}
private static AbstractConfigObject loadSystemProperties() {
return (AbstractConfigObject) Parseable.newProperties(System.getProperties(),
return (AbstractConfigObject) Parseable.newProperties(getSystemProperties(),
ConfigParseOptions.defaults().setOriginDescription("system properties")).parse();
}