From c06c714a43c90d21159e89f98e3b34fe1f52086c Mon Sep 17 00:00:00 2001 From: Chris Conlon Date: Mon, 3 Jan 2022 11:35:23 -0700 Subject: [PATCH] fix NullPointerException when no selected ALPN available --- src/java/com/wolfssl/WolfSSLSession.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/java/com/wolfssl/WolfSSLSession.java b/src/java/com/wolfssl/WolfSSLSession.java index ef6922a..24cae8f 100644 --- a/src/java/com/wolfssl/WolfSSLSession.java +++ b/src/java/com/wolfssl/WolfSSLSession.java @@ -2840,10 +2840,18 @@ public class WolfSSLSession { */ public String getAlpnSelectedString() throws IllegalStateException { + byte[] alpnSelectedBytes = null; + if (this.active == false) throw new IllegalStateException("Object has been freed"); - return new String(getAlpnSelected(), StandardCharsets.UTF_8); + alpnSelectedBytes = getAlpnSelected(); + + if (alpnSelectedBytes != null) { + return new String(alpnSelectedBytes, StandardCharsets.UTF_8); + } else { + return null; + } } /**