Conversation
skytin1004
left a comment
There was a problem hiding this comment.
Reviewed and verified locally.
The focused tests pass locally (4 tests). I also temporarily reverted the handler change and confirmed that the end-to-end test reproduces the original NumberFormatException in CellTagHandler.
The fix is narrowly scoped, and the regression coverage verifies both the internal handler and the public read path. I also confirmed that valid numeric style indexes are still handled through the existing lookup path, so the change does not affect the normal style lookup behavior.
LGTM.
|
POI doesn't actually provide fault tolerance for this scenario during streaming reads: Looking at the source code of Therefore, mentioning "matching POI's lenient behavior" in the comment might not be entirely accurate. In addition, while I agree that we should be lenient with non-standard files missing |
|
@bengbengbalabalabeng Thanks for the source-level pointer — you're right on both points, and I verified your reading locally before replying. On the wording. "Matches POI's lenient behavior" was inaccurate, and the test file masked it. I reproduced the scenario against POI 5.5.1 with a structurally complete xlsx (styles.xml present, one cellXf, middle cell
The accurate statement is: fesod deliberately goes further than POI here — a malformed style index never aborts the read, both in structurally complete files and in files missing styles.xml. I've updated the PR description accordingly. On the test gap. Agreed the test only covered the no-styles.xml case, which is not the scenario the report came from. The latest commit (fead136) adds a variant with a structurally complete file (styles.xml + one cellXf inside the zip): all 3 rows are read and the corrupt cell's value On
That said, if you or the maintainers prefer the stricter reading — malformed data in a structurally complete file should lose format info entirely — I'm glad to switch. Happy to follow your call. |
|
I agree with using |
| // whole file read; fall back to the default format, matching POI's lenient behavior. | ||
| dateFormatIndexInteger = DEFAULT_FORMAT_INDEX; |
There was a problem hiding this comment.
I noticed that this comment still refers to POI's lenient behavior, although the updated PR description now explains that Fesod is intentionally more lenient here. How about updating it to this?
| // whole file read; fall back to the default format, matching POI's lenient behavior. | |
| dateFormatIndexInteger = DEFAULT_FORMAT_INDEX; | |
| // A malformed style index (e.g. produced by third-party tools) must not abort the | |
| // whole file read. Treat it like a missing style index and use the default format. |
Fixes #355
What changes were proposed in this pull request?
CellTagHandlerparses a cell'ssattribute (style index) with a bareInteger.parseInt. A non-numeric value — as produced by some third-party tools — threwNumberFormatExceptionand aborted the whole file read at the first corrupt cell (in the report: reading stopped at row 3218 of 3000+ rows).The parse now falls back to the default format index (
0) onNumberFormatException: a corrupt style index only loses that cell's style info, while the cell value and all subsequent rows are still read. This follows the reporter's suggestion, and is deliberately more lenient than POI — POI's native streaming read throwsNumberFormatExceptionon the same input when styles.xml is present, and only reads such a file completely when styles.xml is absent.How was this patch tested?
CellTagHandlerTest(2 new unit tests): non-numericsfalls back todataFormatData(0)without throwing; numericskeeps the exact lookup.CorruptStyleIndexReadTest(new end-to-end test, two variants): a hand-built xlsx whose middle row carriess="abc"is read completely — both the minimal variant (no styles.xml) and the structurally complete variant (styles.xml + one cellXf present).NumberFormatException: For input string: "abc"); with the fix they pass.fesod-sheetsuite: 898/898 green.spotless:checkandjavadocpass.Notes