Repository navigation
fix(sheet): read the OOXML ISO date cell type instead of aborting - #1285
Conversation
skytin1004
left a comment
There was a problem hiding this comment.
Hi @Sean-Walker0, I tested this on Windows with Java 11. The product fix works, but the new integration test fails because File.separator creates an invalid classpath resource path. Could you please use / or the existing resource helper so the test also runs on Windows?
Mikkey-f
left a comment
There was a problem hiding this comment.
Thanks @Sean-Walker0 — I reproduced skytin1004's Windows failure and verified the product fix independently (Windows 11, JDK 17).
Reproduction (PR head as-is)
IsoDateCellTypeTest fails 2/3 on Windows:
ExcelCommonException: Convert excel format exception...
Caused by: ExcelAnalysisException: File ...\target\test-classes\typed%5cnumber-cell.xlsx not exists.
The backslash from File.separator is URL-encoded to %5c in the classpath resource URL, so new File(url.getFile()) points at a non-existent file.
Verification
- With
resource()changed to"typed/" + name:IsoDateCellTypeTest3/3 green. - With the routing change reverted (patched test left in place):
Invalid cell data type: 'd' in cell A1— the product fix is what makes the ISO cell readable.
Suggestion
AbstractExcelTest already provides readFile(String resourcePath), which normalizes / and File.separator segments and copies the resource into the per-test temp dir (robust when resources live in a JAR). Since the test already extends AbstractExcelTest, the custom resource() helper can be replaced with readFile("typed/" + name) — that fixes the Windows failure and the JAR case in one go.
Everything else looks good to me: routing "d" to DIRECT_STRING matches the str/inlineStr handling, and the unit test pins unknown types to null.
c759d1b to
e31f218
Compare
|
Fixed — the test now loads the crafted workbooks through the existing |
773298a to
3288168
Compare
|
Thanks for the contribution! The implementation looks good to me. I only have a few documentation/comment wording suggestions for accuracy and clarity:
The https://ecma-international.org/publications-and-standards/standards/ecma-376/
I'm not sure "first-class type" is the most accurate description here. Apache POI v5.x uses the ECMA-376 5th edition OOXML schemas (Transitional), in which the |
skytin1004
left a comment
There was a problem hiding this comment.
Hi @Sean-Walker0, I re-reviewed the latest commit. The Windows resource-path issue is fixed by using the existing readFile("typed/" + name) helper, and the implementation and tests look good to me.
I agree with @bengbengbalabalabeng's accuracy notes: t="d" should be described as Strict-schema support or compatibility handling, rather than as a generally valid OOXML type or explicit POI support. Please update the PR description and the new source/test comments accordingly. This is documentation wording only, so I don't think it needs to block the implementation.
|
Thanks for the corrections — both wording issues are fixed:
No code behavior change (the comment text update is folded into the existing commit). |
3288168 to
cec76cb
Compare
ECMA-376 section 18.18.11 defines the cell type t="d": a date cell holding an ISO-8601 string. The type routing map did not know it, so CellTagHandler threw 'Invalid cell data type: d' and aborted the entire read on the first such cell - a spec-valid file that POI itself reads. Excel does not write t="d", but third-party OOXML producers do. Route "d" to DIRECT_STRING, keeping the ISO-8601 text as the cell value like the other non-shared-string text forms. Genuinely unknown types still throw, preserving the intent of the unknown-type guard. Verified with IsoDateCellTypeTest (a crafted spec-valid workbook with a t="d" cell aborts the read before the change and reads the ISO text after; a plain-number workbook and the unknown-type rejection are pinned on both sides) plus the full fesod-sheet suite (1792 tests) and spotless:check.
cec76cb to
13c0f8a
Compare
Purpose of the pull request
The
ST_CellTypevalued- an ISO-8601 date-string cell, supported since ECMA-376 2nd edition and, from the 4th edition on, retained only in the Strict schema (removed from Transitional) - was not known to the type routing map, soCellTagHandlerthrewInvalid cell data type: 'd' in cell A1and aborted the entire read on the first such cell. A single such cell killed the whole file read.Excel itself does not write
t="d"(it writes date serials), but the type is part of the OOXML schema and third-party OOXML producers emit it; POI's own SAX reader (XSSFSheetXMLHandler) does not recognizedexplicitly - the raw text only survives as a compatibility fallback when the numeric parse fails.Reproduced on current main with a minimal spec-valid workbook (hand-crafted OPC package, one
t="d"cell): the read throws; the same package with a plain number cell reads fine.No issue exists for this yet; found while auditing the XLSX cell-type routing.
What's changed?
CellDataTypeEnum.TYPE_ROUTING_MAProutes"d"toDIRECT_STRING— the ISO-8601 text is kept as the cell value, matching how the other non-shared-string text forms (str,inlineStr) are handled. Genuinely unknown types still throw, preserving the intent of the unknown-type guard (#965).Checklist
Verifying this change
IsoDateCellTypeTest:isoDateCellReadsAsText— red before (ExcelAnalysisException: Invalid cell data type: 'd' in cell A1), green after: the crafted workbook reads and the cell yields the ISO text;plainNumberCellStillReads— pins ordinary reads of the same package shape, green on both sides;isoDateTypeRoutesToDirectString— unit-pins the routing ("d"->DIRECT_STRING) and that unknown types still answer null, green on both sides of the second assertion and red on the first before the change../mvnw clean package -B -Dmaven.test.skip=false -pl fesod-common,fesod-shaded,fesod-sheet: 1792 tests, 0 failures, 0 errors../mvnw -pl fesod-sheet spotless:check: clean.Notes
t="d"cells now read instead of throwing. The date arrives as its ISO-8601 text (not converted to a serial), which is the least-surprising lossless representation for a cell whose spec-defined payload is that string.CellDataTypeEnum; perf(sheet): cut per-cell allocation on the XLSX read hot path #1208/fix: fall back to default format index on malformed style index (#355) #1059 touchCellTagHandlerin hunks strictly below the type-routing lines and their diffs merge cleanly.