Skip to content

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

image

I have removed but the compileJava task build fail

Within @NullMarked, remember, unannotated types are the same as if they were annotated with @nonnull. Since the bound of E is the same as @nonnull Number, and not @nullable Number, that means the type argument for E can't be a type that includes null. @nullable Integer can't be the type argument, then, since that can include null. (In other words: @nullable Integer is not a subtype of Number.)

https://jspecify.dev/docs/user-guide/#declaring-generics

* @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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

DITTO

@sdeleuze sdeleuze added the in: web Issues in web modules (web, webmvc, webflux, websocket) label Feb 5, 2026
@sbrannen sbrannen changed the title Add @Nullable to ResponseEntity generic type Revise nullability in HttpEntity and ResponseEntity Feb 6, 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.

4 participants