From ad9fc41319a97a17a16be25a3bcdd9e309afac72 Mon Sep 17 00:00:00 2001 From: jchrys Date: Thu, 8 Feb 2024 01:36:53 +0900 Subject: [PATCH] Fixed NPE with `SslMode.TUNNEL` Usage Motivation: A NPE was identified when utilizing `SslMode.TUNNEL`, introduced by PR #204. The issue arises when `ConnectionContext#isMariaDb` is invoked from `SslBridgeHandler#isTls13Enabled`, leading to an NPE due to the ConnectionContext not being initialized at that time. Modification: We have updated ConnectionContext#isMariaDb to return false if the context has not been initialized, preventing the NPE. (Mainly to restore previous behavior) Result: This change addresses the NPE issue, ensuring stability when `SslMode.TUNNEL` is selected. It resolves the problem reported in https://github.com/GoogleCloudPlatform/cloud-sql-jdbc-socket-factory/pull/1828 --- src/main/java/io/asyncer/r2dbc/mysql/ConnectionContext.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/io/asyncer/r2dbc/mysql/ConnectionContext.java b/src/main/java/io/asyncer/r2dbc/mysql/ConnectionContext.java index 3039ea19b..a1735caa8 100644 --- a/src/main/java/io/asyncer/r2dbc/mysql/ConnectionContext.java +++ b/src/main/java/io/asyncer/r2dbc/mysql/ConnectionContext.java @@ -57,6 +57,7 @@ public final class ConnectionContext implements CodecContext { */ private volatile short serverStatuses = ServerStatuses.AUTO_COMMIT; + @Nullable private volatile Capability capability = null; ConnectionContext(ZeroDateOption zeroDateOption, @Nullable Path localInfilePath, @@ -109,7 +110,8 @@ public ZoneId getServerZoneId() { @Override public boolean isMariaDb() { - return capability.isMariaDb() || serverVersion.isMariaDb(); + final Capability c = capability; + return c != null && (c.isMariaDb() || serverVersion.isMariaDb()); } boolean shouldSetServerZoneId() {