Skip to content

Commit e8adfa2

Browse files
committed
fix potential NullPointerException in ApiCallAttemptTimeoutTrackingStage when exception is thrown before the tracker can be set in the context
1 parent 6ffda0b commit e8adfa2

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

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)