Skip to content

Commit 3408ef7

Browse files
authored
Fix an issue where NPE could be thrown when a request fails before timer starts (#3096)
1 parent 1032916 commit 3408ef7

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"category": "AWS SDK for Java v2",
3+
"contributor": "",
4+
"type": "bugfix",
5+
"description": "Fixed an issue where NPE could be thrown when a request failed before API call timer started"
6+
}

.idea/inspectionProfiles/AWS_Java_SDK_2_0.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ 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.apiCallTimeoutTracker().hasExecuted()) {
114+
if (apiCallTimerExecuted(context)) {
115115
// Clear the interrupt flag. Since we already have an exception from the call, which may contain information
116116
// that's useful to the caller, just return that instead of an ApiCallTimeoutException.
117117
Thread.interrupted();
@@ -133,7 +133,7 @@ private RuntimeException handleInterruptedException(RequestExecutionContext cont
133133
if (e instanceof SdkInterruptedException) {
134134
((SdkInterruptedException) e).getResponseStream().ifPresent(r -> invokeSafely(r::close));
135135
}
136-
if (context.apiCallTimeoutTracker().hasExecuted()) {
136+
if (apiCallTimerExecuted(context)) {
137137
// Clear the interrupt status
138138
Thread.interrupted();
139139
return generateApiCallTimeoutException(context);
@@ -143,6 +143,10 @@ private RuntimeException handleInterruptedException(RequestExecutionContext cont
143143
return AbortedException.create("Thread was interrupted", e);
144144
}
145145

146+
private static boolean apiCallTimerExecuted(RequestExecutionContext context) {
147+
return context.apiCallTimeoutTracker() != null && context.apiCallTimeoutTracker().hasExecuted();
148+
}
149+
146150
private ApiCallTimeoutException generateApiCallTimeoutException(RequestExecutionContext context) {
147151
return ApiCallTimeoutException.create(
148152
resolveTimeoutInMillis(context.requestConfig()::apiCallTimeout, apiCallTimeout));

0 commit comments

Comments
 (0)