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

Connection.isValid(int) does not work when connection is closed

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 1.1.7
    • Fix Version/s: 1.1.8
    • Component/s: None
    • Labels:
      None

      Description

      Background:
      The method Connection.isValid(int) method http://docs.oracle.com/javase/7/docs/api/java/sql/Connection.html#isValid%28int%29 has this documentation for Returns:
      “true if the connection is valid, false otherwise”
      And this documentation for Throws:
      “SQLException - if the value supplied for timeout is less then 0”

      How to reproduce:

      1. Download and run the attached JUnit test file ConnectionIsValidTest.java
      2. Run the test with MariaDB JDBC
      3. Run the test with Mysql JDBC (see instructions in the file for details)
      4. Run the test with H2 in memory database

      Psedo-code:

      1. Create a connection to the database server
      2. Kill the connection in some way (for example with KILL CONNECTION)
      3. Check the status of the connection with Connection.isValid(10).

      Actual MariaDB JDBC:
      isValid_shouldThrowExceptionWithNegativeTimeout: fails because it does not throw an SQLException
      isValid_testWorkingConnection: pass
      isValid_closedConnection: fails with a NullPointerException
      isValid_connectionThatTimesOutByServer: fails with SQLException
      isValid_connectionThatIsKilledExternally: fails with SQLException

      Actual Mysql JDBC:
      isValid_shouldThrowExceptionWithNegativeTimeout: fails because it does not throw an SQLException
      isValid_testWorkingConnection: pass
      isValid_closedConnection: pass
      isValid_connectionThatTimesOutByServer: pass
      isValid_connectionThatIsKilledExternally: pass

      Actual H2:
      isValid_shouldThrowExceptionWithNegativeTimeout: fails because it does not throw an SQLException
      isValid_testWorkingConnection: pass
      isValid_closedConnection: pass
      isValid_connectionThatTimesOutByServer: ignored
      isValid_connectionThatIsKilledExternally: ignored

      Expected:
      Every test case should pass (except the ignored test cases in the H2 case).

      However every JDBC implementation has ignored that a negative timeout should throw an SQLException. This is probably such a minor detail that it is not worth fixing.

        Attachments

          Activity

            People

            Assignee:
            massimo.siani Massimo Siani (Inactive)
            Reporter:
            lennartschedin Lennart Schedin
            Votes:
            0 Vote for this issue
            Watchers:
            2 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.