This is an corner case, discovered while performing some property-based testing for my API.
Affects spring-web:6.0.12
Here is a minimal code sample that reproduces the issue
https://gist.github.com/ltsallas/9903343b6b7a90013cdd155bfcd670ce
I think the the last two tests in the DemoControllerTest should return a 400(MethodArgumentTypeMismatchException) and not a 500(MissingPathVariableException) response.
Comment From: rstoyanchev
This case where a value is present, but becomes null after conversion (StringToUUIDConverter
calls UUID.fromString
) was addressed in #26679. We now detect it and raise MissingPathVariableException
, which is what we do generally with missing path variables since that could be an incorrectly defined URI template.
That said in this case a value is present, but not valid and indeed should be treated as a 400. As part of #26679 we did add a missingAfterConversion
flag to MissingRequestValueException
and could use that to differentiate this case from the more general case of a missing path variable.
Comment From: ltsallas
Thanks for taking a look into this one @rstoyanchev
Are you suggesting this change in the getStatusCode()
of the MissingPathVariableException
?
java
@Override
public HttpStatusCode getStatusCode() {
return isMissingAfterConversion() ? super.getStatusCode() : HttpStatus.INTERNAL_SERVER_ERROR;
}