Bug in org.postgresql.jdbc2.AbstractJdbc2ResultSet?

Поиск
Список
Период
Сортировка
Искать

Bug in org.postgresql.jdbc2.AbstractJdbc2ResultSet?

От:
David Clark <davidclark@tx.rr.com>
Дата:
There seems to be a bug in internalGetObject(int, Field) in 
org.postgresql.jdbc2.AbstractJdbc2ResultSet.  I am using the 
postgresql-jdbc-8.0-319.src sources.  I am placing the patch file inline 
below in case the mailing list does not accept attachments.  The bug (?) is 
that for TINYINT and SMALLINT columns a java.lang.Short should be returned 
from internalGetObject, but an Integer is returned instead.

Patch:

--- AbstractJdbc2ResultSet.java 2007-04-16 11:37:04.000000000 -0500
+++ AbstractJdbc2ResultSet.java.patched 2007-04-30 15:52:51.000000000 -0500
@@ -117,6 +117,7 @@
             return getBoolean(columnIndex) ? Boolean.TRUE : Boolean.FALSE;
         case Types.TINYINT:
         case Types.SMALLINT:
+           return new Short(getShort(columnIndex));
         case Types.INTEGER:
             return new Integer(getInt(columnIndex));
         case Types.BIGINT:

David Clark

Re: Bug in org.postgresql.jdbc2.AbstractJdbc2ResultSet?

От:
Kris Jurka <books@ejurka.com>
Дата:


On Mon, 30 Apr 2007, David Clark wrote:

> There seems to be a bug in internalGetObject(int, Field) in
> org.postgresql.jdbc2.AbstractJdbc2ResultSet.  I am using the
> postgresql-jdbc-8.0-319.src sources.  I am placing the patch file inline
> below in case the mailing list does not accept attachments.  The bug (?) is
> that for TINYINT and SMALLINT columns a java.lang.Short should be returned
> from internalGetObject, but an Integer is returned instead.
>

Actually this behavior is correct according to the JDBC spec.  If you see 
Appendix B [1] it says:

Note - The JDBC 1.0 specification defined the Java object mapping for the 
SMALLINT and TINYINT JDBC types to be Integer.  The Java language did not 
include the Byte and Short data types when the JDBC 1.0 specification was 
finalized.  The mapping of SMALLINT and TINYINT to Integer is maintained 
to preserve backwards compatibility.

Kris Jurka

http://jcp.org/aboutJava/communityprocess/final/jsr221/index.html
FAQ