fix: clone DataFormatData in WriteCellStyle.merge to avoid mutating cached annotation style#957
Open
nkuprins wants to merge 1 commit into
Open
Conversation
…ached annotation style A registered cell style strategy could permanently change the cached @ContentStyle(dataFormat) of a field, because WriteCellStyle.merge copied the source DataFormatData by reference and a later merge then wrote into the shared object. Clone it like writeFont on the line below. Closes apache#956
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request fixes a subtle style-caching mutation bug in fesod-sheet where WriteCellStyle.merge previously copied DataFormatData by reference, allowing later merges (e.g., from a HorizontalCellStyleStrategy) to corrupt the cached annotation-driven @ContentStyle(dataFormat) metadata and produce incorrect number formats.
Changes:
- Clone
DataFormatDatawhen assigning it duringWriteCellStyle.mergeto prevent shared-reference mutation of cached annotation style metadata. - Add
ContentStyleDataFormatPollutionTestregression coverage to ensure the annotation format survives (1) within the same write when a strategy provides no format, and (2) across writes whenCacheLocationEnum.MEMORYis used.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
fesod-sheet/src/main/java/org/apache/fesod/sheet/write/metadata/style/WriteCellStyle.java |
Prevents cached annotation DataFormatData from being aliased/mutated by cloning on merge assignment. |
fesod-sheet/src/test/java/org/apache/fesod/sheet/style/ContentStyleDataFormatPollutionTest.java |
Adds regression tests that assert on the written file’s number formats to prevent recurrence (same-write + MEMORY-cache scenarios). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Purpose of the pull request
Closed: #956
What's changed?
WriteCellStyle.mergecopied the source'sDataFormatDatainto the target by reference. Because the annotation-driven style source is parsed once and cached, a later merge from another style source (e.g. a registeredHorizontalCellStyleStrategy) wrote into that shared object and permanently changed the cached@ContentStyle(dataFormat)- producing the wrong number format on rows where the strategy defines no format, and (withCacheLocationEnum.MEMORY) on later, unrelated writes of the same bean class.The fix clones the
DataFormatDatabefore assigning it, exactly likewriteFontis already cloned a few lines below in the same method:Added
ContentStyleDataFormatPollutionTestwith two regression tests that assert on the number format of the written file (via the testkit'sExcelAssertions):annotationFormatSurvivesStyleStrategyInSameWrite- default config: a row whose strategy style has no data format must keep the annotation's#,##0.00.annotationFormatSurvivesAcrossWritesWithMemoryCache-MEMORYcache location: a follow-up write with no custom handlers must keep the annotation's format.Both tests fail on
main(format comes out0.00) and pass with the fix. The fullfesod-sheetsuite passes with the fix applied (673 tests, 0 failures, 0 errors, 0 skipped), confirming no behavior change for styles that don't involve a sharedDataFormatData.Checklist