From 89956ea7df37e7b7ea03c2435a3401109a0f27f8 Mon Sep 17 00:00:00 2001 From: Michael Pilquist Date: Mon, 18 Mar 2013 16:51:52 -0400 Subject: [PATCH] Fix ConcurrentModificationException that occurs when system properties are being modified during a call to ConfigImpl#loadSystemProperties --- .../java/com/typesafe/config/impl/ConfigImpl.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/config/src/main/java/com/typesafe/config/impl/ConfigImpl.java b/config/src/main/java/com/typesafe/config/impl/ConfigImpl.java index 9dfb1b1e..7cee43d0 100644 --- a/config/src/main/java/com/typesafe/config/impl/ConfigImpl.java +++ b/config/src/main/java/com/typesafe/config/impl/ConfigImpl.java @@ -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(); }