Skip to content

Invalid request results in 500 INTERNAL ERROR instead of 400 BAD REQUEST (with Lombok and Kotlin) #24610

Closed
@quiram

Description

@quiram

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.

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: regressionA bug that is also a regression

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions