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 18:25:25 UTC
(solr) branch branch_9x 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 branch_9x
in repository https://gitbox.apache.org/repos/asf/solr.git
The following commit(s) were added to refs/heads/branch_9x by this push:
new 6ef158102b6 SOLR-15960: Fix EnvUtils.camelCaseToDotsMap thread-safety (#2204)
6ef158102b6 is described below
commit 6ef158102b689b9260a8ca4eeca55a7d06220dca
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 */