Repository navigation
Classify VARCHAR failures in the temporal ResultSet getters - #576
Merged
Merged
Conversation
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
commented
Nov 18, 2026
perNyfelt
left a comment
Member
Author
There was a problem hiding this comment.
Approved. Verified on Java 21:
- New
TemporalGetStringConversionTestis red on the pre-fixJParqResultSet(8 failures + 1 error: leakedIllegalArgumentExceptions plus the2024-02-30rollover) and green with the fix (11/11). - Full
mvn verifypasses: 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.
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.
Fixes #326.
Problem
JParqResultSet.getDate/getTimestampconvertedStringvalues withjava.sql.Date.valueOf/Timestamp.valueOf. That conversion is lenient and unclassified:SELECT 'bad' AS x FROM mtcars LIMIT 1getDate(1)IllegalArgumentExceptionescapes JDBCSELECT 'bad' AS x FROM mtcars LIMIT 1getTimestamp(1)IllegalArgumentException: Timestamp format must be ...SELECT '2024-02-30' AS x FROM mtcars LIMIT 1getDate(1)2024-03-01SELECT '25:00:00' AS x FROM mtcars LIMIT 1getTime(1)01:00:00Reproduced the first three on HEAD (
getTimewas already fixed by the #239 follow-up and now rejects25:00:00with 22008).Fix
Route
getDateandgetTimestampthrough the strictDateTimeFunctions.toDate/toTimestamphelpers — the same onesgetTimealready uses — and wrap failures throughSqlExceptions.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 asSQLDataExceptionwith 22007 (invalid format) or 22008 (out-of-range fields), and no unchecked exception escapes.Tests
New
TemporalGetStringConversionTest(jparq package, mtcars fixture):SQLDataExceptionwith the expected SQLState (this also proves no unchecked exception escapes);'2024-2-29');Verified red on the pre-fix commit (8 failures + 1 error: 6 raw
IllegalArgumentExceptionleaks, 2 silent rollovers) and green with the fix. Fullmvn verify(unit + IT + checkstyle + PMD + spotless + JaCoCo) passes on Java 21.Related: #241 (the same unchecked-leak pattern for numeric getters) remains open.