Bug #82896 Unexpected behavior on attempt to connect to JDBC driver with unsupported URL
Submitted: 7 Sep 2016 21:33 Modified: 21 Jun 2017 17:25
Reporter: Artem Lodygin Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / J Severity:S3 (Non-critical)
Version:6.0.4 OS:Any
Assigned to: Alexander Soklakov CPU Architecture:Any

[7 Sep 2016 21:33] Artem Lodygin
Description:
Attempt to connect to mySql JDBC driver with unsupported URL causes WrongArgumentException stacktrace to be printed to console, such as:

com.mysql.cj.core.exceptions.WrongArgumentException: Connector/J cannot handle a database URL of type 'jdbc:h2:mem:test' **stacktrace follows**

When several JDBC drivers are registered in the system, it happens on every connection attempt to all drivers chained below mysql. 

Expected behavior is SILENTLY failing with SQLException.

How to repeat:
Put mysql connector jar into classpath. Do NOT put com.h2database driver into classpath. Execute the following code:

DriverManager.getConnection("jdbc:h2:mem:test", null, null);

Suggested fix:
Remove "e.printStackTrace();" from the method 
ConnectionUrl getConnectionUrlInstance(String connString, Properties info)
[8 Sep 2016 11:34] Chiranjeevi Battula
Hello Artem Lodygin,

Thank you for the bug report.
Verified based on internal discussion with dev's.

Thanks,
Chiranjeevi.
[17 Mar 2017 12:00] Alexander Soklakov
Hi Artem,

I can't reproduce reported error with last released c/J 6.0.6 version. Could you confirm that it works for you as well?

Thanks,
Alex
[24 Mar 2017 13:36] Alexander Soklakov
Posted by developer:
 
This bug was fixed in c/J 6.0.5 as a part of WL#9981 patch, commit 6de59dcf82d4fb9c4ed7d3791e3cf47f2ecd8419.
[21 Jun 2017 17:25] Daniel So
Posted by developer:
 
Added the following entry to the Connector/J 6.0.5 changelog:

"Connecting to a MySQL server with an invalid connection URL resulted in a WrongArgumentException and a stack trace. With this fix, the connection failed in the situation with an SQLException and without a stack trace."
[29 Aug 2017 19:31] Praml Roland
Hello,
I have still the same issue, but with a different connection string in 6.0.6.

My connection URL is: "jdbc:oracle:thin:@//127.0.0.1:1521/orcl" (which looks a bit uncommon, yes)

maybe you can add an `acceptsUrl` check in NonRegisteredDriver.connect() (or a startsWith("jdbc:mysql:") check)
BTW: 5.1.43 works (as it only parses urls with valid prefixes)

Cheers
Roland

--- Stacktrace ----
Caused by: java.sql.SQLNonTransientConnectionException: Cannot load connection class because of underlying exception: com.mysql.cj.core.exceptions.WrongArgumentException: Malformed database URL, failed to parse the main URL sections.
        at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:526)
        at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:513)
        at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:505)
        at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:479)
        at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:489)
        at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:72)
        at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:124)
        at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:224)
        at java.sql.DriverManager.getConnection(DriverManager.java:664)
        at java.sql.DriverManager.getConnection(DriverManager.java:208)
....
--------
[30 Aug 2017 6:49] Alexander Soklakov
Hi Roland,

It's a different issue. Could you create a new bug report?

Thanks in advance,
Alex