[CONJ-775] Null Pointer Exception when attempting to close an invalid connection Created: 2020-03-24  Updated: 2020-04-02  Resolved: 2020-04-02

Status: Closed
Project: MariaDB Connector/J
Component/s: configuration
Affects Version/s: 2.6.0
Fix Version/s: 2.6.1

Type: Bug Priority: Major
Reporter: Willis Wendler Assignee: Diego Dupin
Resolution: Fixed Votes: 0
Labels: crash
Environment:

Red Hat Enterprise Linux release 8.1 (Ootpa)
mysql Ver 15.1 Distrib 10.3.17-MariaDB, for Linux (x86_64) using readline 5.1
openjdk version "1.8.0_222"



 Description   

I'm in the process of upgrading from MariaDB 5.5.56 to 10.3.17. As part of this I went from using mysql-connector-java version 5.1.35 to using mariadb-connector-java version 2.6.0. One of my java applications is now crashing at start up (the others are working with this setup). I've attached a stack trace and an approximate version of what my code is doing.

Looking at the mariaDB Connector/J code I see that AbstractConnectProtocol is calling SendClosePacket.send with a null PacketOutputStream. I'm not sure where the exact problem is but I think MariaDB Connector should at least be throwing a better exception.

if (!connection.isValid(0)) {
  connection.getConnection().close(); // exception happens here
}

  [ERROR] java.lang.NullPointerException
  [ERROR]         at org.mariadb.jdbc.internal.com.send.SendClosePacket.send(SendClosePacket.java:68)
  [ERROR]         at org.mariadb.jdbc.internal.protocol.AbstractConnectProtocol.close(AbstractConnectProtocol.java:382)
  [ERROR]         at org.mariadb.jdbc.internal.protocol.AbstractQueryProtocol.closeExplicit(AbstractQueryProtocol.java:1384)
  [ERROR]         at org.mariadb.jdbc.MariaDbConnection.close(MariaDbConnection.java:777)



 Comments   
Comment by Diego Dupin [ 2020-03-25 ]

NPE should of course never occur.

Reading code, the only possibility i found that could cause this is having a badly formed url connection like "jdbc:mariadb:///test" with 3 slashes.
Connection string format is :

jdbc:(mysql|mariadb):[replication:|loadbalance:|sequential:|aurora:]//<hostDescription>[,<hostDescription>...]/[database][?<key1>=<value1>[&<key2>=<value2>]]  

having 3 slashes means that there is no host. This is permitted, because of windows named pipe that will use option `pipe` then. But there is no test to ensure pipe is set if there is no host.

Could you confirm that this could correspond to your configuration ?

Comment by Willis Wendler [ 2020-03-25 ]

You're exactly right Diego! I was trying to connect to jdbc:mysql:///DBname essentially. Apparently the old mysql connector accepted the malformed url when connecting to a mariadb server running on localhost. The application works once I change the url it connects to.

Comment by Diego Dupin [ 2020-04-02 ]

commit to avoid repeating this: https://github.com/mariadb-corporation/mariadb-connector-j/commit/ab2e8dbc9a91ce768b02198bfcdc6ec5017bcd65

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