Bug #95210 ClassCastException in BlobFromLocator when connecting as jdbc:mysql:replication
Submitted: 30 Apr 2019 16:36 Modified: 26 Jun 2019 16:35
Reporter: matt m Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / J Severity:S2 (Serious)
Version:8.0.15 OS:Any
Assigned to: CPU Architecture:Any

[30 Apr 2019 16:36] matt m
Description:
When using a connection that supports replication of the form
   
jdbc:mysql:replication://server1:6600,server2:6601/db?useCursorFetch=true&emulateLocators=true&enableQueryTimeouts=false&alwaysSendSetIsolation=false&autoClosePStmtStreams=true&nullCatalogMeansCurrent=true&pinGlobalTxToPhysicalConnection=true&sslMode=DISABLED 

calling read() on the stream returned from BlobFromLocator.getBinaryStream () results in a ClassCastException:

 java.lang.ClassCastException: com.sun.proxy.$Proxy110 cannot be cast to com.mysql.cj.jdbc.result.ResultSetImpl
	at com.mysql.cj.jdbc.BlobFromLocator.getBytesInternal(BlobFromLocator.java:482) ~[mysql-connector-java.jar:8.0.15]
	at com.mysql.cj.jdbc.BlobFromLocator$LocatorInputStream.read(BlobFromLocator.java:560) ~[mysql-connector-java.jar:8.0.15]
	at java.io.BufferedInputStream.fill(BufferedInputStream.java:246) ~[?:1.8.0_202]
	at java.io.BufferedInputStream.read1(BufferedInputStream.java:286) ~[?:1.8.0_202]
	at java.io.BufferedInputStream.read(BufferedInputStream.java:345) ~[?:1.8.0_202]

How to repeat:

Retrieve data from any BlobFromLocator utilizing a replicated (and I suspect loadbalanced) connection.

Suggested fix:
Workaround: don't use emulateLocators=true on loadbalanced connections.

Fix: Remove the cast since getBytes(int) is defined in the java.sql.ResultSet interface.
[21 May 2019 10:54] Alexander Soklakov
Hi Matt,

Thanks for the report and working solution!
[26 Jun 2019 16:35] Daniel So
Posted by developer:
 
Added the following entry to the Connector/J 8.0.17 changelog:

"When using a replication connection, retrieving data from a BlobFromLocator resulted in a ClassCastException. It was due to some wrong and unnecessary casting, which has been removed by this fix."