Skip to content

fix(cache): catch Throwable in CacheManage static init (#1724)#1890

Open
HandSonic wants to merge 1 commit into
OtterMind:mainfrom
HandSonic:fix/1724-cache-manage-throwable
Open

fix(cache): catch Throwable in CacheManage static init (#1724)#1890
HandSonic wants to merge 1 commit into
OtterMind:mainfrom
HandSonic:fix/1724-cache-manage-throwable

Conversation

@HandSonic

@HandSonic HandSonic commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Problem

静态初始化器仅捕获了 Exception,而遗漏了诸如
NoClassDefFoundError 之类的 Errors。一旦初始化因 Error 失败,该类
就会被永久“污染”,且缓存会被静默禁用。

此外,还需在 fuzzyDelete() 中添加初始化保护机制,以防止在缓存初始化
失败且从外部调用 fuzzyDelete 时发生 NPE。

Fix

在 开头添加 守卫

Related

Fixes #1724

@HandSonic
HandSonic force-pushed the fix/1724-cache-manage-throwable branch from 307a5d2 to 73f0beb Compare July 21, 2026 08:14
@openai0229

Copy link
Copy Markdown
Contributor

The fuzzyDelete() initialization guard looks correct. However, please narrow the catch (Throwable) clause. Catching every Throwable also swallows errors such as OutOfMemoryError, StackOverflowError, and ThreadDeath, after which the application should not continue as if only the optional cache failed. If the goal is to handle NoClassDefFoundError, use a targeted clause such as catch (Exception | LinkageError e) or catch (Exception | NoClassDefFoundError e). The original StateTransitionException shown in the referenced historical issue is already covered by Exception in the current code, so a current-version reproduction or focused test for the intended Error path would also help validate this change.

…ss poisoning (OtterMind#1724)

The static initializer only caught Exception, missing Errors like
NoClassDefFoundError. Once the init failed with an Error, the class
was permanently poisoned and cache was silently disabled.

Also add init guard to fuzzyDelete() to prevent NPE when cache init
failed and fuzzyDelete is called externally.
@HandSonic
HandSonic force-pushed the fix/1724-cache-manage-throwable branch from 73f0beb to c3bdc93 Compare July 21, 2026 12:24
@HandSonic

Copy link
Copy Markdown
Contributor Author

Fixed. Changed to , and added an guard at the beginning of to prevent accessing when cache is not initialized.

@HandSonic

Copy link
Copy Markdown
Contributor Author

Fixed. Changed catch (Throwable e) to catch (Exception | LinkageError e), and added an if (!init) return; guard at the beginning of fuzzyDelete() to prevent accessing cacheManager when cache is not initialized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: 报缓存错误

2 participants