Skip to content

Commit

Permalink
Fix Conscrypt NPE workaround (#7219) (#7230)
Browse files Browse the repository at this point in the history
(cherry picked from commit 6ba23dc)

Co-authored-by: Phil Glass <phil@phil.glass>
  • Loading branch information
yschimke and PhilGlass authored Apr 9, 2022
1 parent 5aa716a commit c657392
Showing 1 changed file with 7 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -79,17 +78,16 @@ open class AndroidSocketAdapter(private val sslSocketClass: Class<in SSLSocket>)

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)
}
}
}

Expand Down

0 comments on commit c657392

Please sign in to comment.