Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add documentation to clarify if ResponseBody.close() is necessary #3400

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from
Open
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
14 changes: 12 additions & 2 deletions retrofit/src/main/java/retrofit2/Response.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,22 @@ public boolean isSuccessful() {
return rawResponse.isSuccessful();
}

/** The deserialized response body of a {@linkplain #isSuccessful() successful} response. */
/**
* The deserialized response body of a {@linkplain #isSuccessful() successful} response.
*
* <p>If the body is of type {@link ResponseBody}, {@link ResponseBody#close()} must always be
* called to avoid leaking resources
Comment on lines +153 to +154
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is only true of @Streaming endpoints. I think this doc needs to live only on the @Streaming annotation and not here.

The one down below is still useful, however.

Copy link
Author

Choose a reason for hiding this comment

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

Thanks, that makes sense. I'll try to update it tonight.

*/
public @Nullable T body() {
return body;
}

/** The raw response body of an {@linkplain #isSuccessful() unsuccessful} response. */
/**
* The raw response body of an {@linkplain #isSuccessful() unsuccessful} response.
*
* <p>Calling {@link ResponseBody#close close} on the response body is unnecessary since it is
* closed internally by Retrofit.
*/
public @Nullable ResponseBody errorBody() {
return errorBody;
}
Expand Down