Skip to content

Commit 09a4b8f

Browse files
authored
Fix potential NPE in ApiCallAttemptTimeoutTrackingStage (#6332)
* fix potential NullPointerException in ApiCallAttemptTimeoutTrackingStage when exception is thrown before the tracker can be set in the context * changelog * updated changelog description
1 parent 2f1b2d9 commit 09a4b8f

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"type": "bugfix",
3+
"category": "AWS SDK for Java v2",
4+
"contributor": "",
5+
"description": "Fix a potential NullPointerException that may be thrown when API call timeout is configured"
6+
}

core/sdk-core/src/main/java/software/amazon/awssdk/core/internal/http/pipeline/stages/ApiCallAttemptTimeoutTrackingStage.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ private Exception translatePipelineException(RequestExecutionContext context, Ex
111111
// but before we called timeoutTracker.cancel(). Note that if hasExecuted() returns true, its guaranteed that
112112
// the timeout tracker has set the interrupt flag, and if it returns false, it guarantees that it did not and
113113
// will never set the interrupt flag.
114-
if (context.apiCallAttemptTimeoutTracker().hasExecuted()) {
114+
TimeoutTracker timeoutTracker = context.apiCallAttemptTimeoutTracker();
115+
if (timeoutTracker != null && timeoutTracker.hasExecuted()) {
115116
// Clear the interrupt flag. Since we already have an exception from the call, which may contain information
116117
// that's useful to the caller, just return that instead of an ApiCallTimeoutException.
117118
Thread.interrupted();
@@ -136,7 +137,8 @@ private RuntimeException handleInterruptedException(RequestExecutionContext cont
136137
"Failed to close the response stream",
137138
r::close));
138139
}
139-
if (context.apiCallAttemptTimeoutTracker().hasExecuted()) {
140+
TimeoutTracker timeoutTracker = context.apiCallAttemptTimeoutTracker();
141+
if (timeoutTracker != null && timeoutTracker.hasExecuted()) {
140142
// Clear the interrupt status
141143
Thread.interrupted();
142144
return generateApiCallAttemptTimeoutException(context);

0 commit comments

Comments
 (0)