Skip to content

Commit

Permalink
Catch IllegalArgumentException exception
Browse files Browse the repository at this point in the history
  • Loading branch information
gabekassel committed May 24, 2023
1 parent e172ea7 commit 6534a39
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions okhttp/src/main/java/io/grpc/okhttp/OkHttpProtocolNegotiator.java
Expand Up @@ -248,8 +248,19 @@ protected void configureTlsExtensions(
SET_USE_SESSION_TICKETS.invokeOptionalWithoutCheckedException(sslSocket, true);
}
if (SET_SERVER_NAMES != null && SNI_HOST_NAME != null) {
SET_SERVER_NAMES
.invoke(sslParams, Collections.singletonList(SNI_HOST_NAME.newInstance(hostname)));
try {
// SSLParameters.setServerNames(List<SNIServerName>) may throw IllegalArgumentException
// if an IP address that contains special characters (e.g. % for scope) is passed.
SET_SERVER_NAMES
.invoke(sslParams, Collections.singletonList(SNI_HOST_NAME.newInstance(hostname)));
} catch (InvocationTargetException e) {
Throwable targetException = e.getTargetException();
if (targetException instanceof IllegalArgumentException) {
SET_HOSTNAME.invokeOptionalWithoutCheckedException(sslSocket, hostname);
} else {
throw e;
}
}
} else {
SET_HOSTNAME.invokeOptionalWithoutCheckedException(sslSocket, hostname);
}
Expand Down

0 comments on commit 6534a39

Please sign in to comment.