Aias00 opened a new pull request, #977:
URL: https://github.com/apache/fesod/pull/977
## Summary
Fixes #976.
When a `WriteHolder` excludes a column, the ignored branch removed from
`indexFieldMap` using the running loop counter `index` instead of the field's
own `sortedFieldMap` key. For explicit-index fields, that key
(`entry.getKey()`) equals the field's `@ExcelProperty(index)` — its
`indexFieldMap` key — so removing by the counter dropped an unrelated
explicit-index entry and left the ignored field's entry in place.
## Root cause
`ClassUtils.doDeclaredFields`:
```java
if (writeHolder.ignore(field.getFieldName(), entry.getKey())) {
ignoreSet.add(field.getFieldName());
indexFieldMap.remove(index); // BUG: 'index' is the running counter,
not the field's key
} else {
...
}
```
`indexFieldMap` is keyed by the field's explicit `@ExcelProperty(index = N)`
(see `declaredOneField`), and for explicit-index fields the `sortedFieldMap`
position `entry.getKey()` equals that index (see `buildSortedAllFieldMap`). So
the ignored field's own entry is keyed by `entry.getKey()`, not the counter.
## Fix
```java
indexFieldMap.remove(key);
```
For a field with an explicit index, `key == entry.getKey()` is its
`indexFieldMap` key, so its own entry is removed; for a field without an
explicit index, `key` is not in `indexFieldMap`, so the call is a no-op
(correct — it was never there).
The corruption is observable downstream:
`ExcelHeadProperty.initColumnProperties` passes
`indexFieldMap.containsKey(entry.getKey())` as `forceIndex` into each `Head`,
which `DefaultAnalysisEventProcessor` reads to drive head-to-column matching.
## Verification
Added
`ClassUtilsTest.test_declaredFields_WriteHolder_exclude_preservesUnrelatedExplicitIndex`:
with `ComplexEntity` (`id` index 0, `name` index 2, `email` order 10),
excluding `email` must keep `indexFieldMap` as `{0: id, 2: name}`. Before the
fix `id` (index 0) was wrongly removed; after the fix it stays. Full
`fesod-sheet` suite: `Tests run: 668, Failures: 0`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]