Skip to content

Commit

Permalink
Merge pull request #183 from mziccard/fix-npe-storage-list
Browse files Browse the repository at this point in the history
Fix NPE when listing buckets in empty project and blobs in empty bucket
  • Loading branch information
aozarov committed Sep 28, 2015
2 parents 48458d3 + b5b43d9 commit 23ebbec
Showing 1 changed file with 15 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import com.google.api.services.storage.model.StorageObject;
import com.google.common.base.Function;
import com.google.common.base.Functions;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
Expand Down Expand Up @@ -234,14 +235,16 @@ public Tuple<String, Iterable<com.google.api.services.storage.model.Bucket>> cal
}
}, serviceOptions.retryParams(), EXCEPTION_HANDLER);
String cursor = result.x();
return new BaseListResult<>(new BucketPageFetcher(serviceOptions, cursor, optionsMap), cursor,
Iterables.transform(result.y(),
Iterable<BucketInfo> buckets =
result.y() == null ? ImmutableList.<BucketInfo>of() : Iterables.transform(result.y(),
new Function<com.google.api.services.storage.model.Bucket, BucketInfo>() {
@Override
public BucketInfo apply(com.google.api.services.storage.model.Bucket bucketPb) {
return BucketInfo.fromPb(bucketPb);
}
}));
});
return new BaseListResult<>(new BucketPageFetcher(serviceOptions, cursor, optionsMap), cursor,
buckets);
}

@Override
Expand All @@ -259,14 +262,17 @@ public Tuple<String, Iterable<StorageObject>> call() {
}
}, serviceOptions.retryParams(), EXCEPTION_HANDLER);
String cursor = result.x();
return new BaseListResult<>(new BlobPageFetcher(bucket, serviceOptions, cursor, optionsMap), cursor,
Iterables.transform(result.y(),
Iterable<BlobInfo> blobs =
result.y() == null ? ImmutableList.<BlobInfo>of() : Iterables.transform(result.y(),
new Function<StorageObject, BlobInfo>() {
@Override
public BlobInfo apply(StorageObject storageObject) {
return BlobInfo.fromPb(storageObject);
}
}));
});
return new BaseListResult<>(new BlobPageFetcher(bucket, serviceOptions, cursor, optionsMap),
cursor,
blobs);
}

@Override
Expand Down Expand Up @@ -434,7 +440,7 @@ public BlobReadChannel reader(String bucket, String blob, BlobSourceOption... op
return new BlobReadChannelImpl(options(), BlobInfo.of(bucket, blob), optionsMap);
}

@Override
@Override
public BlobWriteChannel writer(BlobInfo blobInfo, BlobTargetOption... options) {
final Map<StorageRpc.Option, ?> optionsMap = optionMap(blobInfo, options);
return new BlobWriterChannelImpl(options(), blobInfo, optionsMap);
Expand All @@ -461,12 +467,12 @@ public URL signUrl(BlobInfo blobInfo, long expiration, SignUrlOption... options)
stBuilder.append(HttpMethod.GET);
}
stBuilder.append('\n');
if (firstNonNull((Boolean) optionMap.get(SignUrlOption.Option.MD5) , false)) {
if (firstNonNull((Boolean) optionMap.get(SignUrlOption.Option.MD5), false)) {
checkArgument(blobInfo.md5() != null, "Blob is missing a value for md5");
stBuilder.append(blobInfo.md5());
}
stBuilder.append('\n');
if (firstNonNull((Boolean) optionMap.get(SignUrlOption.Option.CONTENT_TYPE) , false)) {
if (firstNonNull((Boolean) optionMap.get(SignUrlOption.Option.CONTENT_TYPE), false)) {
checkArgument(blobInfo.contentType() != null, "Blob is missing a value for content-type");
stBuilder.append(blobInfo.contentType());
}
Expand Down

0 comments on commit 23ebbec

Please sign in to comment.