Skip to content

Commit f79d145

Browse files
divconsnicoll
divcon
authored andcommitted
Use putIfAbsent in Netty5HeadersAdapter
See gh-30343
1 parent 5deab3a commit f79d145

File tree

2 files changed

+8
-12
lines changed

2 files changed

+8
-12
lines changed

spring-web/src/main/java/org/springframework/http/client/reactive/Netty5HeadersAdapter.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -91,11 +91,9 @@ public void setAll(Map<String, String> values) {
9191
@Override
9292
public Map<String, String> toSingleValueMap() {
9393
Map<String, String> singleValueMap = CollectionUtils.newLinkedHashMap(this.headers.size());
94-
this.headers.forEach(entry -> {
95-
if (!singleValueMap.containsKey(entry.getKey())) {
96-
singleValueMap.put(entry.getKey().toString(), entry.getValue().toString());
97-
}
98-
});
94+
this.headers.forEach(entry ->
95+
singleValueMap.putIfAbsent(entry.getKey().toString(), entry.getValue().toString())
96+
);
9997
return singleValueMap;
10098
}
10199

spring-web/src/main/java/org/springframework/http/server/reactive/Netty5HeadersAdapter.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -89,11 +89,9 @@ public void setAll(Map<String, String> values) {
8989
@Override
9090
public Map<String, String> toSingleValueMap() {
9191
Map<String, String> singleValueMap = CollectionUtils.newLinkedHashMap(this.headers.size());
92-
this.headers.forEach(entry -> {
93-
if (!singleValueMap.containsKey(entry.getKey())) {
94-
singleValueMap.put(entry.getKey().toString(), entry.getValue().toString());
95-
}
96-
});
92+
this.headers.forEach(entry ->
93+
singleValueMap.putIfAbsent(entry.getKey().toString(), entry.getValue().toString())
94+
);
9795
return singleValueMap;
9896
}
9997

0 commit comments

Comments
 (0)