Skip to content

Commit 145a9be

Browse files
committed
Merge pull request lightbend#63 from mpilquist/cme-sysprops-fix
Fix ConcurrentModificationException that occurs when system properties are being modified during a call to ConfigImpl#loadSystemProperties
2 parents b5b0f17 + 89956ea commit 145a9be

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

config/src/main/java/com/typesafe/config/impl/ConfigImpl.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import java.util.Iterator;
1111
import java.util.List;
1212
import java.util.Map;
13+
import java.util.Properties;
1314
import java.util.concurrent.Callable;
1415

1516
import com.typesafe.config.Config;
@@ -289,8 +290,18 @@ static ConfigIncluder defaultIncluder() {
289290
}
290291
}
291292

293+
private static Properties getSystemProperties() {
294+
// Avoid ConcurrentModificationException due to parallel setting of system properties by copying properties
295+
final Properties systemProperties = System.getProperties();
296+
final Properties systemPropertiesCopy = new Properties();
297+
synchronized (systemProperties) {
298+
systemPropertiesCopy.putAll(systemProperties);
299+
}
300+
return systemPropertiesCopy;
301+
}
302+
292303
private static AbstractConfigObject loadSystemProperties() {
293-
return (AbstractConfigObject) Parseable.newProperties(System.getProperties(),
304+
return (AbstractConfigObject) Parseable.newProperties(getSystemProperties(),
294305
ConfigParseOptions.defaults().setOriginDescription("system properties")).parse();
295306
}
296307

0 commit comments

Comments
 (0)