Skip to content

fix: keep the coordinates in a cloned ReadCellData - #1132

Open
CodeMan-cmd wants to merge 1 commit into
apache:mainfrom
CodeMan-cmd:fix-read-cell-data-coordinates
Open

CodeMan-cmd wants to merge 1 commit into
apache:mainfrom
CodeMan-cmd:fix-read-cell-data-coordinates

Conversation

@CodeMan-cmd

Copy link
Copy Markdown

Purpose of the pull request

Closed: #1131

What's changed?

A cell read as ReadCellData (a model field typed ReadCellData/CellData, or readDefaultReturn(READ_CELL_DATA)) is produced by ConverterUtils.convertToJavaObject, which clones the parsed cell. ReadCellData.clone() copied the type, the value, the data format and the formula but not rowIndex/columnIndex, so every ReadCellData handed to a listener had null coordinates even though the parsers set them and convertToJavaObject already receives both indexes as arguments. The clone now keeps them, which also matches WriteCellData, where the coordinates are set on the way out.

Measured before the change, same test, on all three formats: date(row=null,col=null) integer1(row=null,col=null) formula(row=null,col=null); after the change: date(row=1,col=0) integer1(row=1,col=1) formula(row=1,col=3).

Tests:

  • CellDataDataTest asserts the coordinates of the ReadCellData fields of a round trip, for xlsx, xls and csv.
  • ReadCellDataTest.cloneKeepsCoordinates is a unit test for the clone itself.

Without the fix 4 of the 5 new assertions fail, with the fix all of them pass.

Local verification with Temurin 1.8.0_472:

  • ./mvnw clean package -B -Dmaven.test.skip=false -pl fesod-common,fesod-shaded,fesod-sheet -> 917 tests, 0 failures
  • ./mvnw spotless:check -> Build success

Checklist

  • I have read the Contributor Guide.
  • I have written the necessary doc or comment.
  • I have added the necessary unit tests and all cases have passed.

A cell read into a ReadCellData field, or read with READ_CELL_DATA, went through ReadCellData.clone(), which copied the value and the format but not rowIndex and columnIndex. The parsers do set them (CellTagHandler, FormulaRecordHandler, BoolErrRecordHandler, CsvExcelReadExecutor), so the coordinates were available in the very call that clones the cell, and every ReadCellData handed to a listener came back with null coordinates. The clone now keeps them, which also matches WriteCellData, where the coordinates are set on the way out.

@skytin1004 skytin1004 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix. I reproduced the missing coordinates with the pre-fix implementation and verified that this change preserves the row and column indexes for XLSX, XLS, and CSV. All tests passed locally with Java 11. LGTM.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] A cell read into a ReadCellData field loses its row and column index

2 participants