Bug #101596 Get the 'host' property error after calling transformProperties() method
Submitted: 13 Nov 2020 8:36 Modified: 5 Mar 2021 19:31
Reporter: Yifan Qian (OCA) Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / J Severity:S3 (Non-critical)
Version:8.0.12 and later OS:Any
Assigned to: CPU Architecture:Any

[13 Nov 2020 8:36] Yifan Qian
Description:
when specifying the 'propertiesTransform' property in URL, the driver will getting the 'host' property from transformed properties after call transformProperties() method, it should use the 'PropertyKey.HOST.getKeyName()' instead of 'PropertyKey.PORT.getKeyName()'. That was a slip of the pen. 

How to repeat:
1. Use mysql-connector-java-8.0.22.jar(or mysql-connector-java-8.0.12.jar and later)
2. Specifying the 'propertiesTransform' property in the URL, you need do nothing in the transform implementation
3. Try to get a connection and there would be a error because of the driver will use the 'PropertyKey.PORT.getKeyName()' key to get the 'host' property value

Suggested fix:
Replace lines 734 in the 'com.mysql.cj.conf.ConnectionUrl' class(version: 8.0.22) with the following:

host = transformedProps.getProperty(PropertyKey.HOST.getKeyName());
[13 Nov 2020 8:57] Yifan Qian
Please see the PR at  https://github.com/mysql/mysql-connector-j/pull/57
[13 Nov 2020 11:41] Filipe Silva
Hi Yifan Qian,

So true! Thank you for your contribution.
[13 Nov 2020 11:47] Filipe Silva
Please don't forget to sign the OCA so that we can use your patch and give you attribution for it.

Thanks again.
[5 Mar 2021 19:31] Daniel So
Posted by developer:
 
Added the following entry to the Connector/J 8.0.24 changelog: 

"Connections to a server could not be established when the user supplied an implementation of the ConnectionPropertiesTransform interface using the connection property peopertiesTransform. This was because Connector/J called PropertyKey.PORT.getKeyName() instead of PropertyKey.HOSt.getKeyName() for getting the host name, and that has been corrected by this fix."