so Kotlin can at least say it returns a nullable type. Thus coercing to a non-null could be a problem.
Now the best code actually depends of the context. I am not familiar with Spring.
aoriani
12/31/2019, 9:07 AM
I imagine that
getBody()
is nullable because
ResponseEntity
represents any HTTP response and not all responses have a body. An HTTP 204, for instance, doesn't have a body.
aoriani
12/31/2019, 9:18 AM
In your case what would missing body mean? That there're no `Task`s ? That there is an error ? You are not checking whether the request actually succeeds (if at least the response has a 200 status code). So assuming it will always succeed is in itself a problem.
In both cases, would it be okay to return an empty list ? Or it is better to throw an exception to know straight away that something went wrong?