Bug #17587 NPE in PreparedStatement.clearParameters

Submitted: 20 Feb 2006 17:06 Modified: 10 Mar 2006 20:29
Reporter: Christopher Stach II Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / J Severity:S3 (Non-critical)
Version:5.0.0-beta OS:Linux (RHEL3)
Assigned to: Mark Matthews CPU Architecture:Any

[20 Feb 2006 17:06] Christopher Stach II
Description:
I'm not sure if the NPE is making the situation worse.  The lack of an initialized parameterValues seems to be caused by the underlying connection error.

[18:53:10.635] Caused by: java.lang.NullPointerException
[18:53:10.635]  at com.mysql.jdbc.PreparedStatement.clearParameters(PreparedStatement.java:583)
[18:53:10.635]  at com.mysql.jdbc.jdbc2.optional.PreparedStatementWrapper.clearParameters(PreparedStatementWrapper.java:768)
[18:53:10.635]  at com.caucho.sql.UserPreparedStatement.clearParameters(UserPreparedStatement.java:136)
[18:53:10.635]  at com.caucho.sql.UserPreparedStatement.clearParameters(UserPreparedStatement.java:136)
[18:53:10.635]  at com.caucho.sql.UserPreparedStatement.close(UserPreparedStatement.java:439)
[18:53:10.635]  at org.hibernate.jdbc.AbstractBatcher.closePreparedStatement(AbstractBatcher.java:471)
[18:53:10.635]  at org.hibernate.jdbc.AbstractBatcher.closeStatement(AbstractBatcher.java:218)
[18:53:10.635]  at org.hibernate.jdbc.AbstractBatcher.closeQueryStatement(AbstractBatcher.java:234)
[18:53:10.635]  at org.hibernate.jdbc.AbstractBatcher.closeQueryStatement(AbstractBatcher.java:162)
[18:53:10.635]  at org.hibernate.loader.Loader.getResultSet(Loader.java:1683)
[18:53:10.635]  at org.hibernate.loader.Loader.doQuery(Loader.java:662)
[18:53:10.635]  at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
[18:53:10.635]  at org.hibernate.loader.Loader.loadCollection(Loader.java:1919)
[18:53:10.635]  at org.hibernate.loader.collection.CollectionLoader.initialize(CollectionLoader.java:71)
[18:53:10.635]  at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:520)
[18:53:10.635]  at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:60)
[18:53:10.635]  at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1693)
[18:53:10.635]  at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:344)
[18:53:10.635]  at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:86)
[18:53:10.635]  at org.hibernate.collection.PersistentSet.iterator(PersistentSet.java:138)
[18:53:10.635]  at com.xxx.foo1(Xxx.java:545)
[18:53:10.635]  at com.xxx.foo2(Xxx.java:182)
[18:53:10.635]  at sun.reflect.GeneratedMethodAccessor340.invoke(Unknown Source)
[18:53:10.635]  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
[18:53:10.635]  at java.lang.reflect.Method.invoke(Method.java:585)
[18:53:10.635]  at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:335)
[18:53:10.635]  at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:181)
[18:53:10.635]  at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:148)
[18:53:10.635]  at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
[18:53:10.635]  at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:170)
[18:53:10.635]  at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:176)
[18:53:10.635]  at $Proxy48.foo(Unknown Source)
[18:53:10.635]  at com.xxx.foo(Xxx.java:116)
[18:53:10.635]  at sun.reflect.GeneratedMethodAccessor339.invoke(Unknown Source)
[18:53:10.635]  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
[18:53:10.635]  at java.lang.reflect.Method.invoke(Method.java:585)
[18:53:10.635]  at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:335)
[18:53:10.635]  at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:181)
[18:53:10.635]  at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:148)
[18:53:10.635]  at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
[18:53:10.635]  at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:170)
[18:53:10.635]  at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:176)
[18:53:10.635]  at $Proxy49.foo(Unknown Source)
[18:53:10.635]  ... 14 more
[18:53:10.647] com.mysql.jdbc.jdbc2.optional.MysqlXAConnection$MysqlXAException: No operations allowed after connection closed.Connection was implicitly closed due to underlying exception/error:
[18:53:10.647]
[18:53:10.647]
[18:53:10.647] ** BEGIN NESTED EXCEPTION **
[18:53:10.647]
[18:53:10.647] com.mysql.jdbc.CommunicationsException
[18:53:10.647] MESSAGE: Communications link failure due to underlying exception:
[18:53:10.647]
[18:53:10.647] ** BEGIN NESTED EXCEPTION **
[18:53:10.647]
[18:53:10.647] java.net.SocketException
[18:53:10.647] MESSAGE: Broken pipe
[18:53:10.647]
[18:53:10.647] STACKTRACE:
[18:53:10.647]
[18:53:10.647] java.net.SocketException: Broken pipe
[18:53:10.647]  at java.net.SocketOutputStream.socketWrite0(Native Method)
[18:53:10.647]  at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:92)
[18:53:10.647]  at java.net.SocketOutputStream.write(SocketOutputStream.java:136)
[18:53:10.647]  at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:65)
[18:53:10.647]  at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:123)
[18:53:10.647]  at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:2590)
[18:53:10.647]  at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:2523)
[18:53:10.647]  at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1517)
[18:53:10.647]  at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1626)
[18:53:10.647]  at com.mysql.jdbc.Connection.execSQL(Connection.java:3031)
[18:53:10.647]  at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:943)
[18:53:10.647]  at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1049)
[18:53:10.647]  at com.mysql.jdbc.jdbc2.optional.PreparedStatementWrapper.executeQuery(PreparedStatementWrapper.java:811)
[18:53:10.647]  at com.caucho.sql.UserPreparedStatement.executeQuery(UserPreparedStatement.java:100)
[18:53:10.647]  at com.caucho.sql.UserPreparedStatement.executeQuery(UserPreparedStatement.java:100)
[18:53:10.647]  at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:139)
[18:53:10.647]  at org.hibernate.loader.Loader.getResultSet(Loader.java:1669)
[18:53:10.647]  at org.hibernate.loader.Loader.doQuery(Loader.java:662)
[18:53:10.647]  at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
[18:53:10.647]  at org.hibernate.loader.Loader.loadCollection(Loader.java:1919)
[18:53:10.647]  at org.hibernate.loader.collection.CollectionLoader.initialize(CollectionLoader.java:71)
[18:53:10.647]  at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:520)
[18:53:10.647]  at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:60)
[18:53:10.647]  at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1693)
[18:53:10.647]  at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:344)
[18:53:10.647]  at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:86)
[18:53:10.647]  at org.hibernate.collection.PersistentSet.iterator(PersistentSet.java:138)
[...]

How to repeat:
I'm not sure yet.

Suggested fix:
Check for non-null parameterValues or initialized state?
[22 Feb 2006 17:19] Mark Matthews
Actually looks like connection being lost, which closes the statements it created. What you should _actually_ get is a SQLException on this method saying that the statement is closed, which would still cause an exception in your application.

I can fix the NPE issue, as I don't like runtime exceptions trickling out of the JDBC driver if we can avoid it.
[9 Mar 2006 21:49] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/3674
[10 Mar 2006 20:29] Mark Matthews
Fix will be available in 5.0.1 and 3.1.13. You can try a nightly snapshot from http://downloads.mysql.com/snapshots.php#connector-j if you want to test the fix before it's officially released. Thanks for the bug report.

Portions of this website are copyright © 2001, 2002 The PHP Group

Page generated in 0.040 sec. using MySQL 8.4.7-u6-cloud

Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.