Java ClassCastException using JDBC driver and selecting smallint arrays

From: Michael Wimmer <michael(dot)wimmer(at)salzburgresearch(dot)at>
To: pgsql-bugs(at)postgresql(dot)org
Subject: Java ClassCastException using JDBC driver and selecting smallint arrays
Date: 2016-02-03 13:27:05
Message-ID: 56B20029.5010605@salzburgresearch.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Hello,

I am developing a Java application using PostgreSQL 9.4 and the current JDBC driver in version 9.4.1207.
I have a simple select statement on a table having a column of type smallint[].
The Java code in the row mapper after query execution looks like:

Array accessTypeArray = rs.getArray("accesstypes");
if (accessTypeArray != null) {
Integer[] accessTypeIds = (Integer[]) accessTypeArray.getArray();
...
}

In some cases of execution this code works fine, in other case (depending on the implementation of the underlying datasource, don't know exactly the
reason) the code ends up in:

java.lang.ClassCastException: [Ljava.lang.Short; cannot be cast to [Ljava.lang.Integer;

I have debugged for some time and found an inconsistent implementation in the class PgArray. Calling the method "getArray()" returns an array of Short
in case of "fieldBytes" not null (calling submethod "readBinaryArray()") or an array of Integer in the other case (calling submethod "buildArray()").

Is it correct that smallint arrays are mapped to Short[]? (see http://docs.oracle.com/javase/6/docs/technotes/guides/jdbc/getstart/mapping.html#table3)

Regards,
Michael

Browse pgsql-bugs by date

  From Date Subject
Next Message Michael Paquier 2016-02-03 14:28:18 Re: Re: BUG #13685: Archiving while idle every archive_timeout with wal_level hot_standby
Previous Message Andres Freund 2016-02-03 09:38:03 Re: Re: BUG #13685: Archiving while idle every archive_timeout with wal_level hot_standby