diff --git a/google-cloud-storage/src/main/java/com/google/cloud/storage/transfermanager/DownloadResult.java b/google-cloud-storage/src/main/java/com/google/cloud/storage/transfermanager/DownloadResult.java index aba05b5d46..27e4c9529b 100644 --- a/google-cloud-storage/src/main/java/com/google/cloud/storage/transfermanager/DownloadResult.java +++ b/google-cloud-storage/src/main/java/com/google/cloud/storage/transfermanager/DownloadResult.java @@ -138,8 +138,12 @@ public Builder setException(@NonNull StorageException exception) { public DownloadResult build() { checkNotNull(input); checkNotNull(status); - // TODO: validate either outputDestination or exception are non-null relative to the value of - // status. + if (status == TransferStatus.SUCCESS) { + checkNotNull(outputDestination); + } else if (status == TransferStatus.FAILED_TO_START + || status == TransferStatus.FAILED_TO_FINISH) { + checkNotNull(exception); + } return new DownloadResult(input, outputDestination, status, exception); } } diff --git a/google-cloud-storage/src/main/java/com/google/cloud/storage/transfermanager/UploadResult.java b/google-cloud-storage/src/main/java/com/google/cloud/storage/transfermanager/UploadResult.java index b67d7fcd5d..2f8b918694 100644 --- a/google-cloud-storage/src/main/java/com/google/cloud/storage/transfermanager/UploadResult.java +++ b/google-cloud-storage/src/main/java/com/google/cloud/storage/transfermanager/UploadResult.java @@ -137,8 +137,12 @@ public Builder setException(@NonNull StorageException exception) { public UploadResult build() { checkNotNull(input); checkNotNull(status); - // TODO: validate either uploadedBlob or exception are non-null relative to the value of - // status. + if (status == TransferStatus.SUCCESS) { + checkNotNull(uploadedBlob); + } else if (status == TransferStatus.FAILED_TO_START + || status == TransferStatus.FAILED_TO_FINISH) { + checkNotNull(exception); + } return new UploadResult(input, status, uploadedBlob, exception); } }