Skip to content

Commit 02e9209

Browse files
committed
Merge pull request #30433 from srivatsa-cfp:main
* gh-30433: Polishing external contribution Add non-null assertions in DefaultEntityResponseBuilder
2 parents 326e27e + 8a29bfb commit 02e9209

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -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
}

0 commit comments

Comments
 (0)