You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@solr.apache.org by ds...@apache.org on 2024/01/18 14:39:55 UTC

(solr) branch main updated: SOLR-15960: Fix EnvUtils.camelCaseToDotsMap thread-safety (#2204)

This is an automated email from the ASF dual-hosted git repository.

dsmiley pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/solr.git


The following commit(s) were added to refs/heads/main by this push:
     new d7e53fefe39  SOLR-15960:  Fix EnvUtils.camelCaseToDotsMap thread-safety (#2204)
d7e53fefe39 is described below

commit d7e53fefe39c0a3548dbcf44af4b419e73383d66
Author: pjmcarthur <92...@users.noreply.github.com>
AuthorDate: Thu Jan 18 06:39:49 2024 -0800

     SOLR-15960:  Fix EnvUtils.camelCaseToDotsMap thread-safety (#2204)
    
    * Use ConcurrentHashMap and use computeIfAbsent
    
    Co-authored-by: Paul McArthur <pm...@proton.me>
    Co-authored-by: David Smiley <ds...@apache.org>
---
 .../src/java/org/apache/solr/common/util/EnvUtils.java     | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)

diff --git a/solr/solrj/src/java/org/apache/solr/common/util/EnvUtils.java b/solr/solrj/src/java/org/apache/solr/common/util/EnvUtils.java
index 9bc33e624e9..48f44754c48 100644
--- a/solr/solrj/src/java/org/apache/solr/common/util/EnvUtils.java
+++ b/solr/solrj/src/java/org/apache/solr/common/util/EnvUtils.java
@@ -29,6 +29,7 @@ import java.util.Objects;
 import java.util.Properties;
 import java.util.SortedMap;
 import java.util.TreeMap;
+import java.util.concurrent.ConcurrentHashMap;
 import java.util.stream.Collectors;
 import org.apache.solr.common.SolrException;
 
@@ -40,7 +41,7 @@ import org.apache.solr.common.SolrException;
 public class EnvUtils {
   private static final SortedMap<String, String> ENV = new TreeMap<>(System.getenv());
   private static final Map<String, String> CUSTOM_MAPPINGS = new HashMap<>();
-  private static final Map<String, String> camelCaseToDotsMap = new HashMap<>();
+  private static final Map<String, String> camelCaseToDotsMap = new ConcurrentHashMap<>();
 
   static {
     try {
@@ -171,14 +172,9 @@ public class EnvUtils {
   }
 
   private static String camelCaseToDotSeparated(String key) {
-    if (camelCaseToDotsMap.containsKey(key)) {
-      return camelCaseToDotsMap.get(key);
-    } else {
-      String converted =
-          String.join(".", key.split("(?=[A-Z])")).replace("..", ".").toLowerCase(Locale.ROOT);
-      camelCaseToDotsMap.put(key, converted);
-      return converted;
-    }
+    return camelCaseToDotsMap.computeIfAbsent(
+        key,
+        (k) -> String.join(".", k.split("(?=[A-Z])")).replace("..", ".").toLowerCase(Locale.ROOT));
   }
 
   /** Get property as integer */