Java ClassCastException using JDBC driver and selecting smallint arrays

Поиск
Список
Период
Сортировка
От Michael Wimmer
Тема Java ClassCastException using JDBC driver and selecting smallint arrays
Дата
Msg-id 56B20029.5010605@salzburgresearch.at
обсуждение исходный текст
Список 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
(callingsubmethod "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

В списке pgsql-bugs по дате отправления:

Предыдущее
От: jpaul@aconex.com
Дата:
Сообщение: BUG #13911: pg_upgrade from 8.4 to 9.5 broken
Следующее
От: John R Pierce
Дата:
Сообщение: Re: BUG #13911: pg_upgrade from 8.4 to 9.5 broken