Skip to content

Commit 4c041d7

Browse files
committed
Update UrlRequest and BidirectionalStream documentation
Explicitly state that there are no guarantees regarding the specific object being passed to callbacks within UrlRequest.Callback and BidirectionalStream.Callback. Bug: 333390290, 328442628 Change-Id: Icbaa3687ed7c99bea9ccdb90339ebb07b56a63ec
1 parent 44e8bfa commit 4c041d7

File tree

2 files changed

+70
-15
lines changed

2 files changed

+70
-15
lines changed

android/java/src/android/net/http/BidirectionalStream.java

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,11 @@ public interface Callback {
171171
* BidirectionalStream#read read()} to start reading data. Consumer may call {@link
172172
* BidirectionalStream#write write()} to start writing data.
173173
*
174-
* @param stream the stream that is ready.
174+
* @param stream the stream that is ready. <strong>This is not guaranteed to be the same
175+
* object as the one received by other callbacks, nor is it guaranteed to be the one
176+
* returned by {@link BidirectionalStream.Builder#build}.</strong> However, method
177+
* calls on this object will have the same effects as calls on the original
178+
* {@link BidirectionalStream}.
175179
*/
176180
void onStreamReady(@NonNull BidirectionalStream stream);
177181

@@ -181,7 +185,11 @@ public interface Callback {
181185
* BidirectionalStream#read read()} to start reading. Consumer may call {@link
182186
* BidirectionalStream#write write()} to start writing or close the stream.
183187
*
184-
* @param stream the stream on which response headers were received.
188+
* @param stream the stream on which response headers were received. <strong>This is not
189+
* guaranteed to be the same object as the one received by other callbacks, nor is
190+
* it guaranteed to be the one returned by {@link BidirectionalStream.Builder#build}.
191+
* </strong> However, method calls on this object will have the same effects as
192+
* calls on the original {@link BidirectionalStream}.
185193
* @param info the response information.
186194
*/
187195
void onResponseHeadersReceived(@NonNull BidirectionalStream stream,
@@ -194,10 +202,13 @@ void onResponseHeadersReceived(@NonNull BidirectionalStream stream,
194202
* onResponseTrailersReceived()}, if there was pending read data before trailers were
195203
* received.
196204
*
197-
* @param stream the stream on which the read completed
205+
* @param stream the stream on which the read completed. <strong>This is not guaranteed to
206+
* be the same object as the one received by other callbacks, nor is it guaranteed
207+
* to be the one returned by {@link BidirectionalStream.Builder#build}.</strong>
208+
* However, method calls on this object will have the same effects as calls on the
209+
* original {@link BidirectionalStream}.
198210
* @param info the response information
199211
* @param buffer the buffer that was passed to {@link BidirectionalStream#read read()}, now
200-
* containing the received data. The buffer's limit is not changed. The buffer's position is
201212
* set to the end of the received data. If position is not updated, it means the remote side
202213
* has signaled that it will send no more data.
203214
* @param endOfStream if true, this is the last read data, remote will not send more data,
@@ -213,7 +224,11 @@ void onReadCompleted(@NonNull BidirectionalStream stream, @NonNull UrlResponseIn
213224
* limit is not changed. To continue writing, call {@link BidirectionalStream#write
214225
* write()}.
215226
*
216-
* @param stream the stream on which the write completed
227+
* @param stream the stream on which the write completed. <strong>This is not guaranteed to
228+
* be the same object as the one received by other callbacks, nor is it guaranteed
229+
* to be the one returned by {@link BidirectionalStream.Builder#build}.</strong>
230+
* However, method calls on this object will have the same effects as calls on the
231+
* original {@link BidirectionalStream}.
217232
* @param info the response information
218233
* @param buffer the buffer that was passed to {@link BidirectionalStream#write write()}.
219234
* The
@@ -231,7 +246,11 @@ void onWriteCompleted(@NonNull BidirectionalStream stream, @NonNull UrlResponseI
231246
*
232247
* Default implementation takes no action.
233248
*
234-
* @param stream the stream on which response trailers were received
249+
* @param stream the stream on which response trailers were received. <strong>This is not
250+
* guaranteed to be the same object as the one received by other callbacks, nor is
251+
* it guaranteed to be the one returned by {@link BidirectionalStream.Builder#build}.
252+
* </strong> However, method calls on this object will have the same effects as calls
253+
* on the original {@link BidirectionalStream}.
235254
* @param info the response information
236255
* @param trailers the trailers received
237256
*/
@@ -243,7 +262,11 @@ void onResponseTrailersReceived(@NonNull BidirectionalStream stream,
243262
* remotely and locally. Once invoked, no further {@link BidirectionalStream.Callback}
244263
* methods will be invoked.
245264
*
246-
* @param stream the stream which is closed successfully
265+
* @param stream the stream which is closed successfully. <strong>This is not guaranteed to
266+
* be the same object as the one received by other callbacks, nor is it guaranteed
267+
* to be the one returned by {@link BidirectionalStream.Builder#build}.</strong>
268+
* However, method calls on this object will have the same effects as calls on the
269+
* original {@link BidirectionalStream}.
247270
* @param info the response information
248271
*/
249272
void onSucceeded(@NonNull BidirectionalStream stream, @NonNull UrlResponseInfo info);
@@ -254,7 +277,11 @@ void onResponseTrailersReceived(@NonNull BidirectionalStream stream,
254277
* mapped to {@link NetworkException#getErrorCode} codes. Once invoked,
255278
* no further {@link BidirectionalStream.Callback} methods will be invoked.
256279
*
257-
* @param stream the stream which has failed
280+
* @param stream the stream which has failed. <strong>This is not guaranteed to
281+
* be the same object as the one received by other callbacks, nor is it guaranteed
282+
* to be the one returned by {@link BidirectionalStream.Builder#build}.</strong>
283+
* However, method calls on this object will have the same effects as calls on the
284+
* original {@link BidirectionalStream}.
258285
* @param info the response information. May be {@code null} if no response was received.
259286
* @param error information about the failure
260287
*/
@@ -266,7 +293,11 @@ void onFailed(@NonNull BidirectionalStream stream, @Nullable UrlResponseInfo inf
266293
* no further {@link BidirectionalStream.Callback} methods will be invoked. Default
267294
* implementation takes no action.
268295
*
269-
* @param stream the stream that was canceled
296+
* @param stream the stream that was canceled. <strong>This is not guaranteed to
297+
* be the same object as the one received by other callbacks, nor is it guaranteed
298+
* to be the one returned by {@link BidirectionalStream.Builder#build}.</strong>
299+
* However, method calls on this object will have the same effects as calls on the
300+
* original {@link BidirectionalStream}.
270301
* @param info the response information. May be {@code null} if no response was received.
271302
*/
272303
void onCanceled(@NonNull BidirectionalStream stream, @Nullable UrlResponseInfo info);

android/java/src/android/net/http/UrlRequest.java

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,11 @@ public interface Callback {
217217
* The redirect will not be followed until the URLRequest's {@link
218218
* UrlRequest#followRedirect} method is called, either synchronously or asynchronously.
219219
*
220-
* @param request Request being redirected.
220+
* @param request Request being redirected. <strong>This is not guaranteed to be the same
221+
* object as the one received by other callbacks, nor is it guaranteed to be the one
222+
* returned by {@link URLRequest.Builder#build}.</strong> However, method calls on
223+
* this object will have the same effects as calls on the original
224+
* {@link URLRequest}.
221225
* @param info Response information.
222226
* @param newLocationUrl Location where request is redirected.
223227
* @throws Exception if an error occurs while processing a redirect. {@link #onFailed} will
@@ -238,7 +242,11 @@ void onRedirectReceived(@NonNull UrlRequest request,
238242
* onSucceeded()} and {@link Callback#onFailed onFailed()}, until {@link UrlRequest#read
239243
* UrlRequest.read()} is called to attempt to start reading the response body.
240244
*
241-
* @param request Request that started to get response.
245+
* @param request Request that started to get response. <strong>This is not guaranteed to be
246+
* the same object as the one received by other callbacks, nor is it guaranteed to be
247+
* the one returned by {@link URLRequest.Builder#build}.</strong> However, method
248+
* calls on this object will have the same effects as calls on the original
249+
* {@link URLRequest}.
242250
* @param info Response information.
243251
* @throws Exception if an error occurs while processing response start. {@link #onFailed}
244252
* will
@@ -258,7 +266,11 @@ void onResponseStarted(@NonNull UrlRequest request,
258266
* onSucceeded()} and {@link Callback#onFailed onFailed()}, until {@link UrlRequest#read
259267
* UrlRequest.read()} is called to attempt to continue reading the response body.
260268
*
261-
* @param request Request that received data.
269+
* @param request Request that received data. <strong>This is not guaranteed to be the same
270+
* object as the one received by other callbacks, nor is it guaranteed to be the one
271+
* returned by {@link URLRequest.Builder#build}.</strong> However, method calls on
272+
* this object will have the same effects as calls on the original
273+
* {@link URLRequest}.
262274
* @param info Response information.
263275
* @param byteBuffer The buffer that was passed in to {@link UrlRequest#read
264276
* UrlRequest.read()},
@@ -278,7 +290,11 @@ void onReadCompleted(@NonNull UrlRequest request,
278290
* Invoked when request is completed successfully. Once invoked, no other {@link Callback}
279291
* methods will be invoked.
280292
*
281-
* @param request Request that succeeded.
293+
* @param request Request that succeeded. <strong>This is not guaranteed to be the same
294+
* object as the one received by other callbacks, nor is it guaranteed to be the one
295+
* returned by {@link URLRequest.Builder#build}.</strong> However, method calls on
296+
* this object will have the same effects as calls on the original
297+
* {@link URLRequest}.
282298
* @param info Response information.
283299
*/
284300
void onSucceeded(
@@ -289,7 +305,11 @@ void onSucceeded(
289305
* other {@link Callback} methods will be invoked. {@code error} provides information about
290306
* the failure.
291307
*
292-
* @param request Request that failed.
308+
* @param request Request that failed. <strong>This is not guaranteed to be the same
309+
* object as the one received by other callbacks, nor is it guaranteed to be the one
310+
* returned by {@link URLRequest.Builder#build}.</strong> However, method calls on
311+
* this object will have the same effects as calls on the original
312+
* {@link URLRequest}.
293313
* @param info Response information. May be {@code null} if no response was received.
294314
* @param error information about error.
295315
*/
@@ -300,7 +320,11 @@ void onFailed(@NonNull UrlRequest request,
300320
* Invoked if request was canceled via {@link UrlRequest#cancel}. Once invoked, no other
301321
* {@link Callback} methods will be invoked. Default implementation takes no action.
302322
*
303-
* @param request Request that was canceled.
323+
* @param request Request that was canceled. <strong>This is not guaranteed to be the same
324+
* object as the one received by other callbacks, nor is it guaranteed to be the one
325+
* returned by {@link URLRequest.Builder#build}.</strong> However, method calls on
326+
* this object will have the same effects as calls on the original
327+
* {@link URLRequest}.
304328
* @param info Response information. May be {@code null} if no response was received.
305329
*/
306330
void onCanceled(@NonNull UrlRequest request, @Nullable UrlResponseInfo info);

0 commit comments

Comments
 (0)