Skip to content

Commit c657392

Browse files
yschimkePhilGlass
andauthored
Fix Conscrypt NPE workaround (#7219) (#7230)
(cherry picked from commit 6ba23dc) Co-authored-by: Phil Glass <[email protected]>
1 parent 5aa716a commit c657392

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

okhttp/src/main/kotlin/okhttp3/internal/platform/android/AndroidSocketAdapter.kt

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ package okhttp3.internal.platform.android
1717

1818
import java.lang.reflect.InvocationTargetException
1919
import java.lang.reflect.Method
20-
import java.nio.charset.StandardCharsets
2120
import javax.net.ssl.SSLSocket
2221
import okhttp3.Protocol
2322
import okhttp3.internal.platform.AndroidPlatform
@@ -79,17 +78,16 @@ open class AndroidSocketAdapter(private val sslSocketClass: Class<in SSLSocket>)
7978

8079
return try {
8180
val alpnResult = getAlpnSelectedProtocol.invoke(sslSocket) as ByteArray?
82-
if (alpnResult != null) String(alpnResult, StandardCharsets.UTF_8) else null
83-
} catch (e: NullPointerException) {
84-
when {
85-
// https://github.com/square/okhttp/issues/5587
86-
e.message == "ssl == null" -> null
87-
else -> throw e
88-
}
81+
alpnResult?.toString(Charsets.UTF_8)
8982
} catch (e: IllegalAccessException) {
9083
throw AssertionError(e)
9184
} catch (e: InvocationTargetException) {
92-
throw AssertionError(e)
85+
// https://github.com/square/okhttp/issues/5587
86+
val cause = e.cause
87+
when {
88+
cause is NullPointerException && cause.message == "ssl == null" -> null
89+
else -> throw AssertionError(e)
90+
}
9391
}
9492
}
9593

0 commit comments

Comments
 (0)