diff --git a/src/main/java/org/mariadb/jdbc/internal/protocol/AbstractConnectProtocol.java b/src/main/java/org/mariadb/jdbc/internal/protocol/AbstractConnectProtocol.java
index <HASH>..<HASH> 100644
--- a/src/main/java/org/mariadb/jdbc/internal/protocol/AbstractConnectProtocol.java
+++ b/src/main/java/org/mariadb/jdbc/internal/protocol/AbstractConnectProtocol.java
@@ -1334,7 +1334,7 @@ public abstract class AbstractConnectProtocol implements Protocol {
     }
 
     public String getTraces() {
-        if (options.enablePacketDebug) return traceCache.printStack();
+        if (options.enablePacketDebug && traceCache != null) return traceCache.printStack();
         return "";
     }
 }
[misc] ensure stability if option "enablePacketDebug" is set and IOException occur in when establishing socket