Skip to content

fix: CsvCell crashes on java.sql.Date/Time due to unsupported toInstant()#954

Open
alaahong wants to merge 5 commits into
apache:mainfrom
alaahong:fix/csv-sql-date-conversion
Open

fix: CsvCell crashes on java.sql.Date/Time due to unsupported toInstant()#954
alaahong wants to merge 5 commits into
apache:mainfrom
alaahong:fix/csv-sql-date-conversion

Conversation

@alaahong

@alaahong alaahong commented Jul 17, 2026

Copy link
Copy Markdown
Member

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
image

What's changed?

CsvCell

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.

alaahong added 2 commits July 16, 2026 16:52
…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.
@alaahong
alaahong requested a review from Copilot July 17, 2026 11:43

Copilot AI 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.

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-case java.sql.Date and java.sql.Time conversions.
  • Add regression/unit tests covering CsvCell date/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.

Comment thread fesod-sheet/src/test/java/org/apache/fesod/sheet/format/CsvRowTest.java Outdated
Comment thread fesod-sheet/src/test/java/org/apache/fesod/sheet/format/CsvRowTest.java Outdated
Comment thread fesod-sheet/src/test/java/org/apache/fesod/sheet/format/CsvRowTest.java Outdated
Comment thread fesod-sheet/src/test/java/org/apache/fesod/sheet/format/CsvRowTest.java Outdated
alaahong added 2 commits July 17, 2026 19:48
…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

Copilot AI 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.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

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.

2 participants