NullPointerException with SQLContainer's J2EEConnectionPool

Hello,

I would like to see if the following is a known issue.

When connecting to an Oracle DB with Vaadin running in Tomcat, I was receiving a NullPointerException. It turned out that I had invalid db login credentials. But I want to see an error message to that effect and not an uninformative NPE. Digging in, it looks like TableQuery.fetchMetaData() can pass a null connection to J2EEConnectionPool.releaseConnection(), but the latter method does not guard against null.

I didn’t find any other discussion of this problem in the forums or in Trac. I’m using Vaadin 6.6.5 and SQLContainer 1.1.0.


java.lang.NullPointerException
	at com.vaadin.addon.sqlcontainer.connection.J2EEConnectionPool.releaseConnection(J2EEConnectionPool.java:51)
	at com.vaadin.addon.sqlcontainer.query.TableQuery.fetchMetaData(TableQuery.java:527)
	at com.vaadin.addon.sqlcontainer.query.TableQuery.<init>(TableQuery.java:87)

and the code from the SQLContainer add-on is


public class TableQuery implements QueryDelegate, QueryDelegate.RowIdChangeNotifier {
        
    private void fetchMetaData() {
        try {
            c = connectionPool.reserveConnection();
            
			// ...
			
        } catch (SQLException e) {
            throw new RuntimeException(e);
        } finally {
            connectionPool.releaseConnection(c);
        }
   }


public class J2EEConnectionPool implements JDBCConnectionPool {

    public void releaseConnection(Connection conn) {
        try {
            conn.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

Thanks,
Dan

I have filed http://dev.vaadin.com/ticket/7597.

I met the similar NullPointerException


Caused by: java.lang.NullPointerException
	at com.vaadin.data.util.sqlcontainer.query.TableQuery.fetchMetaData(TableQuery.java:532)
	at com.vaadin.data.util.sqlcontainer.query.TableQuery.<init>(TableQuery.java:99)
	at com.vaadin.data.util.sqlcontainer.query.TableQuery.<init>(TableQuery.java:113)

TableQuery.fetchMetaData(TableQuery.java:532) is “tables.close();”
How could I prevent this error? OR its the bug?


        } finally {
            try {
                releaseConnection(connection, null, rs);
            } catch (SQLException ignore) {
            } finally {
                try {
                    tables.close();
                } catch (SQLException ignore) {
                }
            }
        }

Any comment for this NPE? Please help. Thanks.

This looks like a bug. It seems that something else needs to go wrong before ending up to that line with null
tables
, but in that case the NPE can hide the original problem.

Please
create a ticket
about the need for a null check there.