You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@fesod.apache.org by "Mikkey-f (via GitHub)" <gi...@apache.org> on 2026/08/30 09:31:01 UTC

[PR] fix: fall back to default format index on malformed style index (#355) [fesod]

Mikkey-f opened a new pull request, #1059:
URL: https://github.com/apache/fesod/pull/1059

   **Fixes #355**
   
   ### What changes were proposed in this pull request?
   
   `CellTagHandler` parses a cell's `s` attribute (style index) with a bare `Integer.parseInt`. A non-numeric value — as produced by some third-party tools — threw `NumberFormatException` and 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`) on `NumberFormatException`: 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 matches POI's lenient behavior (POI reads the same file completely, with the corrupt cell read as empty).
   
   ### How was this patch tested?
   
   - `CellTagHandlerTest` (2 new unit tests): non-numeric `s` falls back to `dataFormatData(0)` without throwing; numeric `s` keeps the exact lookup.
   - `CorruptStyleIndexReadTest` (new end-to-end test): a minimal hand-built xlsx whose middle row carries `s="abc"` is read completely — all 3 rows returned.
   - Red/green check: on the pre-fix code the e2e test fails with the exact exception from the report (`NumberFormatException: For input string: "abc"`); with the fix it passes.
   - Full `fesod-sheet` suite: 915/915 green. `spotless:check` and `javadoc` pass.
   
   ### Notes
   
   - Zero impact on valid files: the numeric parse path is untouched.
   - No API change, no new dependencies.
   


-- 
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: commits-unsubscribe@fesod.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fesod.apache.org
For additional commands, e-mail: commits-help@fesod.apache.org


Re: [PR] fix: fall back to default format index on malformed style index (#355) [fesod]

Posted by "skytin1004 (via GitHub)" <gi...@apache.org>.
skytin1004 commented on PR #1059:
URL: https://github.com/apache/fesod/pull/1059#issuecomment-5975403531

   I agree with using `0` here. A malformed `s` value means there is no usable style index, and a missing `s` already follows the same fallback path.


-- 
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: commits-unsubscribe@fesod.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fesod.apache.org
For additional commands, e-mail: commits-help@fesod.apache.org


Re: [PR] fix: fall back to default format index on malformed style index (#355) [fesod]

Posted by "bengbengbalabalabeng (via GitHub)" <gi...@apache.org>.
bengbengbalabalabeng commented on PR #1059:
URL: https://github.com/apache/fesod/pull/1059#issuecomment-5679785705

   POI doesn't actually provide fault tolerance for this scenario during streaming reads:
   
   Looking at the source code of `XSSFSheetXMLHandler`, reading the test XLSX file with POI’s native streaming API only succeeds because the test file lacks a `styles.xml`. Consequently, `stylesTable` is `null`, which naturally bypasses the style resolution logic. In real-world scenarios, however, as long as `styles.xml` is present, POI will still throw a `NumberFormatException` and abort the read when encountering `s="abc"`.
   
   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 `styles.xml` (ensuring unstyled sheets can still be processed), handling malformed data like `s="abc"` in a structurally complete file is a different story. Whether the framework should catch this exception—and whether it should fall back to `DEFAULT_FORMAT_INDEX = 0` or simply skip it (leave it as `null`)—is probably worth further discussion.


-- 
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: commits-unsubscribe@fesod.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fesod.apache.org
For additional commands, e-mail: commits-help@fesod.apache.org


Re: [PR] fix: fall back to default format index on malformed style index (#355) [fesod]

Posted by "skytin1004 (via GitHub)" <gi...@apache.org>.
skytin1004 commented on code in PR #1059:
URL: https://github.com/apache/fesod/pull/1059#discussion_r4255137184


##########
fesod-sheet/src/main/java/org/apache/fesod/sheet/analysis/v07/handlers/CellTagHandler.java:
##########
@@ -74,7 +74,13 @@ public void startElement(XlsxReadContext xlsxReadContext, String name, Attribute
         if (StringUtils.isEmpty(dateFormatIndex)) {
             dateFormatIndexInteger = DEFAULT_FORMAT_INDEX;
         } else {
-            dateFormatIndexInteger = Integer.parseInt(dateFormatIndex);
+            try {
+                dateFormatIndexInteger = Integer.parseInt(dateFormatIndex);
+            } catch (NumberFormatException e) {
+                // A malformed style index (e.g. produced by third-party tools) must not abort the
+                // whole file read; fall back to the default format, matching POI's lenient behavior.
+                dateFormatIndexInteger = DEFAULT_FORMAT_INDEX;

Review Comment:
   Thanks for the update @Mikkey-f. Look good to me and address my concerns.



-- 
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: commits-unsubscribe@fesod.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fesod.apache.org
For additional commands, e-mail: commits-help@fesod.apache.org


Re: [PR] fix: fall back to default format index on malformed style index (#355) [fesod]

Posted by "Mikkey-f (via GitHub) via commits" <co...@fesod.apache.org>.
Mikkey-f commented on PR #1059:
URL: https://github.com/apache/fesod/pull/1059#issuecomment-6822504820

   Hi @delei — a status check on this one. The earlier approval was dismissed when I pushed the test/documentation follow-ups in October, so it needs a fresh review. bengbengbalabalabeng's question about `DEFAULT_FORMAT_INDEX = 0` vs `null` is answered above: a malformed `s` falls back to index 0 (General), the value is read identically, and a missing `s` already follows the same path. skytin1004 agreed with keeping 0, and the tests cover both a complete file with `styles.xml` and the minimal one without it. CI is green and the branch is mergeable. Could you take a look, or let me know if you'd rather close it? I'm happy to switch to `null` if that's the preference.


-- 
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: commits-unsubscribe@fesod.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fesod.apache.org
For additional commands, e-mail: commits-help@fesod.apache.org


Re: [PR] fix: fall back to default format index on malformed style index (#355) [fesod]

Posted by "skytin1004 (via GitHub)" <gi...@apache.org>.
skytin1004 commented on code in PR #1059:
URL: https://github.com/apache/fesod/pull/1059#discussion_r4175692629


##########
fesod-sheet/src/main/java/org/apache/fesod/sheet/analysis/v07/handlers/CellTagHandler.java:
##########
@@ -74,7 +74,13 @@ public void startElement(XlsxReadContext xlsxReadContext, String name, Attribute
         if (StringUtils.isEmpty(dateFormatIndex)) {
             dateFormatIndexInteger = DEFAULT_FORMAT_INDEX;
         } else {
-            dateFormatIndexInteger = Integer.parseInt(dateFormatIndex);
+            try {
+                dateFormatIndexInteger = Integer.parseInt(dateFormatIndex);
+            } catch (NumberFormatException e) {
+                // A malformed style index (e.g. produced by third-party tools) must not abort the
+                // whole file read; fall back to the default format, matching POI's lenient behavior.
+                dateFormatIndexInteger = DEFAULT_FORMAT_INDEX;

Review 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?
   
   ```suggestion
   // 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.
   ```



-- 
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: commits-unsubscribe@fesod.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fesod.apache.org
For additional commands, e-mail: commits-help@fesod.apache.org


Re: [PR] fix: fall back to default format index on malformed style index (#355) [fesod]

Posted by "Mikkey-f (via GitHub)" <gi...@apache.org>.
Mikkey-f commented on code in PR #1059:
URL: https://github.com/apache/fesod/pull/1059#discussion_r4241027583


##########
fesod-sheet/src/main/java/org/apache/fesod/sheet/analysis/v07/handlers/CellTagHandler.java:
##########
@@ -74,7 +74,13 @@ public void startElement(XlsxReadContext xlsxReadContext, String name, Attribute
         if (StringUtils.isEmpty(dateFormatIndex)) {
             dateFormatIndexInteger = DEFAULT_FORMAT_INDEX;
         } else {
-            dateFormatIndexInteger = Integer.parseInt(dateFormatIndex);
+            try {
+                dateFormatIndexInteger = Integer.parseInt(dateFormatIndex);
+            } catch (NumberFormatException e) {
+                // A malformed style index (e.g. produced by third-party tools) must not abort the
+                // whole file read; fall back to the default format, matching POI's lenient behavior.
+                dateFormatIndexInteger = DEFAULT_FORMAT_INDEX;

Review Comment:
   Applied, thanks — good catch. That clause was the same inaccuracy bengbeng flagged for the description (it only holds for files without styles.xml, which is what the original minimal test masked), and your wording states the actual rationale better.
   
   While re-reading the diff I also fixed a fixture detail in the same area: the e2e sheet had row 3 at s="1" while styles.xml declares a single cellXf, so not all style indexes were resolvable as the class javadoc claims. It now uses s="0"; the test class javadoc keeps its POI reference, since there it is accurate.
   
   Committed in 7a6d783f (comment) and bab30734 (fixture).



-- 
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: commits-unsubscribe@fesod.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fesod.apache.org
For additional commands, e-mail: commits-help@fesod.apache.org


Re: [PR] fix: fall back to default format index on malformed style index (#355) [fesod]

Posted by "Mikkey-f (via GitHub)" <gi...@apache.org>.
Mikkey-f commented on PR #1059:
URL: https://github.com/apache/fesod/pull/1059#issuecomment-6395277671

   Hi @bengbengbalabalabeng — a gentle follow-up on the `DEFAULT_FORMAT_INDEX = 0` vs `null` question you raised on 15 Sep. We kept the fallback-to-0 behavior for the reasons in the reply above, and the tests now cover both a structurally complete file (with `styles.xml`) and the minimal one without it, so the current behavior is pinned.
   
   The PR is green and mergeable. If you still prefer `null` for a malformed `s` in a complete file, I'm happy to switch it — otherwise would fallback-to-0 be acceptable to merge?
   


-- 
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: commits-unsubscribe@fesod.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fesod.apache.org
For additional commands, e-mail: commits-help@fesod.apache.org


Re: [PR] fix: fall back to default format index on malformed style index (#355) [fesod]

Posted by "Mikkey-f (via GitHub)" <gi...@apache.org>.
Mikkey-f commented on PR #1059:
URL: https://github.com/apache/fesod/pull/1059#issuecomment-5967917061

   @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 `s="abc"`):
   
   - **POI with styles.xml present**: native streaming read (`XSSFReader` + `XSSFSheetXMLHandler`) throws `NumberFormatException: For input string: "abc"` and aborts — even the rows after the corrupt cell are lost.
   - **POI without styles.xml**: reads the file completely (3/3 rows) — which is exactly why the e2e test in this PR passed: it was built minimal and deliberately has no styles.xml, so format resolution is bypassed.
   
   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 (fead1362) 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 `2` comes back correctly. Red/green: on pre-fix code the same file reproduces the report's `NumberFormatException`; with the fix it passes.
   
   **On `0` vs `null`.** Agreed this deserves settling explicitly. My reasoning in favor of `DEFAULT_FORMAT_INDEX`:
   
   1. It keeps the malformed-`s` case on the exact path the code already takes when `s` is absent (`StringUtils.isEmpty(dateFormatIndex) → DEFAULT_FORMAT_INDEX`). A malformed index is semantically "no usable style index", so treating it like a missing one is the most consistent reading.
   2. Downstream is null-safe either way (`StringNumberConverter` guards on null; files without styles.xml already yield `null` from `dataFormatData(...)`), so both are workable — but `null` would introduce a third state (malformed ≠ missing) and bypass the existing default-format path.
   3. The difference is confined to the cell's format metadata (index 0, typically "General"); the value is read identically.
   
   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.
   


-- 
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: commits-unsubscribe@fesod.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fesod.apache.org
For additional commands, e-mail: commits-help@fesod.apache.org