Skip to content

Conversation

@YangSiJun528
Copy link

@YangSiJun528 YangSiJun528 commented Dec 17, 2025

Purpose of the pull request

Closes #729

Fixes converter isolation bug where custom converters registered in one ExcelWriter or ExcelReader instance would leak to other instances.

What's changed?

  • Modified DefaultConverterLoader.loadDefaultWriteConverter() and DefaultConverterLoader.loadAllConverter() to return unmodifiable map
  • Modified AbstractWriteHolder and AbstractReadHolder to create mutable copies from the unmodifiable maps
  • Added ConverterIsolationTest to verify converters are properly isolated between instances

Checklist

  • I have read the Contributor Guide.
  • I have written the necessary doc or comment.
  • I have added the necessary unit tests and all cases have passed.

Copy link
Contributor

Copilot AI left a 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() in DefaultConverterLoader to 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 ExcelWriter instances

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.

Comment on lines 56 to 72
@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");
}
Copy link

Copilot AI Dec 17, 2025

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.

Copilot uses AI. Check for mistakes.
Copy link
Author

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.

@YangSiJun528 YangSiJun528 changed the title fix: prevent converter leakage between ExcelWriter instances fix: ensure converter isolation across ExcelWriter and ExcelReader Dec 17, 2025
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] Converter isolation broken - converters leak between ExcelWriter instances

1 participant