[ 
https://issues.apache.org/jira/browse/JCLOUDS-1646?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17926230#comment-17926230
 ] 

Andrew Gaul commented on JCLOUDS-1646:
--------------------------------------

Sorry, I still don't understand:
{code:java}
   @Override
   public Blob getBlob(String container, String name, GetOptions options) {
      GoogleCloudStorageObject gcsObject = 
api.getObjectApi().getObject(container, Strings2.urlEncode(name));
      if (gcsObject == null) {
         return null;
      }
      org.jclouds.http.options.GetOptions httpOptions = 
blob2ObjectGetOptions.apply(options);
      MutableBlobMetadata metadata = objectToBlobMetadata.apply(gcsObject);
      Blob blob = new BlobImpl(metadata);
      Payload payload = api.getObjectApi().download(container, 
Strings2.urlEncode(name), httpOptions).getPayload();
      long contentLength = payload.getContentMetadata().getContentLength();
      payload.setContentMetadata(metadata.getContentMetadata()); // Doing this 
first retains it on setPayload.
      blob.setPayload(payload);
      // getObject() returns the full object length but download() could be 
smaller due to range requests.
      payload.getContentMetadata().setContentLength(contentLength);
      return blob;
   }{code}
If the {{gcsObject}} is null then it should return.  Are you suggesting that 
there is a race between the calls to {{getObject}} and {{download}} where 
another client removes the blob?

I do admit that the code should use {{Long}} instead of {{long}} but I want to 
understand if this is a widespread issue or if it only occurs in a very 
specific situation.

> GCP BlobStore fails to get blob
> -------------------------------
>
>                 Key: JCLOUDS-1646
>                 URL: https://issues.apache.org/jira/browse/JCLOUDS-1646
>             Project: jclouds
>          Issue Type: Bug
>          Components: jclouds-blobstore
>    Affects Versions: 2.7.0
>            Reporter: Aliaksandr
>            Priority: Major
>              Labels: google-cloud-storage
>
> *Steps to reproduce*
> * Configure blob store using `google-cloud-storage`
> * Try to get a blob which doesn't exist
> * The error occurred something like below
> {noformat}
> java.lang.NullPointerException: Cannot invoke "java.lang.Long.longValue()" 
> because the return value of 
> "org.jclouds.io.MutableContentMetadata.getContentLength()" is null
>       at 
> org.jclouds.googlecloudstorage.blobstore.GoogleCloudStorageBlobStore.getBlob(GoogleCloudStorageBlobStore.java:254)
>       at 
> org.jclouds.blobstore.internal.BaseBlobStore.getBlob(BaseBlobStore.java:217)
>       at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(native)
>       at 
> jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
>       at 
> jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>       at java.lang.reflect.Method.invoke(Method.java:568)
>       at 
> com.google.inject.internal.DelegatingInvocationHandler.invoke(DelegatingInvocationHandler.java:50)
>       at jdk.proxy3.$Proxy129.getBlob(unknown)
> {noformat}
> *Root cause*
> The attribute `Content-Length` might be null in 
> `org.jclouds.io.ContentMetadata#getContentLength` but the code does a cast to 
> primitive type(see 
> `org.jclouds.googlecloudstorage.blobstore.GoogleCloudStorageBlobStore#getBlob`):
> {noformat}
> Payload payload = api.getObjectApi().download(container, 
> Strings2.urlEncode(name), httpOptions).getPayload();
> long contentLength = payload.getContentMetadata().getContentLength();
> {noformat}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to