Skip to content

Commit ea30c8f

Browse files
Bernie Schelbergsnicoll
authored andcommitted
Return consistent collection type for matrix variables
See gh-31483
1 parent 6bdf7ad commit ea30c8f

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/MatrixVariableMapMethodArgumentResolver.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public Object resolveArgument(MethodParameter parameter, @Nullable ModelAndViewC
6969
HandlerMapping.MATRIX_VARIABLES_ATTRIBUTE, RequestAttributes.SCOPE_REQUEST);
7070

7171
if (CollectionUtils.isEmpty(matrixVariables)) {
72-
return Collections.emptyMap();
72+
return (isSingleValueMap(parameter) ? Collections.emptyMap() : new LinkedMultiValueMap<>(0));
7373
}
7474

7575
MultiValueMap<String, String> map = new LinkedMultiValueMap<>();

spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/MatrixVariablesMapMethodArgumentResolverTests.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,18 @@ public void resolveArgumentNoParams() throws Exception {
155155
assertThat(map).isEqualTo(Collections.emptyMap());
156156
}
157157

158+
@Test
159+
public void resolveMultiValueMapArgumentNoParams() throws Exception {
160+
161+
MethodParameter param = this.testMethod.annot(matrixAttribute().noPathVar())
162+
.arg(MultiValueMap.class, String.class, String.class);
163+
164+
Object result = this.resolver.resolveArgument(param, this.mavContainer, this.webRequest, null);
165+
166+
//noinspection unchecked
167+
assertThat(result).isInstanceOfSatisfying(MultiValueMap.class, map -> assertThat(map).isEmpty());
168+
}
169+
158170
@Test
159171
public void resolveArgumentNoMatch() throws Exception {
160172
MultiValueMap<String, String> params2 = getVariablesFor("planes");

0 commit comments

Comments
 (0)