Skip to content

Commit 1f578cd

Browse files
Fix ClassCastException in extractAndWrapCause when handling Execution… (#1483)
* Fix ClassCastException in extractAndWrapCause when handling ExecutionException Signed-off-by: Yechan Lim <[email protected]> * Use UndeclaredThrowableException instead of RuntimeException Signed-off-by: Yechan Lim <[email protected]> --------- Signed-off-by: Yechan Lim <[email protected]> (cherry picked from commit a116304) Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 9210f0d commit 1f578cd

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
1313
### Removed
1414

1515
### Fixed
16-
16+
- Fixed ClassCastException in extractAndWrapCause when handling ExecutionException ([#1483](https://github.com/opensearch-project/opensearch-java/pull/1483))
1717
### Security
1818

1919
## [2.22.0] - 03/05/2025

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

+6-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import java.io.IOException;
1515
import java.io.InputStream;
1616
import java.io.UnsupportedEncodingException;
17+
import java.lang.reflect.UndeclaredThrowableException;
1718
import java.net.ConnectException;
1819
import java.net.SocketTimeoutException;
1920
import java.net.URI;
@@ -694,7 +695,11 @@ private static Exception extractAndWrapCause(Exception exception) {
694695
if (t instanceof Error) {
695696
throw (Error) t;
696697
}
697-
exception = (Exception) t;
698+
if (t instanceof Exception) {
699+
exception = (Exception) t;
700+
} else {
701+
exception = new UndeclaredThrowableException(t);
702+
}
698703
}
699704
if (exception instanceof SocketTimeoutException) {
700705
SocketTimeoutException e = new SocketTimeoutException(exception.getMessage());

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

+6-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import java.io.IOException;
1616
import java.io.InputStream;
1717
import java.io.OutputStream;
18+
import java.lang.reflect.UndeclaredThrowableException;
1819
import java.net.ConnectException;
1920
import java.net.SocketTimeoutException;
2021
import java.net.URI;
@@ -1107,7 +1108,11 @@ private static Exception extractAndWrapCause(Exception exception) {
11071108
if (t instanceof Error) {
11081109
throw (Error) t;
11091110
}
1110-
exception = (Exception) t;
1111+
if (t instanceof Exception) {
1112+
exception = (Exception) t;
1113+
} else {
1114+
exception = new UndeclaredThrowableException(t);
1115+
}
11111116
}
11121117
if (exception instanceof ConnectTimeoutException) {
11131118
ConnectTimeoutException e = new ConnectTimeoutException(exception.getMessage());

0 commit comments

Comments
 (0)