Skip to content

Commit 6c5e63e

Browse files
committed
Merge branch '6.1.x'
2 parents 32309e8 + b54420f commit 6c5e63e

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

spring-web/src/main/java/org/springframework/web/method/annotation/MethodArgumentTypeMismatchException.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ public MethodArgumentTypeMismatchException(@Nullable Object value,
4545
initPropertyName(name);
4646
}
4747

48-
4948
/**
5049
* Return the name of the method argument.
5150
*/
@@ -60,4 +59,9 @@ public MethodParameter getParameter() {
6059
return this.parameter;
6160
}
6261

62+
@Override
63+
public String getMessage() {
64+
return "Method parameter '" + getName() + "': " + super.getMessage();
65+
}
66+
6367
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright 2002-2024 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.web.method.annotation;
18+
19+
import org.junit.jupiter.api.Test;
20+
21+
import static org.assertj.core.api.Assertions.assertThat;
22+
23+
class MethodArgumentTypeMismatchExceptionTests {
24+
25+
@Test //gh-33573
26+
void messageIncludesParameterName() {
27+
@SuppressWarnings("DataFlowIssue")
28+
MethodArgumentTypeMismatchException ex = new MethodArgumentTypeMismatchException(
29+
"mismatched value", Integer.class, "paramOne", null, null);
30+
31+
assertThat(ex).hasMessage("Method parameter 'paramOne': Failed to convert value of type " +
32+
"'java.lang.String' to required type 'java.lang.Integer'");
33+
}
34+
35+
}

0 commit comments

Comments
 (0)