[CONJ-1137] NPE in OkPacket when setting auto commit Created: 2023-12-08  Updated: 2023-12-11  Resolved: 2023-12-11

Status: Closed
Project: MariaDB Connector/J
Component/s: Other
Affects Version/s: 3.1.4
Fix Version/s: 3.3.2

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

Database:
AWS RDS MariaDB 10.5.21 with RDS Proxy

Application:
SpringBoot 2.7
MariaDB Connector 3.1.4

Base docker image:
adoptopenjdk/openjdk11-openj9:jre



 Description   

We are encountering occasional NPE in production environment.

When our spring based application starts to create transaction and set auto commit to false (which is calling `Connection.setAutoCommit()`), NPE is thrown in https://github.com/mariadb-corporation/mariadb-connector-j/blob/3.1.4/src/main/java/org/mariadb/jdbc/message/server/OkPacket.java#L52C19-L52C19

Given line 51, `database` is possible to be null while in line 52 it's trying to invoke `database.isEmpty()`, therefore NPE is thrown.

In addition, may I ask why calling `Connection.setAutoCommit()` can result in having `StateChange.SESSION_TRACK_SCHEMA` in the OkPacket?
and in what situation `StateChange.SESSION_TRACK_SCHEMA` will be returned but the subsequent data will be null?



 Comments   
Comment by Diego Dupin [ 2023-12-08 ]

Database can initially be null, but can be changed to some value. There is normally no way to changing that to null afterwhile, so implementation was designed that way. I need to identify why this case occurs first, but correction will be done whatever.

Comment by Mike Chung [ 2023-12-08 ]

Thanks Diego. Please let me know what I could help on troubleshooting.

May I know if we have an expected timeline on this correction? Thanks in advance.

Comment by Diego Dupin [ 2023-12-11 ]

I haven't been able to reproduce it, but i suspect this is because of RDS Proxy use.
Anyway, correction is easily done to avoid that, and this will be part of 3.3.2

available as 3.3.2-SNAPSHOT now (release will be during the next week):

<repositories>
	<repository>
		<id>sonatype-nexus-snapshots</id>
		<name>Sonatype Nexus Snapshots</name>
		<url>https://oss.sonatype.org/content/repositories/snapshots</url>
	</repository>
</repositories>
 
<dependencies>
	<dependency>
		<groupId>org.mariadb.jdbc</groupId>
		<artifactId>mariadb-java-client</artifactId>
		<version>3.3.2-SNAPSHOT</version>
	</dependency>
</dependencies>

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