[CONJ-934] MariaDbDataSource is sensitive to the order of setting of username and password Created: 2022-02-20  Updated: 2022-03-03  Resolved: 2022-03-03

Status: Closed
Project: MariaDB Connector/J
Component/s: configuration
Affects Version/s: 3.0.3
Fix Version/s: 3.0.4

Type: Bug Priority: Major
Reporter: Chris Selwyn Assignee: Diego Dupin
Resolution: Fixed Votes: 0
Labels: None
Environment:

Payara 5.2022.1
OpenJDK 11.0.5
Fedora Core 29



 Description   

If the password happens to be set first before the user then the connection will fail.

The problem occurs in the config() method...

  private void config() throws SQLException {
    if (url == null) throw new SQLException("url not set");
    conf = Configuration.parse(url);
    if (loginTimeout != null) conf.connectTimeout(loginTimeout * 1000);
    if (user != null) {
      conf = conf.clone(user, password);
    } else {
      user = conf.user();
      password = conf.password();
    }
  }

If the password is set before the user (i.e. user is null when config() is called) then the statement

      password = conf.password();

overwrites the password with null (assuming that there is no password in the URL).
Any subsequent call to getConnection() will likely fail because the connection will be attempted without a password.

In Payara/Glassfish the order of setting of the connection properties is governed by the code in com.sun.gjc.common.DataSourceObjectBuilder.constructDataSourceObject() which uses reflection to discover the driver's properties. The methods are invoked in the (arbitrary) order of discovery, so the order is not controllable by the user.
It depends on what the eventual result should be as to what the solution is. Should parameters in the URL take precedence over explicit property settings?



 Comments   
Comment by Diego Dupin [ 2022-03-03 ]

corrected with commit https://github.com/mariadb-corporation/mariadb-connector-j/commit/abc89b6adbfe00e1ffe75de0e8ebd92cde2973b5

Generated at Thu Feb 08 03:19:23 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.