Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
* @see #getBody()
* @see #getHeaders()
*/
public class HttpEntity<T> {
public class HttpEntity<T extends @Nullable Object> {

/**
* An {@code HttpEntity} instance with a {@code null} body and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
* @see org.springframework.web.client.RestOperations#getForEntity(URI, Class)
* @see RequestEntity
*/
public class ResponseEntity<T> extends HttpEntity<T> {
public class ResponseEntity<T extends @Nullable Object> extends HttpEntity<T> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you check how ResponseEntity of "empty value" translates in a sample application checked with NullAway, using https://github.com/sdeleuze/jspecify-nullaway-demo as a basis maybe?

I guess that would be ResponseEntity<@Nullable Void> based on jspecify/jspecify#51 but worth to check.


private final HttpStatusCode status;

Expand Down Expand Up @@ -261,7 +261,7 @@ public static BodyBuilder ok() {
* @return the created {@code ResponseEntity}
* @since 4.1
*/
public static <T> ResponseEntity<T> ok(@Nullable T body) {
public static <T extends @Nullable Object> ResponseEntity<T> ok(@Nullable T body) {
return ok().body(body);
}

Expand Down Expand Up @@ -308,7 +308,7 @@ public <T> ResponseEntity<T> build() {
* @return the created {@code ResponseEntity}
* @since 6.0.5
*/
public static <T> ResponseEntity<T> ofNullable(@Nullable T body) {
public static <T extends @Nullable Object> ResponseEntity<T> ofNullable(@Nullable T body) {
if (body == null) {
return notFound().build();
}
Expand Down Expand Up @@ -658,7 +658,7 @@ public <T> ResponseEntity<T> build() {
}

@Override
public <T> ResponseEntity<T> body(@Nullable T body) {
public <T extends @Nullable Object> ResponseEntity<T> body(@Nullable T body) {
return new ResponseEntity<>(body, this.headers, this.statusCode);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,21 @@ class ResponseEntityKotlinTests {
assertThat(responseEntity.body).isNull()
}


@Test
fun ofNullNullableType() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add a test for empty value, ie. how ResponseEntity<@Nullable Void> translates to Kotlin. Is it ResponseEntity<Unit>?

val responseEntity = ResponseEntity.ofNullable<Int?>(null)
assertThat(responseEntity).isNotNull()
assertThat(responseEntity.statusCode).isEqualTo(HttpStatus.NOT_FOUND)
assertThat(responseEntity.body).isNull()
}

@Test
fun okNullNullableType() {
val responseEntity = ResponseEntity.ok<String?>(null)
assertThat(responseEntity).isNotNull()
assertThat(responseEntity.statusCode).isEqualTo(HttpStatus.OK)
assertThat(responseEntity.body).isNull()
}

}