Skip to content

Commit 428dbc4

Browse files
committed
Add missing nullable annotation to ResponseEntity ok convenience method
Closes gh-26613
1 parent dd3262b commit 428dbc4

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

spring-web/src/main/java/org/springframework/http/ResponseEntity.java

+14-12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-2021 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.
@@ -31,8 +31,8 @@
3131
import org.springframework.util.ObjectUtils;
3232

3333
/**
34-
* Extension of {@link HttpEntity} that adds a {@link HttpStatus} status code.
35-
* Used in {@code RestTemplate} as well {@code @Controller} methods.
34+
* Extension of {@link HttpEntity} that adds an {@link HttpStatus} status code.
35+
* Used in {@code RestTemplate} as well as in {@code @Controller} methods.
3636
*
3737
* <p>In {@code RestTemplate}, this class is returned by
3838
* {@link org.springframework.web.client.RestTemplate#getForEntity getForEntity()} and
@@ -44,7 +44,8 @@
4444
* HttpStatus statusCode = entity.getStatusCode();
4545
* </pre>
4646
*
47-
* <p>Can also be used in Spring MVC, as the return value from a @Controller method:
47+
* <p>This can also be used in Spring MVC as the return value from an
48+
* {@code @Controller} method:
4849
* <pre class="code">
4950
* &#64;RequestMapping("/handle")
5051
* public ResponseEntity&lt;String&gt; handle() {
@@ -81,15 +82,15 @@ public class ResponseEntity<T> extends HttpEntity<T> {
8182

8283

8384
/**
84-
* Create a new {@code ResponseEntity} with the given status code, and no body nor headers.
85+
* Create a {@code ResponseEntity} with a status code only.
8586
* @param status the status code
8687
*/
8788
public ResponseEntity(HttpStatus status) {
8889
this(null, null, status);
8990
}
9091

9192
/**
92-
* Create a new {@code ResponseEntity} with the given body and status code, and no headers.
93+
* Create a {@code ResponseEntity} with a body and status code.
9394
* @param body the entity body
9495
* @param status the status code
9596
*/
@@ -98,7 +99,7 @@ public ResponseEntity(@Nullable T body, HttpStatus status) {
9899
}
99100

100101
/**
101-
* Create a new {@code HttpEntity} with the given headers and status code, and no body.
102+
* Create a {@code ResponseEntity} with headers and a status code.
102103
* @param headers the entity headers
103104
* @param status the status code
104105
*/
@@ -107,7 +108,7 @@ public ResponseEntity(MultiValueMap<String, String> headers, HttpStatus status)
107108
}
108109

109110
/**
110-
* Create a new {@code HttpEntity} with the given body, headers, and status code.
111+
* Create a {@code ResponseEntity} with a body, headers, and a status code.
111112
* @param body the entity body
112113
* @param headers the entity headers
113114
* @param status the status code
@@ -119,7 +120,7 @@ public ResponseEntity(@Nullable T body, @Nullable MultiValueMap<String, String>
119120
}
120121

121122
/**
122-
* Create a new {@code HttpEntity} with the given body, headers, and status code.
123+
* Create a {@code ResponseEntity} with the given body, headers, and status code.
123124
* Just used behind the nested builder API.
124125
* @param body the entity body
125126
* @param headers the entity headers
@@ -231,12 +232,13 @@ public static BodyBuilder ok() {
231232
}
232233

233234
/**
234-
* A shortcut for creating a {@code ResponseEntity} with the given body and
235-
* the status set to {@linkplain HttpStatus#OK OK}.
235+
* A shortcut for creating a {@code ResponseEntity} with the given body
236+
* and the status set to {@linkplain HttpStatus#OK OK}.
237+
* @param body the body of the response entity (possibly empty)
236238
* @return the created {@code ResponseEntity}
237239
* @since 4.1
238240
*/
239-
public static <T> ResponseEntity<T> ok(T body) {
241+
public static <T> ResponseEntity<T> ok(@Nullable T body) {
240242
return ok().body(body);
241243
}
242244

0 commit comments

Comments
 (0)