From: Michael Wimmer <michael.wimmer@salzburgresearch.at>
To: pgsql-bugs@postgresql.org
Subject: Java ClassCastException using JDBC driver and selecting smallint arrays
Date: Wed, 03 Feb 2016 14:27:05 +0100
Message-ID: <56B20029.5010605@salzburgresearch.at> (raw)
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-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
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: michael.wimmer@salzburgresearch.at
Subject: Re: Java ClassCastException using JDBC driver and selecting smallint arrays
In-Reply-To: <56B20029.5010605@salzburgresearch.at>
References: <56B20029.5010605@salzburgresearch.at>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox