Skip to content

Commit f54e1ef

Browse files
committed
Initialize propertyName
MethodArgumentTypeMismatchException and MethodArgumentConversionNotSupportedException are TypeMismatchException subclasses with MethodParameter information and should initialize propertyName in TypeMismatchInformation. Closes gh-29959
1 parent a3efcab commit f54e1ef

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2023 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.
@@ -42,6 +42,7 @@ public MethodArgumentConversionNotSupportedException(@Nullable Object value,
4242
super(value, requiredType, cause);
4343
this.name = name;
4444
this.parameter = param;
45+
initPropertyName(name);
4546
}
4647

4748

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2023 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.
@@ -42,6 +42,7 @@ public MethodArgumentTypeMismatchException(@Nullable Object value,
4242
super(value, requiredType, cause);
4343
this.name = name;
4444
this.parameter = param;
45+
initPropertyName(name);
4546
}
4647

4748

spring-web/src/test/java/org/springframework/web/method/annotation/RequestHeaderMethodArgumentResolverTests.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-2023 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.
@@ -45,6 +45,7 @@
4545

4646
import static org.assertj.core.api.Assertions.assertThat;
4747
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
48+
import static org.assertj.core.api.Assertions.assertThatThrownBy;
4849

4950
/**
5051
* Unit tests for {@link RequestHeaderMethodArgumentResolver}.
@@ -242,15 +243,16 @@ void uuidConversionWithValidValue() throws Exception {
242243
}
243244

244245
@Test
245-
void uuidConversionWithInvalidValue() throws Exception {
246+
void uuidConversionWithInvalidValue() {
246247
servletRequest.addHeader("name", "bogus-uuid");
247248

248249
ConfigurableWebBindingInitializer bindingInitializer = new ConfigurableWebBindingInitializer();
249250
bindingInitializer.setConversionService(new DefaultFormattingConversionService());
250251

251-
assertThatExceptionOfType(MethodArgumentTypeMismatchException.class).isThrownBy(
252-
() -> resolver.resolveArgument(paramUuid, null, webRequest,
253-
new DefaultDataBinderFactory(bindingInitializer)));
252+
assertThatThrownBy(() ->
253+
resolver.resolveArgument(paramUuid, null, webRequest, new DefaultDataBinderFactory(bindingInitializer)))
254+
.isInstanceOf(MethodArgumentTypeMismatchException.class)
255+
.extracting("propertyName").isEqualTo("name");
254256
}
255257

256258
@Test

0 commit comments

Comments
 (0)