[CONJ-616] Null Pointer Exception on getConnection() Created: 2018-05-31  Updated: 2019-02-08  Resolved: 2018-09-03

Status: Closed
Project: MariaDB Connector/J
Component/s: Failover
Affects Version/s: 2.2.4, 2.2.5, 2.2.6
Fix Version/s: 2.3.0, 1.8.0

Type: Bug Priority: Critical
Reporter: Joseph Witthuhn Assignee: Diego Dupin
Resolution: Fixed Votes: 0
Labels: None
Environment:

Amazon Linux
Java 8



 Description   

We are connecting to an AWS Aurora RDS datasource using a connection string that looks like this:
jdbc:mariadb:aurora://XXXXX.cluster-XXXXX.eu-west-1.rds.amazonaws.com:3306/XXXXX?socketTimeout=0&useSSL=true&connectTimeout=31000

When calling getConnection(), we see this error message. It looks like there is a NullPointerException occuring somewhere within the driver code:

java.lang.NullPointerException: null
	at org.mariadb.jdbc.internal.failover.AbstractMastersListener.throwFailoverMessage(AbstractMastersListener.java:506)
	at org.mariadb.jdbc.internal.failover.impl.MastersSlavesListener.checkInitialConnection(MastersSlavesListener.java:300)
	at org.mariadb.jdbc.internal.failover.impl.MastersSlavesListener.initializeConnection(MastersSlavesListener.java:169)
	at org.mariadb.jdbc.internal.failover.FailoverProxy.<init>(FailoverProxy.java:116)
	at org.mariadb.jdbc.internal.util.Utils.retrieveProxy(Utils.java:485)
	at org.mariadb.jdbc.MariaDbConnection.newConnection(MariaDbConnection.java:155)
	at org.mariadb.jdbc.MariaDbDataSource.getConnection(MariaDbDataSource.java:288)

We first saw this after upgrading to 2.2.5.



 Comments   
Comment by Joseph Witthuhn [ 2018-06-04 ]

It turns out this wasn't related to the upgrade to 2.2.5, but 2.2.5 has a change that changed it from a meaningful exception to this NullPointerException.

If we downgrade to 2.2.4, we get a better stack trace.

java.sql.SQLException: Communications link failure with primary. No active connection found for master. 
	at org.mariadb.jdbc.internal.failover.AbstractMastersListener.throwFailoverMessage(AbstractMastersListener.java:487)
	at org.mariadb.jdbc.internal.failover.impl.MastersSlavesListener.checkInitialConnection(MastersSlavesListener.java:176)
	at org.mariadb.jdbc.internal.failover.impl.MastersSlavesListener.initializeConnection(MastersSlavesListener.java:162)
	at org.mariadb.jdbc.internal.failover.FailoverProxy.<init>(FailoverProxy.java:101)
	at org.mariadb.jdbc.internal.util.Utils.retrieveProxy(Utils.java:477)
	at org.mariadb.jdbc.MariaDbConnection.newConnection(MariaDbConnection.java:150)
	at org.mariadb.jdbc.MariaDbDataSource.getConnection(MariaDbDataSource.java:288)
	...

Despite the fact that the underlying issue is with our connection string and not a problem with the driver, I still think we wouldn't want an incorrect hostname in a connection string to lead to an NPE, so I'll leave this open, but lower the priority.

Comment by Joseph Witthuhn [ 2018-06-07 ]

We are actually getting a different NullPointerException in 2.2.4, but at a very low frequency (about 1 time in every 200 connection attempts). We rolled back to 2.2.1 (which we have been using since January without issue), and the issue went away.

java.lang.NullPointerException: null
	at sun.reflect.GeneratedMethodAccessor56.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.mariadb.jdbc.internal.failover.AbstractMastersListener.invoke(AbstractMastersListener.java:381)
	at org.mariadb.jdbc.internal.failover.FailoverProxy.executeInvocation(FailoverProxy.java:229)
	at org.mariadb.jdbc.internal.failover.FailoverProxy.invoke(FailoverProxy.java:222)
	at com.sun.proxy.$Proxy17.versionGreaterOrEqual(Unknown Source)
	at org.mariadb.jdbc.MariaDbConnection.<init>(MariaDbConnection.java:128)
	at org.mariadb.jdbc.MariaDbConnection.newConnection(MariaDbConnection.java:151)
	at org.mariadb.jdbc.Driver.connect(Driver.java:86)

This might belong as a separate bug report - I can create a separate issue if you'd prefer it to be reported that way.

Comment by Joseph Witthuhn [ 2018-08-23 ]

We continue to see the same NullPointerException issue from 2.2.5 in 2.2.6.

Here is an updated stack trace with updated line numbers for 2.2.6:

java.lang.NullPointerException: null
               at org.mariadb.jdbc.internal.failover.impl.MastersSlavesListener.versionGreaterOrEqual(MastersSlavesListener.java:223)
               at org.mariadb.jdbc.internal.failover.FailoverProxy.invoke(FailoverProxy.java:163)
               at com.sun.proxy.$Proxy18.versionGreaterOrEqual(Unknown Source)
               at org.mariadb.jdbc.MariaDbConnection.<init>(MariaDbConnection.java:133)
               at org.mariadb.jdbc.MariaDbConnection.newConnection(MariaDbConnection.java:156)
               at org.mariadb.jdbc.Driver.connect(Driver.java:86)
               at org.flywaydb.core.internal.util.jdbc.DriverDataSource.getConnectionFromDriver(DriverDataSource.java:409)
               at org.flywaydb.core.internal.util.jdbc.DriverDataSource.getConnection(DriverDataSource.java:370)
               at org.flywaydb.core.internal.util.jdbc.JdbcUtils.openConnection(JdbcUtils.java:50)
               at org.flywaydb.core.Flyway.execute(Flyway.java:1327)

(The context here is that the calls are coming via Flyway 4.0.3...)

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