fix: descriptive error for unrecognized cell type attribute#965
Open
nkuprins wants to merge 2 commits into
Open
fix: descriptive error for unrecognized cell type attribute#965nkuprins wants to merge 2 commits into
nkuprins wants to merge 2 commits into
Conversation
An xlsx cell whose t attribute is not one of the recognized types (s, str, inlineStr, e, b, n) caused CellDataTypeEnum.buildFromCellType to return null. The very next line then tripped the ReadCellData constructor with a confusing 'IllegalArgumentException: Type can not be null' that named neither the cell nor the offending attribute. Detect the null in CellTagHandler and throw an ExcelAnalysisException that names the invalid type and the offending cell (by its Excel reference, e.g. B4), and document the nullable return of buildFromCellType so callers know to handle it. The read still aborts at the same point; only the exception type and message change. Closes apache#955
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request improves diagnostics when reading .xlsx files by detecting unrecognized cell t attribute values during SAX parsing and throwing a descriptive ExcelAnalysisException that includes both the invalid type and the cell reference (addressing issue #955).
Changes:
- Add a null-check in
CellTagHandler.startElementforCellDataTypeEnum.buildFromCellType(...)and throw anExcelAnalysisExceptionwith cell/type context when the type is unrecognized. - Document in
CellDataTypeEnum.buildFromCellTypeJavadoc that the method may returnnullfor unknowntvalues (andEMPTYfor missing/emptyt). - Add a regression unit test ensuring the thrown error message includes both the unknown type and the cell reference.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
fesod-sheet/src/main/java/org/apache/fesod/sheet/analysis/v07/handlers/CellTagHandler.java |
Throws a descriptive ExcelAnalysisException when an unknown cell t value would otherwise lead to a null type and a confusing downstream exception. |
fesod-sheet/src/main/java/org/apache/fesod/sheet/enums/CellDataTypeEnum.java |
Clarifies contract: may return null for unrecognized t values, EMPTY when t is empty/missing. |
fesod-sheet/src/test/java/org/apache/fesod/sheet/analysis/v07/handlers/CellTagHandlerTest.java |
Adds regression coverage verifying the new exception message includes both invalid type and cell reference. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Purpose of the pull request
Closed: #955
What's changed?
An
.xlsxcell whosetattribute isn't a recognized type (s,str,inlineStr,e,b,n) madeCellDataTypeEnum.buildFromCellTypereturnnull, whichCellTagHandlerpassed straight intonew ReadCellData<>(type), leading toIllegalArgumentException: Type can not be null, which names neither the cell nor the attribute.CellTagHandler.startElementnow detects thenulland throws anExcelAnalysisExceptionthat names the type and the cell:Following the discussion with @bengbengbalabalabeng on the issue, the check lives in the handler (rather than centralised in
CellDataTypeEnum.buildFromCellType), so the message can point at the exact cell. AndCellDataTypeEnum.buildFromCellTypeJavadoc now documents that it may returnnullfor an unrecognised type.Covered by
CellTagHandlerTest.Checklist