1717package com .google .cloud .storage ;
1818
1919import static com .google .cloud .storage .GrpcUtils .contextWithBucketName ;
20+ import static com .google .cloud .storage .Utils .nullSafeList ;
2021
2122import com .google .api .core .SettableApiFuture ;
2223import com .google .api .gax .grpc .GrpcCallContext ;
3233import com .google .cloud .storage .Retrying .RetryingDependencies ;
3334import com .google .cloud .storage .UnbufferedWritableByteChannelSession .UnbufferedWritableByteChannel ;
3435import com .google .common .annotations .VisibleForTesting ;
35- import com .google .common .collect .ImmutableList ;
3636import com .google .protobuf .ByteString ;
3737import com .google .storage .v2 .BidiWriteObjectRequest ;
3838import com .google .storage .v2 .BidiWriteObjectResponse ;
@@ -297,7 +297,7 @@ public void onNext(BidiWriteObjectResponse value) {
297297 } else {
298298 clientDetectedError (
299299 ResumableSessionFailureScenario .SCENARIO_7 .toStorageException (
300- ImmutableList . of (lastWrittenRequest ), value , context , null ));
300+ nullSafeList (lastWrittenRequest ), value , context , null ));
301301 }
302302 } else if (finalizing && value .hasResource ()) {
303303 long totalSentBytes = writeCtx .getTotalSentBytes ().get ();
@@ -308,16 +308,16 @@ public void onNext(BidiWriteObjectResponse value) {
308308 } else if (finalSize < totalSentBytes ) {
309309 clientDetectedError (
310310 ResumableSessionFailureScenario .SCENARIO_4_1 .toStorageException (
311- ImmutableList . of (lastWrittenRequest ), value , context , null ));
311+ nullSafeList (lastWrittenRequest ), value , context , null ));
312312 } else {
313313 clientDetectedError (
314314 ResumableSessionFailureScenario .SCENARIO_4_2 .toStorageException (
315- ImmutableList . of (lastWrittenRequest ), value , context , null ));
315+ nullSafeList (lastWrittenRequest ), value , context , null ));
316316 }
317317 } else if (!finalizing && value .hasResource ()) {
318318 clientDetectedError (
319319 ResumableSessionFailureScenario .SCENARIO_1 .toStorageException (
320- ImmutableList . of (lastWrittenRequest ), value , context , null ));
320+ nullSafeList (lastWrittenRequest ), value , context , null ));
321321 } else if (finalizing && value .hasPersistedSize ()) {
322322 long totalSentBytes = writeCtx .getTotalSentBytes ().get ();
323323 long persistedSize = value .getPersistedSize ();
@@ -329,16 +329,16 @@ public void onNext(BidiWriteObjectResponse value) {
329329 } else if (persistedSize < totalSentBytes ) {
330330 clientDetectedError (
331331 ResumableSessionFailureScenario .SCENARIO_3 .toStorageException (
332- ImmutableList . of (lastWrittenRequest ), value , context , null ));
332+ nullSafeList (lastWrittenRequest ), value , context , null ));
333333 } else {
334334 clientDetectedError (
335335 ResumableSessionFailureScenario .SCENARIO_2 .toStorageException (
336- ImmutableList . of (lastWrittenRequest ), value , context , null ));
336+ nullSafeList (lastWrittenRequest ), value , context , null ));
337337 }
338338 } else {
339339 clientDetectedError (
340340 ResumableSessionFailureScenario .SCENARIO_0 .toStorageException (
341- ImmutableList . of (lastWrittenRequest ), value , context , null ));
341+ nullSafeList (lastWrittenRequest ), value , context , null ));
342342 }
343343 }
344344
@@ -352,7 +352,7 @@ public void onError(Throwable t) {
352352 && ed .getErrorInfo ().getReason ().equals ("GRPC_MISMATCHED_UPLOAD_SIZE" ))) {
353353 clientDetectedError (
354354 ResumableSessionFailureScenario .SCENARIO_5 .toStorageException (
355- ImmutableList . of (lastWrittenRequest ), null , context , oore ));
355+ nullSafeList (lastWrittenRequest ), null , context , oore ));
356356 return ;
357357 }
358358 }
@@ -367,9 +367,7 @@ public void onError(Throwable t) {
367367 tmp .getCode (),
368368 tmp .getMessage (),
369369 tmp .getReason (),
370- lastWrittenRequest != null
371- ? ImmutableList .of (lastWrittenRequest )
372- : ImmutableList .of (),
370+ nullSafeList (lastWrittenRequest ),
373371 null ,
374372 context ,
375373 t );
@@ -422,7 +420,7 @@ void await() {
422420 clientDetectedError = null ;
423421 previousError = null ;
424422 if ((e != null || err != null ) && stream != null ) {
425- if (lastWrittenRequest .getFinishWrite ()) {
423+ if (lastWrittenRequest != null && lastWrittenRequest .getFinishWrite ()) {
426424 stream .onCompleted ();
427425 } else {
428426 stream .onError (Status .CANCELLED .asRuntimeException ());
0 commit comments