Undefined behavior when JDBC connection string and properties contain conflicting parameters.
Details
| Detail name | Value |
|---|---|
| Changelog Number | 24636 |
| Type | Improvement |
| Status | Resolved |
| Fix Versions | JDBC 25.2.3 |
| Resolution Date | 2025-04-11 |
Description
When a parameter is provided in both the JDBC connection string and the properties, the parameter value defined in the connection string is overwritten by the value from the properties. This behavior may lead to unintended and undefined behavior.
Steps to Reproduce
Code Example
String connectionString = "jdbc:exa:localhost:8795;fingerprint=conn_fingerprint";
Properties properties = new Properties();
properties.setProperty("fingerprint", "prop_fingerprint");
Connection connection = DriverManager.getConnection(connectionString, properties);
// Value used by the driver: prop_fingerprint
Observed Behavior
The fingerprint parameter from the Properties instance (prop_fingerprint) overwrites the value from the connection string (conn_fingerprint). This behavior is unexpected and not intended.
Desired Behavior
An exception should be thrown when the same parameter is provided in both the connection string and the properties with conflicting, non-empty values.
Fix
New Behavior
An exception will be thrown when the same parameter exists in both the connection string and properties, and their values are conflicting (i.e. non-identical and non-empty).
Exception Message
Parameter (parameterName) is provided in both connection string and properties with conflicting non-empty values.
Allowed Scenarios
- If one of the values is empty, the non-empty value will be used.
- If the values are identical, the parameter is accepted without throwing an exception.
Changed behavior
Previous Behavior
The Properties values would silently overwrite conflicting values from the connection string.
New Behavior
An exception will be thrown when conflicting, non-empty values are detected in both the connection string and properties.