Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -290,9 +290,10 @@ else if (paramType.isPrimitive()) {
throw new MethodArgumentConversionNotSupportedException(arg, ex.getRequiredType(),
namedValueInfo.name, parameter, ex.getCause());
}
catch (TypeMismatchException ex) {
throw new MethodArgumentTypeMismatchException(arg, ex.getRequiredType(),
namedValueInfo.name, parameter, ex.getCause());
catch (TypeMismatchException | IllegalArgumentException ex) {
throw new MethodArgumentTypeMismatchException(arg, ex instanceof TypeMismatchException tme ?
tme.getRequiredType() : parameterType,
namedValueInfo.name, parameter, ex);
}
return arg;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,14 @@
import org.springframework.http.server.ServerHttpResponse;
import org.springframework.http.server.ServletServerHttpResponse;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.context.request.async.AsyncRequestNotUsableException;
import org.springframework.web.context.request.async.StandardServletAsyncWebRequest;
import org.springframework.web.context.request.async.WebAsyncManager;
import org.springframework.web.context.request.async.WebAsyncUtils;
import org.springframework.web.context.support.StaticWebApplicationContext;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException;
import org.springframework.web.method.annotation.ModelMethodProcessor;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.method.support.HandlerMethodReturnValueHandler;
Expand Down Expand Up @@ -131,6 +127,32 @@ void cacheControlWithoutSessionAttributes() throws Exception {
assertThat(response.getHeader("Cache-Control")).contains("max-age");
}

@Test
void invalidBooleanRequestParamResultsInBadRequest() throws Exception {
this.handlerAdapter.afterPropertiesSet();

this.request.setRequestURI("/test");
this.request.setParameter("bool", "dummy");

HandlerMethod handlerMethod =
handlerMethod(new BooleanParamController(), "test", boolean.class);

assertThatThrownBy(() -> {
try {
this.handlerAdapter.handle(this.request, this.response, handlerMethod);
}
catch (Exception ex) {
throw new RuntimeException(ex);
}
})
.hasCauseInstanceOf(MethodArgumentTypeMismatchException.class);

}





@Test
void cacheControlWithSessionAttributes() throws Exception {
SessionAttributeController handler = new SessionAttributeController();
Expand Down Expand Up @@ -410,6 +432,15 @@ public ResponseEntity<?> handle(@RequestParam String q) throws IOException {

}

@RestController
static class BooleanParamController {

@GetMapping("/test")
void test(@RequestParam boolean bool) {
}
}



@ControllerAdvice
private static class ModelAttributeAdvice {
Expand Down