From 66f33a82651b6cfaec8e85a5f5af9a8bc285d5ca Mon Sep 17 00:00:00 2001 From: rstoyanchev Date: Mon, 9 Dec 2024 15:21:55 +0000 Subject: [PATCH] MapMethodProcessor supportsParameter is more specific Closes gh-33160 --- .../method/annotation/MapMethodProcessor.java | 7 +++++-- .../annotation/MapMethodProcessorTests.java | 17 +++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/spring-web/src/main/java/org/springframework/web/method/annotation/MapMethodProcessor.java b/spring-web/src/main/java/org/springframework/web/method/annotation/MapMethodProcessor.java index ba47fe3d4258..8f8cb85489c2 100644 --- a/spring-web/src/main/java/org/springframework/web/method/annotation/MapMethodProcessor.java +++ b/spring-web/src/main/java/org/springframework/web/method/annotation/MapMethodProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,6 +20,7 @@ import org.springframework.core.MethodParameter; import org.springframework.lang.Nullable; +import org.springframework.ui.ModelMap; import org.springframework.util.Assert; import org.springframework.web.bind.support.WebDataBinderFactory; import org.springframework.web.context.request.NativeWebRequest; @@ -42,7 +43,9 @@ public class MapMethodProcessor implements HandlerMethodArgumentResolver, Handle @Override public boolean supportsParameter(MethodParameter parameter) { - return (Map.class.isAssignableFrom(parameter.getParameterType()) && + // We don't support any type of Map + Class type = parameter.getParameterType(); + return ((type.isAssignableFrom(Map.class) || ModelMap.class.isAssignableFrom(type)) && parameter.getParameterAnnotations().length == 0); } diff --git a/spring-web/src/test/java/org/springframework/web/method/annotation/MapMethodProcessorTests.java b/spring-web/src/test/java/org/springframework/web/method/annotation/MapMethodProcessorTests.java index 483f88d80f3f..2f7c40dec9e2 100644 --- a/spring-web/src/test/java/org/springframework/web/method/annotation/MapMethodProcessorTests.java +++ b/spring-web/src/test/java/org/springframework/web/method/annotation/MapMethodProcessorTests.java @@ -16,6 +16,7 @@ package org.springframework.web.method.annotation; +import java.util.HashMap; import java.util.Map; import org.junit.jupiter.api.BeforeEach; @@ -63,8 +64,13 @@ void setUp() { void supportsParameter() { assertThat(this.processor.supportsParameter( this.resolvable.annotNotPresent().arg(Map.class, String.class, Object.class))).isTrue(); + assertThat(this.processor.supportsParameter( this.resolvable.annotPresent(RequestBody.class).arg(Map.class, String.class, Object.class))).isFalse(); + + // gh-33160 + assertThat(this.processor.supportsParameter( + ResolvableMethod.on(getClass()).argTypes(ExtendedMap.class).build().arg(ExtendedMap.class))).isFalse(); } @Test @@ -100,4 +106,15 @@ private Map handle( return null; } + + @SuppressWarnings("unused") + private Map handle(ExtendedMap extendedMap) { + return null; + } + + + @SuppressWarnings("serial") + private static final class ExtendedMap extends HashMap { + } + }