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