Browse Source

Initialize propertyName

MethodArgumentTypeMismatchException and
MethodArgumentConversionNotSupportedException are TypeMismatchException
subclasses with MethodParameter information and should initialize
propertyName in TypeMismatchInformation.

Closes gh-29959
pull/29975/head
rstoyanchev 3 years ago
parent
commit
f54e1ef880
  1. 3
      spring-web/src/main/java/org/springframework/web/method/annotation/MethodArgumentConversionNotSupportedException.java
  2. 3
      spring-web/src/main/java/org/springframework/web/method/annotation/MethodArgumentTypeMismatchException.java
  3. 12
      spring-web/src/test/java/org/springframework/web/method/annotation/RequestHeaderMethodArgumentResolverTests.java

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

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2023 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.
@ -42,6 +42,7 @@ public class MethodArgumentConversionNotSupportedException extends ConversionNot @@ -42,6 +42,7 @@ public class MethodArgumentConversionNotSupportedException extends ConversionNot
super(value, requiredType, cause);
this.name = name;
this.parameter = param;
initPropertyName(name);
}

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

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2023 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.
@ -42,6 +42,7 @@ public class MethodArgumentTypeMismatchException extends TypeMismatchException { @@ -42,6 +42,7 @@ public class MethodArgumentTypeMismatchException extends TypeMismatchException {
super(value, requiredType, cause);
this.name = name;
this.parameter = param;
initPropertyName(name);
}

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

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 the original author or authors.
* Copyright 2002-2023 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.
@ -45,6 +45,7 @@ import org.springframework.web.testfixture.servlet.MockHttpServletResponse; @@ -45,6 +45,7 @@ import org.springframework.web.testfixture.servlet.MockHttpServletResponse;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
/**
* Unit tests for {@link RequestHeaderMethodArgumentResolver}.
@ -242,15 +243,16 @@ class RequestHeaderMethodArgumentResolverTests { @@ -242,15 +243,16 @@ class RequestHeaderMethodArgumentResolverTests {
}
@Test
void uuidConversionWithInvalidValue() throws Exception {
void uuidConversionWithInvalidValue() {
servletRequest.addHeader("name", "bogus-uuid");
ConfigurableWebBindingInitializer bindingInitializer = new ConfigurableWebBindingInitializer();
bindingInitializer.setConversionService(new DefaultFormattingConversionService());
assertThatExceptionOfType(MethodArgumentTypeMismatchException.class).isThrownBy(
() -> resolver.resolveArgument(paramUuid, null, webRequest,
new DefaultDataBinderFactory(bindingInitializer)));
assertThatThrownBy(() ->
resolver.resolveArgument(paramUuid, null, webRequest, new DefaultDataBinderFactory(bindingInitializer)))
.isInstanceOf(MethodArgumentTypeMismatchException.class)
.extracting("propertyName").isEqualTo("name");
}
@Test

Loading…
Cancel
Save