Bug #79920 NPE when executing update to MySQL Fabric
Submitted: 11 Jan 2016 21:31 Modified: 5 Dec 2018 1:05
Reporter: Martin Kirchner Email Updates:
Status: Won't fix Impact on me:
None 
Category:Connector / J Severity:S3 (Non-critical)
Version:5.1.38 OS:Any
Assigned to: Assigned Account CPU Architecture:Any

[11 Jan 2016 21:31] Martin Kirchner
Description:
If I create a FabricMySQLDataSource and connect to a Fabric node I get a ClassCastException:

Exception in thread "main" org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: java.lang.ClassCastException: java.lang.String cannot be cast to java.util.List
	at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:80)
	at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:390)
	at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:439)
	at de.cas.tools.mysql.clusterdemo.ContinousDataInserter.dropTable(ContinousDataInserter.java:122)
	at de.cas.tools.mysql.clusterdemo.ContinousDataInserter.run(ContinousDataInserter.java:96)
	at de.cas.tools.mysql.clusterdemo.ContinousDataInserter.main(ContinousDataInserter.java:85)
Caused by: java.sql.SQLException: java.lang.ClassCastException: java.lang.String cannot be cast to java.util.List
	at com.mysql.fabric.jdbc.FabricMySQLDriver.connect(FabricMySQLDriver.java:80)
	at com.mysql.fabric.jdbc.FabricMySQLDataSource.getConnection(FabricMySQLDataSource.java:123)
	at com.mysql.jdbc.jdbc2.optional.MysqlDataSource.getConnection(MysqlDataSource.java:139)
	at com.mysql.jdbc.jdbc2.optional.MysqlDataSource.getConnection(MysqlDataSource.java:109)
	at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:111)
	at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:77)
	... 5 more

In Connector/J 5.1.35 the bug does not exist.

How to repeat:
Create the DataSource like this:

final FabricMySQLDataSource fabricDS=new FabricMySQLDataSource();
fabricDS.setUrl(url);
fabricDS.setUser(user);
fabricDS.setPassword(password);
fabricDS.setFabricServerGroup("innovationspace");
fabricDS.setFabricUsername("admin");
fabricDS.setFabricPassword("secret");

And retrieve a connection (I used a Spring JdbcTemplate).
See screenshot.

Suggested fix:
Use the correct index in com.mysql.fabric.DumpResponse.DumpResponse(List<?>).
See screenshot.
[11 Jan 2016 21:33] Martin Kirchner
Debugger view - Incorrect index

Attachment: 2016-01-11 22_29_18-Open-2.0 _ Ohne OSGi - Debug - com.mysql.fabric.DumpResponse - Eclipse.png (image/png, text), 72.79 KiB.

[28 Jan 2016 17:58] Jess Balint
Thanks for the bug report. It appears you are not using 5.1.38 but an older version of the connector. Can you describe how you deploy the connector in your application and how you verify that there is not another version present?
[5 Feb 2016 14:48] Martin Kirchner
It's a simple demo application. The dependencies are managed in a maven pom.xml. So I am quite sure that the version was correct.
I tried to reproduce it. However in the meantime I changed the code and now get a NullPointerException (same in 5.1.38 and 5.1.35).

java.lang.NullPointerException: null
	at com.mysql.jdbc.StatementImpl$CancelTask.<init>(StatementImpl.java:86) ~[mysql-connector-java-5.1.38.jar:5.1.38]
	at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1853) ~[mysql-connector-java-5.1.38.jar:5.1.38]
	at com.mysql.jdbc.PreparedStatement.executeUpdateInternal(PreparedStatement.java:2073) ~[mysql-connector-java-5.1.38.jar:5.1.38]
	at com.mysql.jdbc.PreparedStatement.executeUpdateInternal(PreparedStatement.java:2009) ~[mysql-connector-java-5.1.38.jar:5.1.38]
	at com.mysql.jdbc.PreparedStatement.executeLargeUpdate(PreparedStatement.java:5094) ~[mysql-connector-java-5.1.38.jar:5.1.38]
	at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1994) ~[mysql-connector-java-5.1.38.jar:5.1.38]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_72]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_72]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_72]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_72]
	at com.mysql.jdbc.MultiHostConnectionProxy$JdbcInterfaceProxy.invoke(MultiHostConnectionProxy.java:103) ~[mysql-connector-java-5.1.38.jar:5.1.38]
	at com.sun.proxy.$Proxy7.executeUpdate(Unknown Source) ~[na:na]
	at org.springframework.jdbc.core.JdbcTemplate$2.doInPreparedStatement(JdbcTemplate.java:873) ~[spring-jdbc-4.2.3.RELEASE.jar:4.2.3.RELEASE]
	at org.springframework.jdbc.core.JdbcTemplate$2.doInPreparedStatement(JdbcTemplate.java:866) ~[spring-jdbc-4.2.3.RELEASE.jar:4.2.3.RELEASE]
	at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:629) ~[spring-jdbc-4.2.3.RELEASE.jar:4.2.3.RELEASE]
	at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:866) ~[spring-jdbc-4.2.3.RELEASE.jar:4.2.3.RELEASE]
	at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:927) ~[spring-jdbc-4.2.3.RELEASE.jar:4.2.3.RELEASE]
	at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:937) ~[spring-jdbc-4.2.3.RELEASE.jar:4.2.3.RELEASE]
	at de.cas.tools.mysql.clusterdemo.ClusterDemo$1.doInTransaction(ClusterDemo.java:136) ~[classes/:na]
	at de.cas.tools.mysql.clusterdemo.ClusterDemo$1.doInTransaction(ClusterDemo.java:1) ~[classes/:na]
	at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:133) ~[spring-tx-4.2.3.RELEASE.jar:4.2.3.RELEASE]
	at de.cas.tools.mysql.clusterdemo.ClusterDemo.executeInTransaction(ClusterDemo.java:162) [classes/:na]
	at de.cas.tools.mysql.clusterdemo.ClusterDemo.insertData(ClusterDemo.java:133) [classes/:na]
	at de.cas.tools.mysql.clusterdemo.ClusterDemo.run(ClusterDemo.java:97) [classes/:na]
	at de.cas.tools.mysql.clusterdemo.ClusterDemo.main(ClusterDemo.java:79) [classes/:na]

Anyway I'll attach my latest source code version (that one with the NPE).
[5 Feb 2016 15:49] Jess Balint
Thanks Martin. We'll check into this.
[5 Dec 2018 1:05] Filipe Silva
MySQL Fabric is no longer supported. Users are encouraged to migrate to MySQL InnoDB Cluster (https://dev.mysql.com/doc/refman/en/mysql-innodb-cluster-userguide.html).