From 818c2aa3b92297578b485fda011c434310ef2943 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Mon, 12 Nov 2018 16:22:42 +0100 Subject: [PATCH] ServerRequest.attribute(name) defensively accesses concurrent map Issue: SPR-17486 --- .../web/reactive/function/server/ServerRequest.java | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/ServerRequest.java b/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/ServerRequest.java index 92c0b128aa..5d9c313bee 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/ServerRequest.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/ServerRequest.java @@ -187,13 +187,7 @@ public interface ServerRequest { * @return the attribute value */ default Optional attribute(String name) { - Map 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 contentType(); /** - * Get the value of the required {@code Host} header. + * Get the value of the {@code Host} header, if available. *

If the header value does not contain a port, the * {@linkplain InetSocketAddress#getPort() port} in the returned address will * be {@code 0}.