fix(serialize): respect WARN mode in DefaultSerializeClassChecker#16177
Open
daguimu wants to merge 2 commits intoapache:3.3from
Open
fix(serialize): respect WARN mode in DefaultSerializeClassChecker#16177daguimu wants to merge 2 commits intoapache:3.3from
daguimu wants to merge 2 commits intoapache:3.3from
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## 3.3 #16177 +/- ##
============================================
- Coverage 60.80% 60.80% -0.01%
+ Complexity 11767 11760 -7
============================================
Files 1953 1953
Lines 89118 89121 +3
Branches 13444 13446 +2
============================================
Hits 54190 54190
+ Misses 29367 29362 -5
- Partials 5561 5569 +8
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
DefaultSerializeClassCheckerthrowsIllegalArgumentExceptioneven whenSerializeCheckStatusis set toWARN. The WARN mode is intended to only log warnings without blocking deserialization, but three code paths still throw exceptions unconditionally.Root Cause
Three places in
DefaultSerializeClassCheckerignore thecheckStatuswhen deciding to throw:loadClass0()disallow list check (case-sensitive, line 165): Logs a WARN-mode message but then unconditionally throwsIllegalArgumentException.loadClass0()disallow list check (case-insensitive, line 186): Same issue — warns then throws.loadClass()Serializable interface check (line 118): Only checks thecheckSerializableflag but ignorescheckStatus. In WARN mode, non-Serializable classes should be warned about, not rejected.Fix
loadClass0()disallow list checks: In WARN mode, log a warning and return the loaded class viaclassForName()instead of throwing. The warning message is updated to say "will allow to deserialize" (matching the existing non-disallowed warning at line 198).loadClass()Serializable check: Gate the exception oncheckStatus— only throw in STRICT mode (whencheckSerializableis also true). In WARN mode, downgrade fromlogger.errortologger.warn. In DISABLE mode, skip the check entirely.This makes
DefaultSerializeClassCheckerconsistent withFastjson2SecurityManager, which already handles WARN mode correctly by returning null instead of throwing.Tests Added
testDisallowedClassInWarnModeDoesNotThrow()— loadsRuntime.class(disallowed) in WARN mode, verifies no exception and class is in warnedClassestestDisallowedClassInStrictModeThrows()— confirmsRuntime.classthrows in STRICT mode (regression)testCommon()— updated:Socket.class(disallowed, non-Serializable) now loads without exception in WARN modetestStatus(),testBlockAll(),testAddBlock()— all pass unchangedImpact
Only affects deserialization behavior when
checkStatusis explicitly set toWARN. Default mode (STRICT) behavior is unchanged. Users who set WARN mode will now get the expected behavior: warnings are logged but deserialization proceeds.Fixes #15179