[CONJ-167] Driver is throwing IllegalArgumentException instead of returning null Created: 2015-07-20  Updated: 2015-09-02  Resolved: 2015-07-21

Status: Closed
Project: MariaDB Connector/J
Component/s: Other
Affects Version/s: 1.2.0
Fix Version/s: 1.2.2

Type: Bug Priority: Critical
Reporter: Harel E. Assignee: Diego Dupin
Resolution: Fixed Votes: 0
Labels: None
Environment:

JDK 8


Sprint: Sprint connector/j 1.3.0

 Description   

From* java.sql.Driver.connect* javadoc

The driver should return "null" if it realizes it is the wrong kind of driver to connect to the given URL

The problem I ran into is that when the application is loaded with other other jdbc drivers (e.g. H2), mariadb driver is throwing an exception instead of returning null. This exception prevents DriveManager to continue checking other drivers for URL compatibility.

Caused by: java.lang.IllegalArgumentException: Invalid connection URL url jdbc:h2:mem:RZM;DB_CLOSE_DELAY=-1
at org.mariadb.jdbc.JDBCUrl.parse(JDBCUrl.java:144)
at org.mariadb.jdbc.Driver.connect(Driver.java:95)
at java.sql.DriverManager.getConnection(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:208)



 Comments   
Comment by Diego Dupin [ 2015-07-21 ]

Exactly.
The "IllegalArgumentException" must be thrown only if URL is valid for mariadb.

Comment by Harel E. [ 2015-07-21 ]

The Driver should return null if the URL is invalid.
The Driver should throw SQLException if the URL is valid, but cannot connect to the Database.

Otherwise, it should return the Connection object.

It should not throw any RuntimeException

Comment by Harel E. [ 2015-07-21 ]

IMHO the right thing to do, if you encounter an invalid URL with the correct prefix is to throw SQLException (or subclass of it) and not IllegalArgumentException

Comment by Diego Dupin [ 2015-07-21 ]

Thanks about your point, clearly to be changed.

Add commit https://github.com/MariaDB/mariadb-connector-j/commit/4419ac044cfa609e01d491218ef6751b2bb8537f
concerning replacement of RuntimeException by SQLException.

Comment by Harel E. [ 2015-07-21 ]

Thanks for the quick fix

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