Menu ▾ ▴

#1764 getObject(OffsetDateTime.class) changes historical instants or throws for Julian leap-day labels

version 2.5.x
open-fixed
None
5
5 hours ago
2026-11-14
No

Tested with 2.7.5 RC3 and trunk r6855

Reading TIMESTAMP WITH TIME ZONE through ResultSet.getObject(..., OffsetDateTime.class) changes a correctly stored historical instant, or throws DateTimeException. The numeric offset and fractional nanoseconds survive in the shifted example, but the date is interpreted using a different calendar.

Related report: https://sourceforge.net/p/hsqldb/bugs/1763/
This is a separate extraction case: native OffsetDateTime input stores the expected epoch. #1763 concerns LocalDate/LocalDateTime input changing SQL date fields.

The attached HsqlOffsetDateTimeReproducer.java uses only JDBC and an in-memory database.

Environment and version results

  • Eclipse Temurin OpenJDK 25+36-LTS, macOS.
  • 2.6.1: all four rows pass both indexed and column-label typed extraction.
  • 2.7.0 and 2.7.4: historical rows fail, cutover/modern controls pass.
  • Current published development artifact 2.7.5 ReleaseCandidate3, listed 2026-09-07: same historical failures.
  • Current SVN trunk r6855: same historical failures using the upstream Ant engine/JDBC classes build on the classpath. This is not a full distribution/module-path build or a run of HSQL's complete suite.
  • Each build was run in separate UTC and America/Denver JVMs: ten runs total. All stored epoch/nanosecond checks pass in all ten runs; the two historical rows fail typed extraction on all builds except 2.6.1.
  • This bounds the observed regression between 2.6.1 and 2.7.0; an introducing revision was not bisected.

Reproduction

Place the attached source alongside the RC jar, then run:

javac HsqlOffsetDateTimeReproducer.java
java -Duser.timezone=UTC -cp .:hsqldb-2.7.5-ReleaseCandidate3.jar HsqlOffsetDateTimeReproducer
java -Duser.timezone=America/Denver -cp .:hsqldb-2.7.5-ReleaseCandidate3.jar HsqlOffsetDateTimeReproducer

The relevant JDBC operations are:

insert.setObject(1, input, Types.TIMESTAMP_WITH_TIMEZONE);
OffsetDateTime output = result.getObject(1, OffsetDateTime.class);

The label overload is also checked. Independent storage checks use UNIX_TIMESTAMP(v) and the fractional part of EXTRACT(SECOND FROM v), not the typed getter or SQL text as the sole epoch oracle.

Expected / actual

  1. Input 1582-10-04T00:00:00.123456789+05:45
    Expected stored and returned epoch second: -12220263900, nanos 123456789.
    Actual storage: epoch -12220263900, nanos 123456789 (correct).
    SQL wall text: 1582-09-24 00:00:00.123456789+5:45.
    Typed output: 1582-09-24T00:00:00.123456789+05:45 (incorrect instant, correct offset).
    Both indexed and label getters reproduce the shift.

  2. Input 1500-03-10T12:00:00.123456789-03:30
    Expected stored and returned epoch second: -14825838600, nanos 123456789.
    Actual storage: epoch -14825838600, nanos 123456789 (correct).
    SQL wall text: 1500-02-29 12:00:00.123456789-3:30.
    Both typed getters throw:
    java.time.DateTimeException: Invalid date 'February 29' as '1500' is not a leap year

  3. Controls 1582-10-15T00:00:00.123456789+05:45 and
    2026-01-01T12:00:00.123456789-03:30 both retain instant, offset and nanos.

The required invariant is that typed OffsetDateTime extraction represents the physical stored instant and original offset. This report does not request changing HSQL's existing historical SQL wall-calendar semantics. The differing SQL wall label alone is not the reported failure.

Source-level explanation

In trunk r6855, DateTimeType.convertJavaToSQL(SessionInterface, OffsetDateTime), around lines 1110-1142, stores odt.toEpochSecond(), offset seconds and nanos for SQL_TIMESTAMP_WITH_TIME_ZONE. This matches the independent storage observations.

DateTimeType.toOffsetDateTime(), around lines 3161-3183, obtains a ZoneOffset and then calls toLocalDateTime(session, v). That helper (around lines 3107-3126) obtains fields through session.getCalendarGMT(), which uses the hybrid GregorianCalendar. OffsetDateTime.of(lt, zone) then treats those wall fields as proleptic Gregorian. This explains the shifted instant and the Julian leap-date exception.

For the WITH TIME ZONE route, reconstruction from the stored instant/offset would avoid interpreting the hybrid wall fields as proleptic dates. This is a targeted diagnostic observation, not a proposal to globally change the historical meaning of SQL dates or the WITHOUT TIME ZONE conversion path. No ORM workaround is needed to run the reproduction.

Attachments

HsqlOffsetDateTimeReproducer.java: standalone source.
hsqldb-offset-extraction-report.zip: source, this report, ten execution logs, commands/results and checksums. The accompanying local investigation evidence retains source/build provenance and raw issue/search responses.

2 Attachments

Discussion

  • Fred Toussi

    Fred Toussi - 2026-11-22
    • assigned_to: Fred Toussi
     
  • Fred Toussi

    Fred Toussi - 2026-11-22

    Thanks for the tests. I have reviewed and fixed some issues related to this.

    OffsetDateTime and LocalDateTime classes are treated by HSQLDB simply as holders of values for the date components. The proleptic calendar is not used.

    The test for all dates, including prior to 1582-10-05, should be:
    assert input.equals(result.getObject("v", OffsetDateTime.class));
    The toEpochSecond call is guaranteed to give a different value from the actual number of seconds from 1970-01-01 returned by UNIX_TIMESTAMP(v), for those dates.

    I will commit the changes soon, after a further review.

     

    Last edit: Fred Toussi 2026-11-22
  • Fred Toussi

    Fred Toussi - 5 hours ago
    • status: open --> open-fixed
     
  • Fred Toussi

    Fred Toussi - 5 hours ago

    Changes have been committed to SVN after a review.

     

Log in to post a comment.