You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the extractAndWrapCause method of AwsSdk2Transport, when handling an ExecutionException, the code assumes that executionException.getCause() is always an Exception or Error.
However, getCause() can return a Throwable that is neither an Exception nor an Error.
If the cause is another type of Throwable (e.g., a custom subclass that is neither Error nor Exception), the following line will cause a ClassCastException:
exception = (Exception)t;
This results in the loss of the original exception details.
How can one reproduce the bug?
This issue can be reproduced when using NettyNioAsyncHttpClient as the SdkAsyncHttpClient with a low connectionAcquisitionTimeout value.
Steps to reproduce:
1. Set up an OpenSearchClient using AwsSdk2Transport with NettyNioAsyncHttpClient.
2. Configure the client with a very low connectionAcquisitionTimeout, such as 1 millisecond.
3. Attempt to make a request to OpenSearch
4. When a connectionAcquisitionTimeout occurs, it triggers an ExecutionException.
5. The extractAndWrapCause method processes the exception, but if the cause is a Throwable that is neither an Error nor an Exception, a ClassCastException is thrown.
This results in the loss of the original exception context, making it difficult to diagnose the actual timeout issue.
What is the expected behavior?
When a connectionAcquisitionTimeout occurs, the exception should be correctly propagated without causing a ClassCastException.
• If the cause of ExecutionException is an Error, it should be rethrown (which is already handled correctly in the current implementation).
• If the cause is an Exception, it should be processed as intended.
• If the cause is a Throwable that is neither an Error nor an Exception, the code should not attempt to cast it to an Exception, as this leads to a ClassCastException. Instead, it should be wrapped in a more appropriate exception (e.g., RuntimeException).
What is your host/environment?
Mac OS Sonoma 14.6
opensearch-java:2.22.0
netty-nio-client:2.30.37
org.springframework.boot 3.2.7
Do you have any screenshots?
N/A
If possible, I would be happy to create a PR to fix this issue.
The text was updated successfully, but these errors were encountered:
wonthechan
changed the title
[BUG] ClassCastException Occurs in extractAndWrapCause Method of AwsSdk2Transport When ExecutionException's Cause is Not an Exception or Error
[BUG] ClassCastException occurs in extractAndWrapCause method of AwsSdk2Transport when ExecutionException's cause is not an Exception or Error
Mar 14, 2025
What is the bug?
In the extractAndWrapCause method of AwsSdk2Transport, when handling an ExecutionException, the code assumes that executionException.getCause() is always an Exception or Error.
However, getCause() can return a Throwable that is neither an Exception nor an Error.
If the cause is another type of Throwable (e.g., a custom subclass that is neither Error nor Exception), the following line will cause a ClassCastException:
exception = (Exception)t;
This results in the loss of the original exception details.
How can one reproduce the bug?
This issue can be reproduced when using NettyNioAsyncHttpClient as the SdkAsyncHttpClient with a low connectionAcquisitionTimeout value.
Steps to reproduce:
1. Set up an OpenSearchClient using AwsSdk2Transport with NettyNioAsyncHttpClient.
2. Configure the client with a very low connectionAcquisitionTimeout, such as 1 millisecond.
3. Attempt to make a request to OpenSearch
4. When a connectionAcquisitionTimeout occurs, it triggers an ExecutionException.
5. The extractAndWrapCause method processes the exception, but if the cause is a Throwable that is neither an Error nor an Exception, a ClassCastException is thrown.
This results in the loss of the original exception context, making it difficult to diagnose the actual timeout issue.
What is the expected behavior?
When a connectionAcquisitionTimeout occurs, the exception should be correctly propagated without causing a ClassCastException.
• If the cause of ExecutionException is an Error, it should be rethrown (which is already handled correctly in the current implementation).
• If the cause is an Exception, it should be processed as intended.
• If the cause is a Throwable that is neither an Error nor an Exception, the code should not attempt to cast it to an Exception, as this leads to a ClassCastException. Instead, it should be wrapped in a more appropriate exception (e.g., RuntimeException).
What is your host/environment?
Mac OS Sonoma 14.6
opensearch-java:2.22.0
netty-nio-client:2.30.37
org.springframework.boot 3.2.7
Do you have any screenshots?
N/A
If possible, I would be happy to create a PR to fix this issue.
The text was updated successfully, but these errors were encountered: