-
Notifications
You must be signed in to change notification settings - Fork 458
fix: ensure converter isolation across ExcelWriter and ExcelReader #740
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This pull request fixes a converter isolation bug where custom converters registered in one ExcelWriter or ExcelReader instance would leak to other instances due to shared mutable static maps.
Key Changes:
- Wrapped default converter maps with
Collections.unmodifiableMap()inDefaultConverterLoaderto prevent direct modification - Modified holder initialization to create defensive mutable copies of converter maps for each instance
- Added test case to verify converter isolation between
ExcelWriterinstances
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
fesod/src/main/java/org/apache/fesod/sheet/converters/DefaultConverterLoader.java |
Returns unmodifiable maps from loadDefaultWriteConverter() and loadAllConverter() methods to protect static converter maps |
fesod/src/main/java/org/apache/fesod/sheet/write/metadata/holder/AbstractWriteHolder.java |
Creates mutable HashMap copy from unmodifiable default converter map during holder initialization |
fesod/src/main/java/org/apache/fesod/sheet/read/metadata/holder/AbstractReadHolder.java |
Creates mutable HashMap copy from unmodifiable default converter map during holder initialization |
fesod/src/test/java/org/apache/fesod/sheet/converter/ConverterIsolationTest.java |
Adds new test to validate custom converters do not leak between ExcelWriter instances |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @Test | ||
| public void testConverterIsolation() { | ||
| ExcelWriter writer1 = FesodSheet.write(new File(TestFileUtil.getPath() + "writer1.xlsx"), TestData.class) | ||
| .registerConverter(new ConverterA()) | ||
| .build(); | ||
|
|
||
| ExcelWriter writer2 = FesodSheet.write(new File(TestFileUtil.getPath() + "writer2.xlsx"), TestData.class) | ||
| .build(); | ||
|
|
||
| boolean writer2HasConverterA = writer2.writeContext().currentWriteHolder().converterMap().values().stream() | ||
| .anyMatch(c -> c instanceof ConverterA); | ||
|
|
||
| writer1.finish(); | ||
| writer2.finish(); | ||
|
|
||
| assertFalse(writer2HasConverterA, "Custom converter should not leak between ExcelWriter instances"); | ||
| } |
Copilot
AI
Dec 17, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test only validates converter isolation for ExcelWriter instances, but the PR description and code changes indicate that the fix also applies to ExcelReader instances. Consider adding a corresponding test case for ExcelReader to ensure complete coverage of the bug fix and prevent regression in the read path.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a test for ExcelReader at 1d958e9.
Purpose of the pull request
Closes #729
Fixes converter isolation bug where custom converters registered in one
ExcelWriterorExcelReaderinstance would leak to other instances.What's changed?
DefaultConverterLoader.loadDefaultWriteConverter()andDefaultConverterLoader.loadAllConverter()to return unmodifiable mapAbstractWriteHolderandAbstractReadHolderto create mutable copies from the unmodifiable mapsConverterIsolationTestto verify converters are properly isolated between instancesChecklist