Browse Source

Return previous value in UndertowHeadersAdapter's remove() method

Prior to this commit, UndertowHeadersAdapter's remove() method violated
the java.util.Map contract by always returning null.

This commit fixes this by returning the previous list stored under the
specified key, and otherwise returning null if no previous value was
present.

Closes gh-27592
pull/28694/head
Sam Brannen 5 years ago
parent
commit
dfc435d045
  1. 7
      spring-web/src/main/java/org/springframework/http/server/reactive/UndertowHeadersAdapter.java

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

@ -17,6 +17,7 @@ @@ -17,6 +17,7 @@
package org.springframework.http.server.reactive;
import java.util.AbstractSet;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedHashMap;
@ -36,6 +37,7 @@ import org.springframework.util.MultiValueMap; @@ -36,6 +37,7 @@ import org.springframework.util.MultiValueMap;
* {@code MultiValueMap} implementation for wrapping Undertow HTTP headers.
*
* @author Brian Clozel
* @author Sam Brannen
* @since 5.1.1
*/
class UndertowHeadersAdapter implements MultiValueMap<String, String> {
@ -131,7 +133,10 @@ class UndertowHeadersAdapter implements MultiValueMap<String, String> { @@ -131,7 +133,10 @@ class UndertowHeadersAdapter implements MultiValueMap<String, String> {
@Nullable
public List<String> remove(Object key) {
if (key instanceof String) {
this.headers.remove((String) key);
Collection<String> removed = this.headers.remove((String) key);
if (removed != null) {
return new ArrayList<>(removed);
}
}
return null;
}

Loading…
Cancel
Save