mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2026-05-29 18:57:11 +08:00
fix(EnumUtil): 修复枚举类静态初始化时递归调用导致 IllegalStateException: Recursive update 的问题
使用 get + putIfAbsent 替代 computeIfAbsent,避免 ConcurrentHashMap 在递归场景下 抛出 Recursive update 异常。修复 issue#IDQYJK
This commit is contained in:
@@ -480,6 +480,16 @@ public class EnumUtil {
|
||||
if (null == enumClass) {
|
||||
return null;
|
||||
}
|
||||
return CACHE.computeIfAbsent(enumClass, (k) -> enumClass.getEnumConstants());
|
||||
// fix issue#IDQYJK: 避免 ConcurrentHashMap.computeIfAbsent 在枚举类静态初始化时
|
||||
// 递归调用导致 IllegalStateException: Recursive update 的问题
|
||||
// 使用 get + putIfAbsent 替代 computeIfAbsent,安全支持递归场景
|
||||
Enum<?>[] enums = CACHE.get(enumClass);
|
||||
if (null == enums) {
|
||||
enums = enumClass.getEnumConstants();
|
||||
if (null != enums) {
|
||||
CACHE.putIfAbsent(enumClass, enums);
|
||||
}
|
||||
}
|
||||
return enums;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user