findowners: Fix concurrency issue in Config class
The Config class seems to be used in multi-threaded contexts (e.g. via
Cache -> OwnersDb) but is not hardened for multi-threading. We noticed
errors in our logs complaining about concurrent modifications of
projectConfigMap when computeIfAbsent() is called on it. Fix that
immediate issue by switching to a concurrent type for the map.
Change-Id: I1b3f2ae7211787974440444c12c2c703e9d39d9b
diff --git a/src/main/java/com/googlesource/gerrit/plugins/findowners/Config.java b/src/main/java/com/googlesource/gerrit/plugins/findowners/Config.java
index 1ae9f93..e3fab58 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/findowners/Config.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/findowners/Config.java
@@ -25,8 +25,8 @@
import com.google.gerrit.server.project.NoSuchProjectException;
import com.google.gerrit.server.project.ProjectState;
import com.google.gerrit.server.query.change.ChangeData;
-import java.util.HashMap;
import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
/** find-owners configuration parameters */
class Config {
@@ -80,7 +80,7 @@
this.accountCache = accountCache;
this.patchListCache = patchListCache;
this.emails = emails;
- projectConfigMap = new HashMap<>();
+ projectConfigMap = new ConcurrentHashMap<>();
if (configFactory == null && config == null) { // When called from integration tests.
gerritConfig = null;
return;