fix: Preserve thread interrupt status after catching InterruptedException #234
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.
Motivation and Context
When the sendMessage method catches an InterruptedException, it previously swallowed the interrupt without re-asserting the thread’s interrupt status. This can break cooperative interruption in multi-threaded environments and was flagged by SonarQube as a violation of best practices. Re-asserting the interrupt ensures that higher-level code can still detect and respond to the interruption.
How Has This Been Tested?
The change has been verified by running a full SonarQube scan on the project after the update. No new issues or warnings were reported, confirming that the change resolves the previously flagged issue related to interrupt handling without introducing regressions.
Breaking Changes
No. This change only affects internal error handling in the sendMessage method and does not modify any public APIs or require changes in user code or configurations.
Types of changes
Checklist
Additional context
This change makes the SDK more robust by properly handling InterruptedException. According to standard Java practices, when an InterruptedException is caught, the thread’s interrupt status should be preserved — which we now do by calling Thread.currentThread().interrupt(). This also resolves a SonarQube warning related to rule java:S2142.