fix: CsvCell crashes on java.sql.Date/Time due to unsupported toInstant()#954
Open
alaahong wants to merge 5 commits into
Open
fix: CsvCell crashes on java.sql.Date/Time due to unsupported toInstant()#954alaahong wants to merge 5 commits into
alaahong wants to merge 5 commits into
Conversation
…nt() The SQL date type fix in 6374a8c was only applied to WriteCellData, not to CsvCell.setCellValueImpl(Date). The old code calls value.toInstant() unconditionally, which throws UnsupportedOperationException for java.sql.Date and java.sql.Time on Java 9+ (these types override toInstant() to throw because they represent date-only/time-only values). Fix: Add the same instanceof checks as WriteCellData - use toLocalDate() .atStartOfDay() for java.sql.Date and toLocalTime().atDate(...) for java.sql.Time, falling back to toInstant() for regular java.util.Date. Tests: Add CsvRowTest.testCsvCellSqlDateConversion and testCsvCellSqlTimeConversion to verify correct conversion.
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a Java 9+ crash when writing CSV cells containing java.sql.Date / java.sql.Time by avoiding unconditional toInstant() calls in CsvCell and aligning behavior with the earlier WriteCellData fix.
Changes:
- Update
CsvCell.setCellValueImpl(Date)to special-casejava.sql.Dateandjava.sql.Timeconversions. - Add regression/unit tests covering
CsvCelldate/time conversions and a real-file CSV write/readback scenario.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| fesod-sheet/src/main/java/org/apache/fesod/sheet/metadata/csv/CsvCell.java | Adds SQL Date/Time handling to avoid toInstant() UnsupportedOperationException on Java 9+. |
| fesod-sheet/src/test/java/org/apache/fesod/sheet/format/CsvRowTest.java | Adds regression tests validating CsvCell conversion behavior and integration-style CSV output. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…WriteBasicParameter Updated the import statements in SKILL.md to replace references to cn.idev.excel with org.apache.fesod for ReadBasicParameter and WriteBasicParameter. This change aligns the code with the new Fesod package structure.
- Replace FileWriter with Files.newBufferedWriter(path, UTF_8) to ensure platform-independent encoding consistent with CsvWorkbook's UTF-8 config - Replace deprecated java.util.Date(int,int,...) constructors with Calendar-based construction to avoid deprecation warnings
3 tasks
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
The SQL date type fix in #912 was only applied to WriteCellData, not
to CsvCell.setCellValueImpl(Date). The old code calls value.toInstant()
unconditionally, which throws UnsupportedOperationException for
java.sql.Date and java.sql.Time on Java 9+ (these types override
toInstant() to throw because they represent date-only/time-only values).
Fix: Add the same instanceof checks as WriteCellData - use toLocalDate()
.atStartOfDay() for java.sql.Date and toLocalTime().atDate(...) for
java.sql.Time, falling back to toInstant() for regular java.util.Date.
Before Change

What's changed?
CsvCell
Checklist