Skip to content

Commit

Permalink
Fixed NPE with SslMode.TUNNEL Usage
Browse files Browse the repository at this point in the history
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 GoogleCloudPlatform/cloud-sql-jdbc-socket-factory#1828
  • Loading branch information
jchrys committed Feb 7, 2024
1 parent 6982acc commit ad9fc41
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/main/java/io/asyncer/r2dbc/mysql/ConnectionContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit ad9fc41

Please sign in to comment.