Skip to content

HalFormsAdaptingResponseBodyAdvice throws NullPointerException if body is null #2123

@vierbergenlars

Description

@vierbergenlars

This piece of code to get the affordances may result in a NullPointerException in case body is null.

boolean hasAffordances = body.getLinks().stream()
.anyMatch(it -> !it.getAffordances().isEmpty());

In the ResponseBodyAdvice interface from spring-webmvc, the body parameter is annotated as @Nullable, an annotation that was not taken into account in HalFormsAdaptingResponseBodyAdvice.

While developing a spring-data-rest application, I encountered a case where the body might be null, in the case that a 304 Not Modified response is being sent.
A Not Modified status can be sent by spring-data-rest when there is an entity with a @LastModifiedDate-annotated property, and an If-Modified-Since request header is sent by the client.
In case the date from If-Modified-Since is after the date from the @LastModifiedDate property, the 304 Not Modified response is sent with a null body, resulting in a NullPointerException from HalFormsAdaptingResponseBodyAdvice, which always results in an Internal Server Error.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions