Details
-
Bug
-
Status: Closed (View Workflow)
-
Major
-
Resolution: Fixed
-
None
-
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
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.