Uploaded image for project: 'MariaDB Connector/J'
  1. MariaDB Connector/J
  2. CONJ-245

Check connection status before executing query

    XMLWordPrintable

Details

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

      Attachments

        Activity

          People

            diego dupin Diego Dupin
            diego dupin Diego Dupin
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Git Integration

                Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.