Skip to content

Commit 86d5c5c

Browse files
committed
Avoid putIfAbsent call in HttpEntityMethodProcessor
Issue: SPR-14086
1 parent 7e4563a commit 86d5c5c

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/HttpEntityMethodProcessor.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@
4646
import org.springframework.web.context.request.NativeWebRequest;
4747
import org.springframework.web.method.support.ModelAndViewContainer;
4848

49-
import static org.springframework.http.HttpHeaders.VARY;
50-
5149
/**
5250
* Resolves {@link HttpEntity} and {@link RequestEntity} method argument values
5351
* and also handles {@link HttpEntity} and {@link ResponseEntity} return values.
@@ -172,15 +170,17 @@ public void handleReturnValue(Object returnValue, MethodParameter returnType,
172170

173171
HttpHeaders outputHeaders = outputMessage.getHeaders();
174172
HttpHeaders entityHeaders = responseEntity.getHeaders();
175-
if (outputHeaders.containsKey(VARY) && entityHeaders.containsKey(VARY)) {
173+
if (outputHeaders.containsKey(HttpHeaders.VARY) && entityHeaders.containsKey(HttpHeaders.VARY)) {
176174
List<String> values = getVaryRequestHeadersToAdd(outputHeaders, entityHeaders);
177175
if (!values.isEmpty()) {
178176
outputHeaders.setVary(values);
179177
}
180178
}
181179
if (!entityHeaders.isEmpty()) {
182180
for (Map.Entry<String, List<String>> entry : entityHeaders.entrySet()) {
183-
outputHeaders.putIfAbsent(entry.getKey(), entry.getValue());
181+
if (!outputHeaders.containsKey(entry.getKey())) {
182+
outputHeaders.put(entry.getKey(), entry.getValue());
183+
}
184184
}
185185
}
186186

@@ -197,14 +197,15 @@ public void handleReturnValue(Object returnValue, MethodParameter returnType,
197197
return;
198198
}
199199
}
200-
if(inputMessage.getHeaders().containsKey(HttpHeaders.RANGE) &&
200+
if (inputMessage.getHeaders().containsKey(HttpHeaders.RANGE) &&
201201
Resource.class.isAssignableFrom(body.getClass())) {
202202
try {
203203
List<HttpRange> httpRanges = inputMessage.getHeaders().getRange();
204204
Resource bodyResource = (Resource) body;
205205
body = new HttpRangeResource(httpRanges, bodyResource);
206206
outputMessage.setStatusCode(HttpStatus.PARTIAL_CONTENT);
207-
} catch (IllegalArgumentException exc) {
207+
}
208+
catch (IllegalArgumentException ex) {
208209
outputMessage.setStatusCode(HttpStatus.REQUESTED_RANGE_NOT_SATISFIABLE);
209210
outputMessage.flush();
210211
return;

0 commit comments

Comments
 (0)