diff --git a/okhttp/src/main/kotlin/okhttp3/internal/platform/android/AndroidSocketAdapter.kt b/okhttp/src/main/kotlin/okhttp3/internal/platform/android/AndroidSocketAdapter.kt index 35a38641355a..e849bbe20874 100644 --- a/okhttp/src/main/kotlin/okhttp3/internal/platform/android/AndroidSocketAdapter.kt +++ b/okhttp/src/main/kotlin/okhttp3/internal/platform/android/AndroidSocketAdapter.kt @@ -17,7 +17,6 @@ package okhttp3.internal.platform.android import java.lang.reflect.InvocationTargetException import java.lang.reflect.Method -import java.nio.charset.StandardCharsets import javax.net.ssl.SSLSocket import okhttp3.Protocol import okhttp3.internal.platform.AndroidPlatform @@ -79,17 +78,16 @@ open class AndroidSocketAdapter(private val sslSocketClass: Class) return try { val alpnResult = getAlpnSelectedProtocol.invoke(sslSocket) as ByteArray? - if (alpnResult != null) String(alpnResult, StandardCharsets.UTF_8) else null - } catch (e: NullPointerException) { - when { - // https://github.com/square/okhttp/issues/5587 - e.message == "ssl == null" -> null - else -> throw e - } + alpnResult?.toString(Charsets.UTF_8) } catch (e: IllegalAccessException) { throw AssertionError(e) } catch (e: InvocationTargetException) { - throw AssertionError(e) + // https://github.com/square/okhttp/issues/5587 + val cause = e.cause + when { + cause is NullPointerException && cause.message == "ssl == null" -> null + else -> throw AssertionError(e) + } } }