Skip to content

Commit

Permalink
Return previous value in UndertowHeadersAdapter's remove() method
Browse files Browse the repository at this point in the history
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 spring-projectsgh-27592
  • Loading branch information
sbrannen committed Oct 22, 2021
1 parent 78a24c0 commit dfc435d
Showing 1 changed file with 6 additions and 1 deletion.
Expand Up @@ -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;
Expand All @@ -36,6 +37,7 @@
* {@code MultiValueMap} implementation for wrapping Undertow HTTP headers.
*
* @author Brian Clozel
* @author Sam Brannen
* @since 5.1.1
*/
class UndertowHeadersAdapter implements MultiValueMap<String, String> {
Expand Down Expand Up @@ -131,7 +133,10 @@ public List<String> put(String key, List<String> value) {
@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;
}
Expand Down

0 comments on commit dfc435d

Please sign in to comment.