Skip to content

Classify VARCHAR failures in the temporal ResultSet getters - #576

Merged
perNyfelt merged 2 commits into
mainfrom
fix/326-temporal-getter-string-conversion
Nov 18, 2026
Merged

perNyfelt merged 2 commits into
mainfrom
fix/326-temporal-getter-string-conversion

Conversation

@perNyfelt

Copy link
Copy Markdown
Member

Fixes #326.

Problem

JParqResultSet.getDate/getTimestamp converted String values with java.sql.Date.valueOf/Timestamp.valueOf. That conversion is lenient and unclassified:

Query Getter Result
SELECT 'bad' AS x FROM mtcars LIMIT 1 getDate(1) raw IllegalArgumentException escapes JDBC
SELECT 'bad' AS x FROM mtcars LIMIT 1 getTimestamp(1) raw IllegalArgumentException: Timestamp format must be ...
SELECT '2024-02-30' AS x FROM mtcars LIMIT 1 getDate(1) silently rolls over to 2024-03-01
SELECT '25:00:00' AS x FROM mtcars LIMIT 1 getTime(1) silently rolls over to 01:00:00

Reproduced the first three on HEAD (getTime was already fixed by the #239 follow-up and now rejects 25:00:00 with 22008).

Fix

Route getDate and getTimestamp through the strict DateTimeFunctions.toDate/toTimestamp helpers — the same ones getTime already uses — and wrap failures through SqlExceptions.wrap, matching the established pattern. Both getters keep their existing supported-type set and the OffsetDateTime instant conversion; only the String path (and the resulting error contract) changes. Failures now surface as SQLDataException with 22007 (invalid format) or 22008 (out-of-range fields), and no unchecked exception escapes.

Tests

New TemporalGetStringConversionTest (jparq package, mtcars fixture):

  • all getter/value combinations from the issue table, asserting SQLDataException with the expected SQLState (this also proves no unchecked exception escapes);
  • valid VARCHAR temporals retained, including unpadded SQL fields ('2024-2-29');
  • numeric epoch values still take the millisecond path.

Verified red on the pre-fix commit (8 failures + 1 error: 6 raw IllegalArgumentException leaks, 2 silent rollovers) and green with the fix. Full mvn verify (unit + IT + checkstyle + PMD + spotless + JaCoCo) passes on Java 21.

Related: #241 (the same unchecked-leak pattern for numeric getters) remains open.

getDate and getTimestamp converted String values with java.sql Date/Time
Timestamp.valueOf, which leaked unchecked IllegalArgumentException without a
SQLState and accepted values such as 2024-02-30 or 25:00:00 that roll over
silently. Route the conversion through DateTimeFunctions.toDate/toTimestamp,
the same strict helpers getTime already uses, and wrap failures through
SqlExceptions.wrap so they surface as SQLDataException with 22007 for an
invalid format or 22008 for out-of-range fields.
@perNyfelt perNyfelt added the bug Something isn't working label Nov 18, 2026

@perNyfelt perNyfelt left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Approved. Verified on Java 21:

  • New TemporalGetStringConversionTest is red on the pre-fix JParqResultSet (8 failures + 1 error: leaked IllegalArgumentExceptions plus the 2024-02-30 rollover) and green with the fix (11/11).
  • Full mvn verify passes: unit + IT + checkstyle + PMD + spotless + JaCoCo.
  • Independently confirmed the claimed pre-fix java.sql.Date.valueOf("2024-02-30") rollover (-> 2024-03-01).

The implementation matches the established getTime pattern (classify via DateTimeFunctions.to* + SqlExceptions.wrap), preserves each getter's supported-type set exactly, and the Javadocs document the 22007/22008 contract.

Minor, non-blocking: getTime's @throws javadoc (JParqResultSet.java:1754) still omits the 22007/22008 states that the two touched methods now document — worth aligning at some point.

@perNyfelt
perNyfelt merged commit d453e28 into main Nov 18, 2026
2 checks passed
@perNyfelt
perNyfelt deleted the fix/326-temporal-getter-string-conversion branch November 18, 2026 16:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Temporal ResultSet getters leak IllegalArgumentException and roll over invalid VARCHAR dates/times

1 participant