-
Notifications
You must be signed in to change notification settings - Fork 38.3k
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
Invalid request results in 500 INTERNAL ERROR instead of 400 BAD REQUEST (with Lombok and Kotlin) #24610
Comments
@quiram see #24455 (comment). The |
We are facing the same issue, although we are using the Jackson Kotlin module instead of Lombok. In case of a missing attribute, this module throws a |
We might have to handle |
Thanks @rstoyanchev, I think I can see the dilemma here. On one side, if we look at the combined behaviour of lombok (or Kotlin in the case of @mario-philipps-icw) + jackson + spring-web + spring-webmvc, what we had up to Spring Boot 2.2.4 (spring-web 5.2.3) seemed to make sense because:
Looking at the issue as just the combined behaviour, what we have now could be seen as a regression. On the other hand, it is true that, taking into account the Javadoc description for Maybe we can raise this at jackson-databind and see if they are happy to change the root exception from Thoughts? |
It appears as a regression but the hierarchy under I think for Jackson it's unclear what the NPE means and it's probably why it treats it as |
This is promising. The Lombok configuration can be applied per directory, so provided one keeps all the bean definitions in the same package, the flag to raise Is the next step raising an issue in jackson-databind? |
@rstoyanchev Shall I open a new issue for it? |
@mario-philipps-icw Let's keep it under this ticket for the time being. Looks like there will be a single revision refining the exception handling algorithm which will cover all cases here. |
This is the FasterXML/jackson-databind#2126 that changed the treatment of instantiation errors from
This has since caused all sorts of issues with value instantiation and null input validation including 2 here (Lombok, Kotlin), and one under spring-projects/spring-boot#20365 (Standard bean validation), which arguably should be treated as In light of this I propose treating this as a regression, and reverting back to the original behavior: catch (InvalidDefinitionException ex) { // another kind of JsonMappingException
throw new HttpMessageConversionException("Type definition error: " + ex.getType(), ex);
}
catch (JsonProcessingException ex) {
throw new HttpMessageNotReadableException("JSON parse error: " + ex.getOriginalMessage(), ex, inputMessage);
} and likewise for writing where |
We are affected as well. is there an overview of when and by whom (Spring or Jackson) this issue will be resolved? |
Affects: Spring Boot 2.2.5
More specifically spring-web 5.2.4
Scenario
Assume a bean definition with Lombok annotations used for annotation, for instance:
when making a JSON request with
null
asinformationType
, Jackson fails to create the corresponding object due to the non-null restriction, creating aValueInstantiationException
. This exception extendsJsonMappingException
, which extendsJsonProcessingException
.In spring-web 5.2.3, class
AbstractJackson2HttpMessageConverter
would convert anyJsonProcessingException
toHttpMessageNotReadableException
. This second exception is then treated atDefaultHandlerExceptionResolver
(part of spring-webmvc), and transformed into a400 BAD REQUEST
response.However, in spring-web 5.2.4, the class
AbstractJackson2HttpMessageConverter
has been modified so as to convertJsonMappingException
intoHttpMessageConversionException
. This exception is not covered byDefaultHandlerExceptionResolver
, which means the exception bubbles up to produce a500 INTERNAL ERROR
response.This means that the same
ValueInstantiationException
that used to result in a400 BAD REQUEST
response (as expected), now results in a500 INTERNAL ERROR
response.The text was updated successfully, but these errors were encountered: