You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rocketmq.apache.org by ji...@apache.org on 2023/02/11 09:42:56 UTC
[rocketmq] branch develop updated: [ISSUE #5907] Optimize try catch to prevent ConcurrentHashMapUtils init failed (#5908)
This is an automated email from the ASF dual-hosted git repository.
jinrongtong pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/rocketmq.git
The following commit(s) were added to refs/heads/develop by this push:
new 4a6dc040b [ISSUE #5907] Optimize try catch to prevent ConcurrentHashMapUtils init failed (#5908)
4a6dc040b is described below
commit 4a6dc040bd079d997253df47406a8f60c67cc0b9
Author: mxsm <lj...@gmail.com>
AuthorDate: Sat Feb 11 17:42:36 2023 +0800
[ISSUE #5907] Optimize try catch to prevent ConcurrentHashMapUtils init failed (#5908)
* [ISSUE #5907]optimize try catch to prevent ConcurrentHashMapUtils init failed
* polish code style
---
.../apache/rocketmq/common/utils/ConcurrentHashMapUtils.java | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/common/src/main/java/org/apache/rocketmq/common/utils/ConcurrentHashMapUtils.java b/common/src/main/java/org/apache/rocketmq/common/utils/ConcurrentHashMapUtils.java
index b994276c9..1f1b4dd89 100644
--- a/common/src/main/java/org/apache/rocketmq/common/utils/ConcurrentHashMapUtils.java
+++ b/common/src/main/java/org/apache/rocketmq/common/utils/ConcurrentHashMapUtils.java
@@ -21,12 +21,16 @@ import java.util.function.Function;
public abstract class ConcurrentHashMapUtils {
- private static final boolean IS_JDK8;
+ private static boolean isJdk8;
static {
// Java 8
// Java 9+: 9,11,17
- IS_JDK8 = System.getProperty("java.version").startsWith("1.8.");
+ try {
+ isJdk8 = System.getProperty("java.version").startsWith("1.8.");
+ } catch (Exception ignore) {
+ isJdk8 = true;
+ }
}
/**
@@ -36,7 +40,7 @@ public abstract class ConcurrentHashMapUtils {
* @see <a href="https://bugs.openjdk.java.net/browse/JDK-8161372">https://bugs.openjdk.java.net/browse/JDK-8161372</a>
*/
public static <K, V> V computeIfAbsent(ConcurrentMap<K, V> map, K key, Function<? super K, ? extends V> func) {
- if (IS_JDK8) {
+ if (isJdk8) {
V v = map.get(key);
if (null == v) {
v = map.computeIfAbsent(key, func);