Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package org.springframework.util;

import org.jspecify.annotations.Nullable;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.LinkedHashMap;
Expand All @@ -31,11 +33,12 @@
*
* @author Arjen Poutsma
* @author Juergen Hoeller
* @author Yanming Zhou
* @since 3.0
* @param <K> the key type
* @param <V> the value element type
*/
public class LinkedMultiValueMap<K, V> extends MultiValueMapAdapter<K, V> implements Serializable, Cloneable {
public class LinkedMultiValueMap<K, V extends @Nullable Object> extends MultiValueMapAdapter<K, V> implements Serializable, Cloneable {

private static final long serialVersionUID = 3801124242820219131L;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,15 @@
*
* @author Arjen Poutsma
* @author Juergen Hoeller
* @author Yanming Zhou
* @since 5.3
* @param <K> the key type
* @param <V> the value element type
* @see CollectionUtils#toMultiValueMap
* @see LinkedMultiValueMap
*/
@SuppressWarnings("serial")
public class MultiValueMapAdapter<K, V> implements MultiValueMap<K, V>, Serializable {
public class MultiValueMapAdapter<K, V extends @Nullable Object> implements MultiValueMap<K, V>, Serializable {

private final Map<K, List<V>> targetMap;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,12 @@
* Unmodifiable wrapper for {@link MultiValueMap}.
*
* @author Arjen Poutsma
* @author Yanming Zhou
* @since 6.0
* @param <K> the key type
* @param <V> the value element type
*/
final class UnmodifiableMultiValueMap<K,V> implements MultiValueMap<K,V>, Serializable {
final class UnmodifiableMultiValueMap<K, V extends @Nullable Object> implements MultiValueMap<K, V>, Serializable {

private static final long serialVersionUID = -8697084563854098920L;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@
import java.util.List;
import java.util.Map;

import org.jspecify.annotations.Nullable;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;

/**
* @author Arjen Poutsma
* @author Juergen Hoeller
* @author Yanming Zhou
*/
class LinkedMultiValueMapTests {

Expand Down Expand Up @@ -130,4 +132,11 @@ void equals() {
assertThat(map).isEqualTo(o2);
}

@Test
void nullable() {
LinkedMultiValueMap<String, @Nullable String> map = new LinkedMultiValueMap<>();
map.add("test", "test");
map.add("test", null);
assertThat(map.get("test")).containsExactly("test", null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.Set;

import org.assertj.core.api.ThrowableTypeAssert;
import org.jspecify.annotations.Nullable;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;
Expand All @@ -36,6 +37,7 @@
* Tests for {@link UnmodifiableMultiValueMap}.
*
* @author Arjen Poutsma
* @author Yanming Zhou
* @since 6.0
*/
class UnmodifiableMultiValueMapTests {
Expand Down Expand Up @@ -179,6 +181,15 @@ void valuesUnsupported() {
assertThatUnsupportedOperationException().isThrownBy(values::clear);
}

@Test
void nullable() {
MultiValueMap<String, @Nullable String> linkedMultiValueMap = new LinkedMultiValueMap<>();
linkedMultiValueMap.add("test", "test");
linkedMultiValueMap.add("test", null);
UnmodifiableMultiValueMap<String, String> map = new UnmodifiableMultiValueMap<>(linkedMultiValueMap);
assertThat(map.get("test")).containsExactly("test", null);
}

private static ThrowableTypeAssert<UnsupportedOperationException> assertThatUnsupportedOperationException() {
return assertThatExceptionOfType(UnsupportedOperationException.class);
}
Expand Down
Loading