mirror of
https://github.com/lightbend/config.git
synced 2025-01-29 05:30:08 +08:00
Fix ConcurrentModificationException that occurs when system properties are being modified during a call to ConfigImpl#loadSystemProperties
This commit is contained in:
parent
b5b0f17ac1
commit
89956ea7df
@ -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();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user