Bug #75440 When using new style JDBC URL "address=(host=..." connector throws NullPointer

Submitted: 7 Jan 2015 23:58 Modified: 25 Jan 2022 13:02
Reporter: Damian Cala Email Updates:
Status: Can't repeat Impact on me:
None 
Category:Connector / J Severity:S3 (Non-critical)
Version:5.1.34 OS:Any
Assigned to: CPU Architecture:Any
Tags: address, connector

[7 Jan 2015 23:58] Damian Cala
Description:
Hi, I am using Spring Data Jpa and Hibernate in order to connect with a MySQL Database.

The database is a cluster with two masters instances and one slave.

Following this documentation:
http://dev.mysql.com/doc/connector-j/en/connector-j-master-slave-replication-connection.ht...

I use this JDBC URL:
jdbc:mysql://address=(host=db1.wiibii.net)(type=master),address=(host=db2.wiibii.net)(type=slave)/wiibii_translate

When it's trying to connect, I have a NullPointerException in:
NonRegisteringDriver.parseHostPortPair() line: 203

I downloaded the source code and found the error. Many times, the code checks the URL and verify if it is a "new style url" testing if the URL starts with "address=".

In ConnectionImpl.coreConnect it checks if it is a "new style url" verifying if it has a protocol param.

So, I solved the error in my case changing this URL:
address=(host=db1.wiibii.net)(type=master)

with this:
address=(protocol=tcp)(host=db1.wiibii.net)(type=master)

But it is not in the documentation, and the protocol should not identify the type of url used.

The piece of code where this error is:

if (protocol != null) {
  // "new" style URL
  if ("tcp".equalsIgnoreCase(protocol)) {
  ...
} else {
  // THIS CALL THROW A NULLPOINTEREXCEPTION BECAUSE hostPortPair IS NULL
  String[] parsedHostPortPair = NonRegisteringDriver.parseHostPortPair(this.hostPortPair);
  ...
}  

How to repeat:
Connect to a cluster using this driver:
com.mysql.jdbc.ReplicationDriver

and a complete url like this without the protocol attribute:

jdbc:mysql://address=(host=db1.wiibii.net)(type=master),address=(host=db2.wiibii.net)(type=slave)/wiibii_feature

Suggested fix:
-Change the validation in ConnectionImpl.coreConnect()

-Change the documentation:
http://dev.mysql.com/doc/connector-j/en/connector-j-master-slave-replication-connection.ht...

Pointing out that protocol attribute is mandatory and adding it to the example URL:

jdbc:mysql://address=(type=master)(host=master1host),address=(type=master)(host=master2host),address=(type=slave)(host=slave1host)/db
[9 Jan 2015 0:01] Todd Farmer
Damien,

Thanks for the well-researched bug report.  I've verified your findings - as it stands today, the protocol component of the "new style address" format is required.  We'll look into improving this.
[25 Jan 2022 13:02] Alexander Soklakov
Posted by developer:
 
This bug is not reproducible with the latest Connector/J 8.0.

Connector/J 5.1 series came to EOL on Feb 9th, 2021, see https://www.mysql.com/support/eol-notice.html, so this bug will not be fixed there.

Portions of this website are copyright © 2001, 2002 The PHP Group

Page generated in 0.039 sec. using MySQL 8.4.7-u6-cloud

Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.