fix: remove indexFieldMap entry by field key, not running counter - #977
Merged
delei merged 2 commits intoAug 8, 2026
Merged
Conversation
…ache#976) When a WriteHolder excludes a column, the ignored branch removed from indexFieldMap using the running loop counter instead of the field's own sortedFieldMap key (which equals its explicit @ExcelProperty(index) for explicit-index fields). This dropped an unrelated explicit-index entry and left the ignored field's entry in place, corrupting Head.forceIndex downstream. Remove by entry.getKey() instead; add a regression test.
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
Suppressed comments (1)
fesod-sheet/src/main/java/org/apache/fesod/sheet/util/ClassUtils.java:370
- The new explanatory comment has a small grammar issue ("explicit-index fields equals …") and is a bit hard to read. Consider rephrasing it for clarity while keeping the intent.
// indexFieldMap is keyed by the field's explicit @ExcelProperty(index), which for
// explicit-index fields equals the sortedFieldMap position (entry.getKey()); remove
// by that key, not the running counter, otherwise an unrelated explicit-index entry
// is dropped and the ignored field's entry may survive.
3 tasks
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.
Summary
Fixes #976.
When a
WriteHolderexcludes a column, the ignored branch removed fromindexFieldMapusing the running loop counterindexinstead of the field's ownsortedFieldMapkey. For explicit-index fields, that key (entry.getKey()) equals the field's@ExcelProperty(index)— itsindexFieldMapkey — so removing by the counter dropped an unrelated explicit-index entry and left the ignored field's entry in place.Root cause
ClassUtils.doDeclaredFields:indexFieldMapis keyed by the field's explicit@ExcelProperty(index = N)(seedeclaredOneField), and for explicit-index fields thesortedFieldMappositionentry.getKey()equals that index (seebuildSortedAllFieldMap). So the ignored field's own entry is keyed byentry.getKey(), not the counter.Fix
For a field with an explicit index,
key == entry.getKey()is itsindexFieldMapkey, so its own entry is removed; for a field without an explicit index,keyis not inindexFieldMap, so the call is a no-op (correct — it was never there).The corruption is observable downstream:
ExcelHeadProperty.initColumnPropertiespassesindexFieldMap.containsKey(entry.getKey())asforceIndexinto eachHead, whichDefaultAnalysisEventProcessorreads to drive head-to-column matching.Verification
Added
ClassUtilsTest.test_declaredFields_WriteHolder_exclude_preservesUnrelatedExplicitIndex: withComplexEntity(idindex 0,nameindex 2,emailorder 10), excludingemailmust keepindexFieldMapas{0: id, 2: name}. Before the fixid(index 0) was wrongly removed; after the fix it stays. Fullfesod-sheetsuite:Tests run: 668, Failures: 0.