[Backport] Fix exception propagation in Async API methods #1485
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR is a partial backport of PR #1479.
CSOT-related logic is not included in this backport as the 5.1.x branch does not support CSOT. Only code changes relevant to the functionality in 5.1.x are included.
Backported Changes:
Exception handling in Async API:
Resolved an issue where exceptions thrown during thenRun, thenSupply, and related operations in the asynchronous API were not properly propagated to the completion callback. This was fixed by replacing unsafeFinish with finish, ensuring exceptions are caught and correctly passed to the completion callback, even when executed on different threads.
Async API test updates:
Updated existing Async API tests to simulate execution on separate async threads, ensuring accurate testing of the asynchronous behavior.
Local exception handling in async callbacks:
Modified the async callback to catch and handle exceptions locally. Now, exceptions are directly processed and passed as an error argument to the callback function, avoiding unintended propagation to the parent callback.
JIRA Ticket
JAVA-5562