ServerRequest.attribute(name) defensively accesses concurrent map

Issue: SPR-17486
This commit is contained in:
Juergen Hoeller
2018-11-12 16:22:42 +01:00
parent d96a7b4bfc
commit 818c2aa3b9

View File

@@ -187,13 +187,7 @@ public interface ServerRequest {
* @return the attribute value
*/
default Optional<Object> attribute(String name) {
Map<String, Object> attributes = attributes();
if (attributes.containsKey(name)) {
return Optional.of(attributes.get(name));
}
else {
return Optional.empty();
}
return Optional.ofNullable(attributes().get(name));
}
/**
@@ -350,7 +344,7 @@ public interface ServerRequest {
Optional<MediaType> contentType();
/**
* Get the value of the required {@code Host} header.
* Get the value of the {@code Host} header, if available.
* <p>If the header value does not contain a port, the
* {@linkplain InetSocketAddress#getPort() port} in the returned address will
* be {@code 0}.