Details
-
Bug
-
Status: Closed (View Workflow)
-
Minor
-
Resolution: Fixed
-
1.1.7
-
None
-
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:
- Download and run the attached JUnit test file ConnectionIsValidTest.java
- Run the test with MariaDB JDBC
- Run the test with Mysql JDBC (see instructions in the file for details)
- Run the test with H2 in memory database
Psedo-code:
- Create a connection to the database server
- Kill the connection in some way (for example with KILL CONNECTION)
- 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.