United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-6462470 java.lang.NullPointerException from query object update procedure
JDK-6462470 : java.lang.NullPointerException from query object update procedure

Details
Type:
Bug
Submit Date:
2006-08-22
Status:
Closed
Updated Date:
2011-02-16
Project Name:
JDK
Resolved Date:
2006-08-30
Component:
core-libs
OS:
linux_2.6
Sub-Component:
java.sql
CPU:
x86
Priority:
P2
Resolution:
Fixed
Affected Versions:
6
Fixed Versions:

Related Reports

Sub Tasks

Description
The following code (Run with Java DB 10.2.1.0 beta):

import java.sql.*;

public class EODExceptionBug
{
    interface PersonQ extends BaseQuery {
        @java.sql.Update(sql="create table tab (i integer)")
            int createTable();
    }
    
    static public void main(String []args) 
        throws Exception
    {
	String driver = "org.apache.derby.jdbc.EmbeddedDriver";
	String url = "jdbc:derby:/tmp/eodbug;create=true";
        
        Connection conn = DriverManager.getConnection(url);
        
        PersonQ pq = conn.createQueryObject(PersonQ.class);

        System.out.println("First create");
        pq.createTable();
        System.out.println("Second create");
        try {
            pq.createTable();
        } catch (SQLRuntimeException e) {
            System.out.println("Should end up here, but don't");
        }
    }
}


Gives the following response:
First create
Second create
java.sql.SQLException: Table/View 'TAB' already exists in Schema 'APP'.
        at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
        at org.apache.derby.impl.jdbc.SQLExceptionFactory40.wrapArgsForTransportAcrossDRDA(Unknown Source)
        at org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(Unknown Source)
        at org.apache.derby.impl.jdbc.Util.generateCsSQLException(Unknown Source)
        at org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(Unknown Source)
        at org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(Unknown Source)
        at org.apache.derby.impl.jdbc.EmbedConnection.handleException(Unknown Source)
        at org.apache.derby.impl.jdbc.ConnectionChild.handleException(Unknown Source)
        at org.apache.derby.impl.jdbc.EmbedStatement.executeStatement(Unknown Source)
        at org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeStatement(Unknown Source)
        at org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeUpdate(Unknown Source)
        at com.sun.sql.QueryObjectGeneratorImpl.getUpdateImpl(QueryObjectGeneratorImpl.java:543)
        at com.sun.sql.QueryObjectGeneratorImpl.access$200(QueryObjectGeneratorImpl.java:24)
        at com.sun.sql.QueryObjectGeneratorImpl$3.run(QueryObjectGeneratorImpl.java:244)
        at java.security.AccessController.doPrivileged(Native Method)
        at com.sun.sql.QueryObjectGeneratorImpl.invoke(QueryObjectGeneratorImpl.java:239)
        at $Proxy0.createTable(Unknown Source)
        at EODExceptionBug.main(EODExceptionBug.java:24)
Caused by: java.sql.SQLException: Table/View 'TAB' already exists in Schema 'APP'.
        ... 18 more
Exception in thread "main" java.lang.NullPointerException
        at $Proxy0.createTable(Unknown Source)
        at EODExceptionBug.main(EODExceptionBug.java:24)

                                    

Comments
SUGGESTED FIX

The exceptions were caught and there stack trace were being printed instead of throwing those exceptions further.
All such cases have been removed. Now all exceptions are thrown. All cases of exception being caught and stack trace being printed are removed.

checkin logs

Checking in QueryObject.java;
/m/jws/jdbc4.0/src/com/sun/sql/QueryObject.java,v  <--  QueryObject.java
new revision: 1.5; previous revision: 1.4
done
                                     
2006-08-25
EVALUATION

The exceptions were caught and there stack trace were being printed instead of throwing those exceptions further.
                                     
2006-08-25



Hardware and Software, Engineered to Work Together