Skip to content

Commit fd33f16

Browse files
committed
Refactored code according to comments
1 parent e96c109 commit fd33f16

File tree

2 files changed

+24
-11
lines changed

2 files changed

+24
-11
lines changed

core/aws-core/src/main/java/software/amazon/awssdk/awscore/interceptor/TraceIdExecutionInterceptor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
/**
3030
* The {@code TraceIdExecutionInterceptor} copies the trace details to the {@link #TRACE_ID_HEADER} header, assuming we seem to
31-
* be running in a lambda environment.
31+
* be running in a lambda environment.`
3232
*/
3333
@SdkProtectedApi
3434
public class TraceIdExecutionInterceptor implements ExecutionInterceptor {

utils-lite/src/main/java/software/amazon/awssdk/utilslite/SdkInternalThreadLocal.java

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,37 +32,50 @@ private SdkInternalThreadLocal() {
3232
}
3333

3434
public static void put(String key, String value) {
35-
Map<String, String> map = STORAGE.get();
36-
if (map == null) {
37-
map = new HashMap<>();
38-
STORAGE.set(map);
35+
if (key == null) {
36+
throw new IllegalArgumentException("Key cannot be null");
3937
}
40-
38+
Map<String, String> map = STORAGE.get();
4139
if (value == null) {
42-
map.remove(key);
40+
if (map != null) {
41+
map.remove(key);
42+
if (map.isEmpty()) {
43+
STORAGE.remove();
44+
}
45+
}
4346
} else {
47+
if (map == null) {
48+
map = new HashMap<>();
49+
STORAGE.set(map);
50+
}
4451
map.put(key, value);
4552
}
4653
}
4754

4855
public static String get(String key) {
56+
if (key == null) {
57+
throw new IllegalArgumentException("Key cannot be null");
58+
}
4959
Map<String, String> map = STORAGE.get();
5060
return map != null ? map.get(key) : null;
5161
}
5262

5363
public static String remove(String key) {
64+
if (key == null) {
65+
throw new IllegalArgumentException("Key cannot be null");
66+
}
5467
Map<String, String> map = STORAGE.get();
5568
return map != null ? map.remove(key) : null;
5669
}
5770

5871
public static void clear() {
59-
Map<String, String> map = STORAGE.get();
60-
if (map != null) {
61-
map.clear();
62-
}
72+
STORAGE.remove();
6373
}
6474

6575
public static boolean containsKey(String key) {
76+
if (key == null) {
77+
throw new IllegalArgumentException("Key cannot be null");
78+
}
6679
Map<String, String> map = STORAGE.get();
6780
return map != null && map.containsKey(key);
6881
}

0 commit comments

Comments
 (0)