Skip to content

Commit fd88238

Browse files
committed
MapMethodProcessor supportsParameter is more specific
Closes gh-33160
1 parent 3256bf4 commit fd88238

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

Diff for: spring-web/src/main/java/org/springframework/web/method/annotation/MapMethodProcessor.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -20,6 +20,7 @@
2020

2121
import org.springframework.core.MethodParameter;
2222
import org.springframework.lang.Nullable;
23+
import org.springframework.ui.ModelMap;
2324
import org.springframework.util.Assert;
2425
import org.springframework.web.bind.support.WebDataBinderFactory;
2526
import org.springframework.web.context.request.NativeWebRequest;
@@ -42,7 +43,9 @@ public class MapMethodProcessor implements HandlerMethodArgumentResolver, Handle
4243

4344
@Override
4445
public boolean supportsParameter(MethodParameter parameter) {
45-
return (Map.class.isAssignableFrom(parameter.getParameterType()) &&
46+
// We don't support any type of Map
47+
Class<?> type = parameter.getParameterType();
48+
return ((type.isAssignableFrom(Map.class) || ModelMap.class.isAssignableFrom(type)) &&
4649
parameter.getParameterAnnotations().length == 0);
4750
}
4851

Diff for: spring-web/src/test/java/org/springframework/web/method/annotation/MapMethodProcessorTests.java

+17
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.web.method.annotation;
1818

19+
import java.util.HashMap;
1920
import java.util.Map;
2021

2122
import org.junit.jupiter.api.BeforeEach;
@@ -63,8 +64,13 @@ void setUp() {
6364
void supportsParameter() {
6465
assertThat(this.processor.supportsParameter(
6566
this.resolvable.annotNotPresent().arg(Map.class, String.class, Object.class))).isTrue();
67+
6668
assertThat(this.processor.supportsParameter(
6769
this.resolvable.annotPresent(RequestBody.class).arg(Map.class, String.class, Object.class))).isFalse();
70+
71+
// gh-33160
72+
assertThat(this.processor.supportsParameter(
73+
ResolvableMethod.on(getClass()).argTypes(ExtendedMap.class).build().arg(ExtendedMap.class))).isFalse();
6874
}
6975

7076
@Test
@@ -100,4 +106,15 @@ private Map<String, Object> handle(
100106
return null;
101107
}
102108

109+
110+
@SuppressWarnings("unused")
111+
private Map<String, Object> handle(ExtendedMap extendedMap) {
112+
return null;
113+
}
114+
115+
116+
@SuppressWarnings("serial")
117+
private static final class ExtendedMap extends HashMap<String, Object> {
118+
}
119+
103120
}

0 commit comments

Comments
 (0)