Skip to content

Commit 0c817f0

Browse files
srivatsa-cfppoutsma
authored andcommitted
Add non-null assertions in DefaultEntityResponseBuilder
This commit adds various non-null assertions to DefaultEntityResponseBuilder, in Spring MVC. Closes gh-30433
1 parent 326e27e commit 0c817f0

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

spring-webmvc/src/main/java/org/springframework/web/servlet/function/DefaultEntityResponseBuilder.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,14 @@ public EntityResponse.Builder<T> cookie(Cookie cookie) {
114114
@Override
115115
public EntityResponse.Builder<T> cookies(
116116
Consumer<MultiValueMap<String, Cookie>> cookiesConsumer) {
117+
Assert.notNull(cookiesConsumer, "cookiesConsumer must not be null");
117118
cookiesConsumer.accept(this.cookies);
118119
return this;
119120
}
120121

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

129131
@Override
130132
public EntityResponse.Builder<T> headers(Consumer<HttpHeaders> headersConsumer) {
133+
Assert.notNull(headersConsumer, "headersConsumer must not be null");
131134
headersConsumer.accept(this.headers);
132135
return this;
133136
}
134137

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

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

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

171177
@Override
172178
public EntityResponse.Builder<T> lastModified(ZonedDateTime lastModified) {
179+
Assert.notNull(lastModified, "lastModified must not be null");
173180
this.headers.setLastModified(lastModified);
174181
return this;
175182
}
176183

177184
@Override
178185
public EntityResponse.Builder<T> lastModified(Instant lastModified) {
186+
Assert.notNull(lastModified, "lastModified must not be null");
179187
this.headers.setLastModified(lastModified);
180188
return this;
181189
}
182190

183191
@Override
184192
public EntityResponse.Builder<T> location(URI location) {
193+
Assert.notNull(location, "location must not be null");
185194
this.headers.setLocation(location);
186195
return this;
187196
}
188197

189198
@Override
190199
public EntityResponse.Builder<T> cacheControl(CacheControl cacheControl) {
200+
Assert.notNull(cacheControl, "cacheControl must not be null");
191201
this.headers.setCacheControl(cacheControl);
192202
return this;
193203
}
@@ -498,14 +508,14 @@ public NoContentLengthResponseWrapper(HttpServletResponse response) {
498508

499509
@Override
500510
public void addIntHeader(String name, int value) {
501-
if (!HttpHeaders.CONTENT_LENGTH.equals(name)) {
511+
if (name!=null && !HttpHeaders.CONTENT_LENGTH.equals(name)) {
502512
super.addIntHeader(name, value);
503513
}
504514
}
505515

506516
@Override
507517
public void addHeader(String name, String value) {
508-
if (!HttpHeaders.CONTENT_LENGTH.equals(name)) {
518+
if (name!= null && !HttpHeaders.CONTENT_LENGTH.equals(name)) {
509519
super.addHeader(name, value);
510520
}
511521
}

0 commit comments

Comments
 (0)