-
Notifications
You must be signed in to change notification settings - Fork 38.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Exceptions for missing request values should expose information when they are missing after conversion #26679
Comments
And a general remark: For me the changes made in Spring 5.3 feel like a strange (not to say wrong) mix of concepts.
To express "guaranteed to not result in null" I would see or create something like In my discussion with @rstoyanchev in #26088 there are some inaccuracies on my side but interested readers can find more arguments over there (from an old school programmer who is using Spring for around 15 years now and who is picking up innovations (not only in the java programming language) only slowly ;-)). |
@drahkrub indeed at the point of raising the Beyond that there are more options. For example in your own We've debated how |
@rstoyanchev Related to the three paragraphs you wrote:
What about the different response status? Are they intentional? |
I've added a |
Just wanted to make a note that this change appeared during an upgrade from Spring Boot 2.4.4 to 2.4.5 and it broke some of our tests where we are checking the exceptions Should a point release dramatically change an exceptions message is what I'm asking here? I could understand this appearing in an upgrade of 5.3.x to 5.4.0 but a point release.... I'm not so sure... |
Will this be backported to Spring 5? |
In Spring 5.3 it is possible that a
MissingServletRequestParameterException
is thrown although a required parameter is provided (and therefore not missing). The same holds for a required path variable - even it is provided aMissingPathVariableException
may be thrown.Moreover the
MissingServletRequestParameterException
triggers a response status 400 in contrast to theMissingPathVariableException
which ends up in a response status 500.The former happens due to the changes made in #23939: If a provided parameter (request parameter or path variable) is converted to
null
it is handled as a missing value, see AbstractNamedValueMethodArgumentResolver.I would like to propose:
IllegalArgumentException
) if a required parameter (request parameter or path variable) is provided but converted tonull
.In a lengthy discussion with @rstoyanchev in #26088 (I thank his patience) I gave an example to explain that the current status is problematic:
I attached a small spring boot app with several test cases (github, spring_sandbox-master.zip).
With
calling
/rp/book?id=42
leads to aMissingServletRequestParameterException
which is also thrown if/edit
is called without a parameter or with an empty parameter - these cases can not be distinguished in an elegant way, see the testsnoRequestParamThrowsMissingServletRequestParameterException
emptyRequestParamThrowsMissingServletRequestParameterException
idOfDeletedBookThrowsMissingServletRequestParameterException
In contrast calling
with
/pv/book/42
"only" leads to a misleadingMissingPathVariableException
, but the method can not be called with no or an empty parameter (if/pv/book
is not mapped to a different method it is handled by theResourceHttpRequestHandler
, see the testmissingValueNotHandledByController
).But a conflicting case can be constructed this way:
Here calling
/cc/book
and/cc/book/42
both lead to aMissingPathVariableException
- but as I said this is constructed resp. bad programming.The text was updated successfully, but these errors were encountered: