Bug #119271 Connector/J fails to accept legacy value zeroDateTimeBehavior=convertToNull on multi-host URLs (failover), but works on
Submitted: 30 Oct 11:14 Modified: 8 Dec 6:23
Reporter: Wu Zhengyi (OCA) Email Updates:
Status: Verified Impact on me:
None 
Category:Connector / J Severity:S3 (Non-critical)
Version:All OS:Any
Assigned to: Filipe Silva CPU Architecture:Any
Tags: backward-compatibility, failover, multi-host, properties, zeroDateTimeBehavior

[30 Oct 11:14] Wu Zhengyi
Description:
When using a multi-host JDBC URL (failover) with the legacy property value zeroDateTimeBehavior=convertToNull, the driver throws an exception stating the only acceptable values are CONVERT_TO_NULL, EXCEPTION, or ROUND. The same property/value works with a single-host URL.
Root cause:
Legacy value translation is applied only per-host in fixHostInfo() via replaceLegacyPropertyValues(hostProps).
In the failover path, FailoverConnectionProxy initializes properties from ConnectionUrl.getConnectionArgumentsAsProperties(), which returns the global properties map (this.properties) that has not been passed through replaceLegacyPropertyValues.
As a result, convertToNull is not normalized to CONVERT_TO_NULL and enum parsing fails in EnumPropertyDefinition.
Impact:
Backward-compatible URLs that rely on convertToNull fail in multi-host scenarios, but succeed in single-host scenarios, creating inconsistent behavior.
Exception (abridged):
com.mysql.cj.exceptions.CJException: The connection property 'zeroDateTimeBehavior' acceptable values are: 'CONVERT_TO_NULL', 'EXCEPTION' or 'ROUND'. The value 'convertToNull' is not acceptable.

How to repeat:
Use a JDBC URL with two hosts and legacy value:
jdbc:mysql://host1:3306,host2:3306?useSSL=false&zeroDateTimeBehavior=convertToNull
Attempt to connect (e.g., via DriverManager.getConnection).
Observe: connection fails with WrongArgumentException as above.
Control:
Using a single host URL with the same parameters succeeds:
jdbc:mysql://host1:3306?useSSL=false&zeroDateTimeBehavior=convertToNull

Suggested fix:
Normalize legacy property values in the global properties map, not only in per-host maps.
Concrete change:
In com.mysql.cj.conf.ConnectionUrl.collectProperties(...), after expanding and injecting properties, call:
fixProtocolDependencies(this.properties) [optional but consistent], and
replaceLegacyPropertyValues(this.properties)
so that getConnectionArgumentsAsProperties() returns already-normalized values used by FailoverConnectionProxy and other multi-host connection proxies.
Rationale:
Single-host paths use HostInfo built through fixHostInfo(), which already calls replaceLegacyPropertyValues(hostProps).
Multi-host paths use global properties; normalizing them ensures parity between single- and multi-host behaviors.
Compatibility:
Safe; only broadens acceptance of legacy values in global properties, maintaining existing behavior for per-host properties.
[30 Oct 20:02] Filipe Silva
Thank you for your interest in MySQL Connector/J and for taking the time to file this report.

Verified as described.
[8 Dec 6:23] Wu Zhengyi
https://github.com/mysql/mysql-connector-j/pull/119
[9 Dec 12:02] Filipe Silva
Thank you for your contribution, but the issue is already being addressed internally.
[15 Dec 18:43] OCA Admin
Contribution submitted via Github - fix Bug #119271: Connector/J fails to accept legacy value zeroDateTimeBehavior=c 
(*) Contribution by Wu Zhengyi (Github wuzhengyi, mysql-connector-j/pull/119#issuecomment-3638095843): 
I confirm the code being submitted is offered under the terms of the OCA, and that I am authorized to contribute it.
---- Replied Message ----
| From | ***@***.***> |
| Date | 12/09/2025 22:54 |
| To | mysql/mysql-connector-j ***@***.***> |
| Cc | Zane ***@***.***>,
Author ***@***.***> |
| Subject | Re: [mysql/mysql-connector-j] fix Bug #119271: Connector/J fails to accept legacy value zeroDateTimeBehavior=convertToNull on multi-host URLs (failover), but works on (PR #119) |
mysql-oca-bot left a comment (mysql/mysql-connector-j#119)

Hi, thank you for your contribution. Please confirm this code is submitted under the terms of the OCA (Oracle''s Contribution Agreement) you have previously signed by cutting and pasting the following text as a comment:
"I confirm the code being submitted is offered under the terms of the OCA, and that I am authorized to contribute it."
Thanks

—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you authored the thread.Message ID: ***@***.***>

Contribution: git_patch_3074257288.txt (text/plain), 3.90 KiB.