Skip to content

[Enhancement] Descriptive error for unrecognized cell type attribute instead of "IllegalArgumentException: Type can not be null" #955

Description

@nkuprins

Search before asking

  • I searched in the issues and found nothing similar.

Motivation

This is about failing with a useful error, not about supporting more cell types.

A cell whose t attribute is not one of s, str, inlineStr, e, b, n aborts the whole read with an error that names neither the cell nor the attribute:

java.lang.IllegalArgumentException: Type can not be null
    at org.apache.fesod.sheet.metadata.data.ReadCellData.<init>(ReadCellData.java:78)
    at org.apache.fesod.sheet.analysis.v07.handlers.CellTagHandler.startElement(CellTagHandler.java:63)

Repro:
Any xlsx sheet that contains e.g. <c r="A1" t="d"><v>2024-05-01T00:00:00</v></c> (or t="anything")

Cause:
In CellDataTypeEnum.buildFromCellType, a missing t attribute is handled - it returns EMPTY. But when t is present with a value that isn't in the map, the lookup returns null and nothing checks for it. That null then trips the ReadCellData constructor, which is where the confusing exception comes from.

Solution

Keep failing, but say what happened. In CellTagHandler.startElement:

String cellType = attributes.getValue(ExcelXmlConstants.ATTRIBUTE_T);
CellDataTypeEnum type = CellDataTypeEnum.buildFromCellType(cellType);
if (type == null) {
    throw new ExcelAnalysisException("Unsupported cell type '" + cellType + "'");
}

Alternatives

Fall back to DIRECT_STRING when the type is null

Anything else?

No response

Are you willing to submit a PR?

  • I'm willing to submit a PR!

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions