17
17
package com .google .cloud .storage ;
18
18
19
19
import static com .google .cloud .storage .GrpcUtils .contextWithBucketName ;
20
+ import static com .google .cloud .storage .Utils .nullSafeList ;
20
21
21
22
import com .google .api .core .SettableApiFuture ;
22
23
import com .google .api .gax .grpc .GrpcCallContext ;
32
33
import com .google .cloud .storage .Retrying .RetryingDependencies ;
33
34
import com .google .cloud .storage .UnbufferedWritableByteChannelSession .UnbufferedWritableByteChannel ;
34
35
import com .google .common .annotations .VisibleForTesting ;
35
- import com .google .common .collect .ImmutableList ;
36
36
import com .google .protobuf .ByteString ;
37
37
import com .google .storage .v2 .BidiWriteObjectRequest ;
38
38
import com .google .storage .v2 .BidiWriteObjectResponse ;
@@ -297,7 +297,7 @@ public void onNext(BidiWriteObjectResponse value) {
297
297
} else {
298
298
clientDetectedError (
299
299
ResumableSessionFailureScenario .SCENARIO_7 .toStorageException (
300
- ImmutableList . of (lastWrittenRequest ), value , context , null ));
300
+ nullSafeList (lastWrittenRequest ), value , context , null ));
301
301
}
302
302
} else if (finalizing && value .hasResource ()) {
303
303
long totalSentBytes = writeCtx .getTotalSentBytes ().get ();
@@ -308,16 +308,16 @@ public void onNext(BidiWriteObjectResponse value) {
308
308
} else if (finalSize < totalSentBytes ) {
309
309
clientDetectedError (
310
310
ResumableSessionFailureScenario .SCENARIO_4_1 .toStorageException (
311
- ImmutableList . of (lastWrittenRequest ), value , context , null ));
311
+ nullSafeList (lastWrittenRequest ), value , context , null ));
312
312
} else {
313
313
clientDetectedError (
314
314
ResumableSessionFailureScenario .SCENARIO_4_2 .toStorageException (
315
- ImmutableList . of (lastWrittenRequest ), value , context , null ));
315
+ nullSafeList (lastWrittenRequest ), value , context , null ));
316
316
}
317
317
} else if (!finalizing && value .hasResource ()) {
318
318
clientDetectedError (
319
319
ResumableSessionFailureScenario .SCENARIO_1 .toStorageException (
320
- ImmutableList . of (lastWrittenRequest ), value , context , null ));
320
+ nullSafeList (lastWrittenRequest ), value , context , null ));
321
321
} else if (finalizing && value .hasPersistedSize ()) {
322
322
long totalSentBytes = writeCtx .getTotalSentBytes ().get ();
323
323
long persistedSize = value .getPersistedSize ();
@@ -329,16 +329,16 @@ public void onNext(BidiWriteObjectResponse value) {
329
329
} else if (persistedSize < totalSentBytes ) {
330
330
clientDetectedError (
331
331
ResumableSessionFailureScenario .SCENARIO_3 .toStorageException (
332
- ImmutableList . of (lastWrittenRequest ), value , context , null ));
332
+ nullSafeList (lastWrittenRequest ), value , context , null ));
333
333
} else {
334
334
clientDetectedError (
335
335
ResumableSessionFailureScenario .SCENARIO_2 .toStorageException (
336
- ImmutableList . of (lastWrittenRequest ), value , context , null ));
336
+ nullSafeList (lastWrittenRequest ), value , context , null ));
337
337
}
338
338
} else {
339
339
clientDetectedError (
340
340
ResumableSessionFailureScenario .SCENARIO_0 .toStorageException (
341
- ImmutableList . of (lastWrittenRequest ), value , context , null ));
341
+ nullSafeList (lastWrittenRequest ), value , context , null ));
342
342
}
343
343
}
344
344
@@ -352,7 +352,7 @@ public void onError(Throwable t) {
352
352
&& ed .getErrorInfo ().getReason ().equals ("GRPC_MISMATCHED_UPLOAD_SIZE" ))) {
353
353
clientDetectedError (
354
354
ResumableSessionFailureScenario .SCENARIO_5 .toStorageException (
355
- ImmutableList . of (lastWrittenRequest ), null , context , oore ));
355
+ nullSafeList (lastWrittenRequest ), null , context , oore ));
356
356
return ;
357
357
}
358
358
}
@@ -367,9 +367,7 @@ public void onError(Throwable t) {
367
367
tmp .getCode (),
368
368
tmp .getMessage (),
369
369
tmp .getReason (),
370
- lastWrittenRequest != null
371
- ? ImmutableList .of (lastWrittenRequest )
372
- : ImmutableList .of (),
370
+ nullSafeList (lastWrittenRequest ),
373
371
null ,
374
372
context ,
375
373
t );
@@ -422,7 +420,7 @@ void await() {
422
420
clientDetectedError = null ;
423
421
previousError = null ;
424
422
if ((e != null || err != null ) && stream != null ) {
425
- if (lastWrittenRequest .getFinishWrite ()) {
423
+ if (lastWrittenRequest != null && lastWrittenRequest .getFinishWrite ()) {
426
424
stream .onCompleted ();
427
425
} else {
428
426
stream .onError (Status .CANCELLED .asRuntimeException ());
0 commit comments