Re: Bug with OffsetTimeZone deserialization in HSQL 2.4.0?

Michele Mancioppi <[email protected]> Sun, 30 Apr 2017 15:00:42 +0200
Newsgroups gmane.comp.java.hsqldb.user
Message-ID <CAG6FkRpkcM0cp=BNjY9FuXp5_iXrWRRkp16QkZriHUpMaZJEYA@mail.gmail.com>
Hi,

I looked into the code of 2.4.0 and I think I found the bug:

org/hsqldb/jdbc/JDBCResultSet.java, line 7335:

    private Object getTimestampWithZone(int columnIndex) throws
SQLException {
        TimestampData v = (TimestampData) getColumnInType(columnIndex,
Type.SQL_TIMESTAMP_WITH_TIME_ZONE);

        if (v == null) {
            return null;
        }

        ZoneOffset z = ZoneOffset.ofTotalSeconds(v.getZone());
        LocalDateTime ldt = LocalDateTime.ofEpochSecond(v.getSeconds() -
v.getZone(), v.getNanos(), z);
        return OffsetDateTime.of(ldt, z);
    }

When calculating the LocalDateTime, the v.getZone() is indeed subtracted
from the v.getSeconds() (which is the bug), and then the zone is applied
again as 3rd argument (which is right).

As far as I can see, the bug is still there in Trunk. I'll send a patch, if
I can remember how SVN works :D

Best,
  Michele

On Sat, Apr 29, 2017 at 7:06 PM, Michele Mancioppi <
[email protected]> wrote:

> Hi,
>
> I might be missing something obvious about timezones, but I think there
> may be a bug in the way the HSQL 2.4.0 JDBC driver deserializes TIMESTAMP
> WITH TIME ZONE data as OffsetTimeZone objects: on the one hand,
> ResultSet.getString(n) returns "2009-10-02 16:52:30.000000+2:00" (which is
> exactly what I expected); on the other hand, ResultSet.getObject(n) returns
> an OffsetTimeZone that, to string, maps to "2009-10-02T14:52:30+02:00".
> That it, it seems to me the timezone is applied twice. I did not look in
> the code, but this is exactly the faulty outcome I would expect if the
> OffsetTimeZone object had been created using the value of
> ResultSet.getTime(n) and then had the +2:00 timezone applied to it.
>
> I am using the following Maven dependency:
>
>             <dependency>
>                 <groupId>org.hsqldb</groupId>
>                 <artifactId>hsqldb</artifactId>
>                 <version>2.4.0</version>
>             </dependency>
>
> Is it a bug on the code, or is the bug between keyboard and chair? :-)
>
> Best,
>   Michele
>

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot

_______________________________________________
Hsqldb-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/hsqldb-user