db-derby-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Knut Anders Hatlen (JIRA)" <j...@apache.org>
Subject [jira] [Updated] (DERBY-6081) JDBC 4.2 setObject() and updateObject() methods throw NPE when type is null
Date Wed, 20 Feb 2013 15:37:13 GMT

     [ https://issues.apache.org/jira/browse/DERBY-6081?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel

Knut Anders Hatlen updated DERBY-6081:

    Attachment: d6081-1a.diff

The current code detects that an invalid type is specified and tries to create an SQLException
to report it. When creating the SQLException, it calls toString() on the type object in order
to produce the message text. Since the object is null, a NullPointerException is thrown.

The factory methods that create SQLExceptions don't require message arguments to be strings,
they could be any object type. Eventually, MessageFormat will call toString() on them, but
it will first check for null values in order to prevent NullPointerExceptions.

The attached patch changes the code that produces the SQLException so that it simply passes
the SQLType object to the message formatter without calling toString() on it first. This prevents
the NullPointerException and makes setObject() and updateObject() produce an SQLException
with the following message text instead:

java.sql.SQLFeatureNotSupportedException: The data type 'null' is not supported.

The patch adds test cases to PreparedStatementTest42. This test fails with NPE without the
suggested fix, and runs cleanly when the fix is applied. I've started the full regression
test suite on JDK 8. Will report back when it has completed.
> JDBC 4.2 setObject() and updateObject() methods throw NPE when type is null
> ---------------------------------------------------------------------------
>                 Key: DERBY-6081
>                 URL: https://issues.apache.org/jira/browse/DERBY-6081
>             Project: Derby
>          Issue Type: Bug
>          Components: JDBC
>    Affects Versions:
>            Reporter: Knut Anders Hatlen
>            Assignee: Knut Anders Hatlen
>         Attachments: d6081-1a.diff
> If the SQLType argument to the new JDBC 4.2 methods in PreparedStatement and ResultSet
is null, the call will fail with a NullPointerException. It should fail with an SQLException.
> Stack trace on embedded:
> java.lang.NullPointerException
>         at org.apache.derby.impl.jdbc.Util42.getTypeAsInt(Util42.java:57)
>         at org.apache.derby.impl.jdbc.EmbedPreparedStatement42.setObject(EmbedPreparedStatement42.java:57)
> Stack trace on client:
> java.lang.NullPointerException
>         at org.apache.derby.client.am.Utils42.getTypeAsInt(Utils42.java:55)
>         at org.apache.derby.client.am.PreparedStatement42.setObject(PreparedStatement42.java:78)

This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

View raw message