[CONJ-245] Check connection status before executing query Created: 2016-01-12  Updated: 2016-09-01  Resolved: 2016-09-01

Status: Closed
Project: MariaDB Connector/J
Component/s: Other
Affects Version/s: None
Fix Version/s: 1.4.0

Type: Bug Priority: Major
Reporter: Diego Dupin Assignee: Diego Dupin
Resolution: Fixed Votes: 0
Labels: None


 Description   

If a statement execute a query on a close connection a nullpointer exception is thrown :
javax.persistence.PersistenceException: java.lang.NullPointerException
at org.eclipse.persistence.internal.jpa.QueryImpl.getResultList(QueryImpl.java:484)
at MariaDBTest$2.run(MariaDBTest.java:52)
Caused by: java.lang.NullPointerException
at org.mariadb.jdbc.internal.stream.PacketOutputStream.startPacket(PacketOutputStream.java:68)
at org.mariadb.jdbc.internal.stream.PacketOutputStream.startPacket(PacketOutputStream.java:78)
at org.mariadb.jdbc.internal.packet.send.SendTextQueryPacket.send(SendTextQueryPacket.java:101)
at org.mariadb.jdbc.internal.protocol.AbstractQueryProtocol.sendQuery(AbstractQueryProtocol.java:388)
at org.mariadb.jdbc.internal.protocol.AbstractQueryProtocol.executeQuery(AbstractQueryProtocol.java:382)
at org.mariadb.jdbc.internal.protocol.AbstractQueryProtocol.executeQuery(AbstractQueryProtocol.java:339)
at org.mariadb.jdbc.MariaDbStatement.execute(MariaDbStatement.java:280)
at org.mariadb.jdbc.MariaDbStatement.executeQuery(MariaDbStatement.java:448)

to reproduce :

```
Connection connection = DriverManager.getConnection("jdbc:mariadb:/....");
Statement statement = connection.createStatement();
try

{ Statement otherStatement = connection.createStatement(); otherStatement.execute("QUERY"); }

catch (SQLException e)

{ //throw connection exception (SQLState "08XXX") due to network instability //otherStatement and connection will be closed //but method continue }

//Will throw this nullPointerException
statement.execute("QUERY");
```
The correction seem not to change the PacketOutputStream, since socket is close. The thing is to check "connected" status in the AbstractQueryProtocol, before executing a query and to throw a connection exception since connection is closed. That way, if driver is configured to support failover, a new connection will be created, if not, the statement will be closed and throw exception.



 Comments   
Comment by Diego Dupin [ 2016-09-01 ]

Closed, since implemented by a pull request since 1.4.

Generated at Thu Feb 08 03:14:15 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.