Skip to content

Commit bc9245f

Browse files
committed
Fix ClassCastException in extractAndWrapCause when handling ExecutionException
1 parent eab4091 commit bc9245f

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

java-client/src/main/java/org/opensearch/client/transport/aws/AwsSdk2Transport.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,11 @@ private static Exception extractAndWrapCause(Exception exception) {
694694
if (t instanceof Error) {
695695
throw (Error) t;
696696
}
697-
exception = (Exception) t;
697+
if (t instanceof Exception) {
698+
exception = (Exception) t;
699+
} else {
700+
exception = new RuntimeException("Unexpected throwable caught in execution", t);
701+
}
698702
}
699703
if (exception instanceof SocketTimeoutException) {
700704
SocketTimeoutException e = new SocketTimeoutException(exception.getMessage());

java-client/src/main/java/org/opensearch/client/transport/httpclient5/ApacheHttpClient5Transport.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -1107,7 +1107,11 @@ private static Exception extractAndWrapCause(Exception exception) {
11071107
if (t instanceof Error) {
11081108
throw (Error) t;
11091109
}
1110-
exception = (Exception) t;
1110+
if (t instanceof Exception) {
1111+
exception = (Exception) t;
1112+
} else {
1113+
exception = new RuntimeException("Unexpected throwable caught in execution", t);
1114+
}
11111115
}
11121116
if (exception instanceof ConnectTimeoutException) {
11131117
ConnectTimeoutException e = new ConnectTimeoutException(exception.getMessage());

0 commit comments

Comments
 (0)