Description
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:
import lombok.Builder;
import lombok.NonNull;
import lombok.Value;
import java.util.Map;
@Value
@Builder
public class InformationReceivedRequest {
@NonNull
private String informationType;
private Map<String, Object> data;
}
when making a JSON request with null
as informationType
, Jackson fails to create the corresponding object due to the non-null restriction, creating a ValueInstantiationException
. This exception extends JsonMappingException
, which extends JsonProcessingException
.
In spring-web 5.2.3, class AbstractJackson2HttpMessageConverter
would convert any JsonProcessingException
to HttpMessageNotReadableException
. This second exception is then treated at DefaultHandlerExceptionResolver
(part of spring-webmvc), and transformed into a 400 BAD REQUEST
response.
However, in spring-web 5.2.4, the class AbstractJackson2HttpMessageConverter
has been modified so as to convert JsonMappingException
into HttpMessageConversionException
. This exception is not covered by DefaultHandlerExceptionResolver
, which means the exception bubbles up to produce a 500 INTERNAL ERROR
response.
This means that the same ValueInstantiationException
that used to result in a 400 BAD REQUEST
response (as expected), now results in a 500 INTERNAL ERROR
response.