Skip to content

Commit

Permalink
Merge pull request #30433 from srivatsa-cfp:main
Browse files Browse the repository at this point in the history
* gh-30433:
  Polishing external contribution
  Add non-null assertions in DefaultEntityResponseBuilder
  • Loading branch information
poutsma committed Jun 14, 2023
2 parents 326e27e + 8a29bfb commit 02e9209
Showing 1 changed file with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down 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

0 comments on commit 02e9209

Please sign in to comment.