Skip to content

Add @Nullable to ResponseEntity generic type#36238

Open
ngocnhan-tran1996 wants to merge 1 commit intospring-projects:mainfrom
ngocnhan-tran1996:gh-36236
Open

Add @Nullable to ResponseEntity generic type#36238
ngocnhan-tran1996 wants to merge 1 commit intospring-projects:mainfrom
ngocnhan-tran1996:gh-36236

Conversation

@ngocnhan-tran1996
Copy link
Contributor

Based on the IDE warning shown in the screenshot

image

This change adds @Nullable to the generic bound of ResponseEntity to make the nullability contract.

Related to gh-36236

Signed-off-by: Tran Ngoc Nhan <ngocnhan.tran1996@gmail.com>
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Jan 31, 2026
@sdeleuze sdeleuze self-assigned this Feb 5, 2026
Copy link
Contributor

@sdeleuze sdeleuze left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please refine as suggested for all similar use cases and check with a full build that NullAway does not trigger errors.


private final HttpHeaders headers;

private final @Nullable T body;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, you should just leverage the nullability defined at type level, so please remove the explicit @Nullable override here.

* @param headers the entity headers
* @since 7.0
*/
public HttpEntity(@Nullable T body, @Nullable HttpHeaders headers) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, you should just leverage the nullability defined at type level, so please remove the explicit @Nullable override here and in other similar use cases.

* @since 4.1
*/
public static <T> ResponseEntity<T> ok(@Nullable T body) {
public static <T extends @Nullable Object> ResponseEntity<T> ok(@Nullable T body) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here I think you should just use public static <T> ResponseEntity<T> ok(T body) since the nullability is defined at type level. Please adapt similar use cases.

@sdeleuze sdeleuze added the in: web Issues in web modules (web, webmvc, webflux, websocket) label Feb 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

in: web Issues in web modules (web, webmvc, webflux, websocket) status: waiting-for-triage An issue we've not yet triaged or decided on

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants