Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1aRBDr-0005gC-19 for pgsql-bugs@arkaria.postgresql.org; Thu, 04 Feb 2016 04:08:47 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1aRBDq-0000KH-KG for pgsql-bugs@arkaria.postgresql.org; Thu, 04 Feb 2016 04:08:46 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1aQxSj-0006kG-BH for pgsql-bugs@postgresql.org; Wed, 03 Feb 2016 13:27:13 +0000 Received: from mx0.salzburgresearch.at ([78.104.175.164]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1aQxSe-0005cp-Ra for pgsql-bugs@postgresql.org; Wed, 03 Feb 2016 13:27:12 +0000 X-Virus-Scanned: by Salzburg Research on mx0.salzburgresearch.at DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=salzburgresearch.at; s=srfg; t=1454506026; bh=jUEvED+8s56qbmZzfhruEJwNBf9/iAZpxRxSDPCaQT0=; h=Date:From:To:Subject:From; b=v40eddZnrG/yro4fJLFv86rGWNstF6FvudXZPrg2I+tV2DDLh47VlA5SUvtW33daa XtNwkejKdaP93886uP0c4rzNxn+KsS/And4cRhd0zuf+Tn5EsbCT1qGLCMevq/vdYb 8OJ6gyWfx6OKk85w0KAfDT4FG1W3x47v0nA2r9DU= Received: from mail01.salzburgresearch.at (mail01.salzburgresearch.at [172.16.0.31]) by mx0.salzburgresearch.at (Postfix) with ESMTPS id 8D4BD200EC4 for ; Wed, 3 Feb 2016 14:27:05 +0100 (CET) Received: from [172.16.97.189] (mowi89.salzburgresearch.at [172.16.97.189]) by mail01.salzburgresearch.at (Postfix) with ESMTPSA id 796F35196 for ; Wed, 3 Feb 2016 14:27:05 +0100 (CET) Message-ID: <56B20029.5010605@salzburgresearch.at> Date: Wed, 03 Feb 2016 14:27:05 +0100 From: Michael Wimmer User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20130620 Thunderbird/17.0.7 MIME-Version: 1.0 To: pgsql-bugs@postgresql.org Subject: Java ClassCastException using JDBC driver and selecting smallint arrays X-Enigmail-Version: 1.6 Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -2.4 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org 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