Skip to content

Commit

Permalink
Merge pull request #19 from eBay/byarger/fix
Browse files Browse the repository at this point in the history
Addressing ConcurrentModificationException on RuntimeConfigManager arguments map.
  • Loading branch information
yarg0007 authored Feb 28, 2023
2 parents beadedc + b4fd0ca commit 403ba48
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
20 changes: 17 additions & 3 deletions NST/src/main/java/com/ebay/runtime/RuntimeConfigManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;

import com.ebay.nst.hosts.manager.PoolType;
import com.ebay.runtime.arguments.AndroidMocksLocationArgument;
Expand All @@ -25,7 +26,7 @@ public class RuntimeConfigManager {
// Singleton instance
private static RuntimeConfigManager instance = null;

Map<String, RuntimeConfigValue<?>> arguments = new HashMap<>();
private Map<String, RuntimeConfigValue<?>> arguments = new ConcurrentHashMap<>();

private RuntimeConfigManager() {
arguments.put(AndroidMocksLocationArgument.KEY, new AndroidMocksLocationArgument());
Expand Down Expand Up @@ -223,9 +224,22 @@ public String getCustomLoggerFormatPackage() {
private void init() {

String value;
String runtimeArgumentKey;
// Avoid concurrent modification exception on 'arguments' collection
// by updating a new map and then reinitializing 'arguments' with the
// contents of the new map.
Map<String, RuntimeConfigValue<?>> argumentValues = new HashMap<>();
for (Entry<String, RuntimeConfigValue<?>> entry : arguments.entrySet()) {
value = System.getProperty(entry.getValue().getRuntimeArgumentKey());
entry.getValue().parseRuntimeArgument(value);

RuntimeConfigValue<?> entryValue = entry.getValue();
runtimeArgumentKey = entryValue.getRuntimeArgumentKey();

value = System.getProperty(runtimeArgumentKey);
entryValue.parseRuntimeArgument(value);

argumentValues.put(runtimeArgumentKey, entryValue);
}
arguments.clear();
arguments.putAll(argumentValues);
}
}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<maven.compiler.plugin.version>3.6.0</maven.compiler.plugin.version>
<maven.surefire.plugin.version>2.9</maven.surefire.plugin.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<nstest.version>1.1.1</nstest.version>
<nstest.version>1.1.2</nstest.version>
<testng.version>7.5</testng.version>
<maven.deploy.skip>true</maven.deploy.skip>
</properties>
Expand Down

0 comments on commit 403ba48

Please sign in to comment.