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
This commit is contained in:
Sam Brannen 2021-10-22 14:57:12 +02:00
parent e5475d698a
commit a603779f33
1 changed files with 6 additions and 1 deletions

View File

@ -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.List;
@ -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> {
@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;
}