Skip to content

Commit

Permalink
Add non-null assertions in DefaultEntityResponseBuilder
Browse files Browse the repository at this point in the history
This commit adds various non-null assertions to
DefaultEntityResponseBuilder, in Spring MVC.

Closes gh-30433
  • Loading branch information
srivatsa-cfp authored and poutsma committed Jun 14, 2023
1 parent 326e27e commit 0c817f0
Showing 1 changed file with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,14 @@ public EntityResponse.Builder<T> cookie(Cookie cookie) {
@Override
public EntityResponse.Builder<T> cookies(
Consumer<MultiValueMap<String, Cookie>> cookiesConsumer) {
Assert.notNull(cookiesConsumer, "cookiesConsumer must not be null");
cookiesConsumer.accept(this.cookies);
return this;
}

@Override
public EntityResponse.Builder<T> header(String headerName, String... headerValues) {
Assert.notNull(headerName, "headerName must not be null");
for (String headerValue : headerValues) {
this.headers.add(headerName, headerValue);
}
Expand All @@ -128,18 +130,21 @@ public EntityResponse.Builder<T> header(String headerName, String... headerValue

@Override
public EntityResponse.Builder<T> headers(Consumer<HttpHeaders> headersConsumer) {
Assert.notNull(headersConsumer, "headersConsumer must not be null");
headersConsumer.accept(this.headers);
return this;
}

@Override
public EntityResponse.Builder<T> allow(HttpMethod... allowedMethods) {
Assert.notNull(allowedMethods, "allowedMethods must not be null");
this.headers.setAllow(new LinkedHashSet<>(Arrays.asList(allowedMethods)));
return this;
}

@Override
public EntityResponse.Builder<T> allow(Set<HttpMethod> allowedMethods) {
Assert.notNull(allowedMethods, "allowedMethods must not be null");
this.headers.setAllow(allowedMethods);
return this;
}
Expand All @@ -152,6 +157,7 @@ public EntityResponse.Builder<T> contentLength(long contentLength) {

@Override
public EntityResponse.Builder<T> contentType(MediaType contentType) {
Assert.notNull(contentType, "contentType must not be null");
this.headers.setContentType(contentType);
return this;
}
Expand All @@ -170,24 +176,28 @@ public EntityResponse.Builder<T> eTag(String etag) {

@Override
public EntityResponse.Builder<T> lastModified(ZonedDateTime lastModified) {
Assert.notNull(lastModified, "lastModified must not be null");
this.headers.setLastModified(lastModified);
return this;
}

@Override
public EntityResponse.Builder<T> lastModified(Instant lastModified) {
Assert.notNull(lastModified, "lastModified must not be null");
this.headers.setLastModified(lastModified);
return this;
}

@Override
public EntityResponse.Builder<T> location(URI location) {
Assert.notNull(location, "location must not be null");
this.headers.setLocation(location);
return this;
}

@Override
public EntityResponse.Builder<T> cacheControl(CacheControl cacheControl) {
Assert.notNull(cacheControl, "cacheControl must not be null");
this.headers.setCacheControl(cacheControl);
return this;
}
Expand Down Expand Up @@ -498,14 +508,14 @@ public NoContentLengthResponseWrapper(HttpServletResponse response) {

@Override
public void addIntHeader(String name, int value) {
if (!HttpHeaders.CONTENT_LENGTH.equals(name)) {
if (name!=null && !HttpHeaders.CONTENT_LENGTH.equals(name)) {
super.addIntHeader(name, value);
}
}

@Override
public void addHeader(String name, String value) {
if (!HttpHeaders.CONTENT_LENGTH.equals(name)) {
if (name!= null && !HttpHeaders.CONTENT_LENGTH.equals(name)) {
super.addHeader(name, value);
}
}
Expand Down

0 comments on commit 0c817f0

Please sign in to comment.