You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@jclouds.apache.org by Jean Helou <se...@byjean.eu> on 2018/08/22 09:33:48 UTC

NullPointer in BlobStore#streamBlob using RegionScopedSwiftBlobStore (2.1.1)

Hello,

I am currently working on integrating JClouds to create a blobstore storage
for apache james. I noticed that using

    blobStore.streamBlob("container", "wrongid");

yields a NullPointerException when trying to access a blob which doesn't
exist. The NPE is raised in RegionScopedSwiftBlobStore when the streamBlob
method tries to read the blob metadata.

I think it should null check and return null or an empty inputstream but
not raise an NPE

see https://github.com/jclouds/jclouds
/blob/46759f8bda00f86ef934345846e22e2bd2b0d7ae/apis/openstack-swift/src/main/java/org/
jclouds/openstack/swift/v1/blobstore/RegionScopedSwiftBlobStore.java#L691

for now I work around by using

    blobStore.getBlob("container","id");

doing the nullcheck myself and then getting the inputstream from the blob's
payload.

best regards,
jean

Re: NullPointer in BlobStore#streamBlob using RegionScopedSwiftBlobStore (2.1.1)

Posted by Jean Helou <se...@byjean.eu>.
thanks for your answers, we have indeed abandonned streamBlob because of
the issues outlined in my original email and go through  getBlob

jean

Le mar. 16 oct. 2018 à 08:20, Andrew Gaul <ga...@apache.org> a écrit :

> On Wed, Aug 22, 2018 at 11:33:48AM +0200, Jean Helou wrote:
> > Hello,
> >
> > I am currently working on integrating JClouds to create a blobstore
> storage
> > for apache james. I noticed that using
> >
> >     blobStore.streamBlob("container", "wrongid");
> >
> > yields a NullPointerException when trying to access a blob which doesn't
> > exist. The NPE is raised in RegionScopedSwiftBlobStore when the
> streamBlob
> > method tries to read the blob metadata.
> >
> > I think it should null check and return null or an empty inputstream but
> > not raise an NPE
> >
> > see https://github.com/jclouds/jclouds
> >
> /blob/46759f8bda00f86ef934345846e22e2bd2b0d7ae/apis/openstack-swift/src/main/java/org/
> > jclouds/openstack/swift/v1/blobstore/RegionScopedSwiftBlobStore.java#L691
> >
> > for now I work around by using
> >
> >     blobStore.getBlob("container","id");
> >
> > doing the nullcheck myself and then getting the inputstream from the
> blob's
> > payload.
>
> Sorry for the late reply but I find the implementation of
> BlobStore.streamBlob confusing since it lives in the portable
> abstraction yet only has one implementation.  I recommend using getBlob
> which actually does stream the payload.
>
> --
> Andrew Gaul
> http://gaul.org/
>

Re: NullPointer in BlobStore#streamBlob using RegionScopedSwiftBlobStore (2.1.1)

Posted by Andrew Gaul <ga...@apache.org>.
On Wed, Aug 22, 2018 at 11:33:48AM +0200, Jean Helou wrote:
> Hello,
> 
> I am currently working on integrating JClouds to create a blobstore storage
> for apache james. I noticed that using
> 
>     blobStore.streamBlob("container", "wrongid");
> 
> yields a NullPointerException when trying to access a blob which doesn't
> exist. The NPE is raised in RegionScopedSwiftBlobStore when the streamBlob
> method tries to read the blob metadata.
> 
> I think it should null check and return null or an empty inputstream but
> not raise an NPE
> 
> see https://github.com/jclouds/jclouds
> /blob/46759f8bda00f86ef934345846e22e2bd2b0d7ae/apis/openstack-swift/src/main/java/org/
> jclouds/openstack/swift/v1/blobstore/RegionScopedSwiftBlobStore.java#L691
> 
> for now I work around by using
> 
>     blobStore.getBlob("container","id");
> 
> doing the nullcheck myself and then getting the inputstream from the blob's
> payload.

Sorry for the late reply but I find the implementation of
BlobStore.streamBlob confusing since it lives in the portable
abstraction yet only has one implementation.  I recommend using getBlob
which actually does stream the payload.

-- 
Andrew Gaul
http://gaul.org/

Re: NullPointer in BlobStore#streamBlob using RegionScopedSwiftBlobStore (2.1.1)

Posted by Ignasi Barrera <na...@apache.org>.
Hi,

Returning an empty input stream is not a good idea, as users wouldn't
have feedback about why that stream is empty. Probably an empty blob,
probably a blob that does not exist... An empty input stream does not
provide the right semantics so that the calling code knows what is
going on and what to do.

The same applies to a null return value. It makes sense for a standard
"get" method to return null to indicate a resource does not exist, but
when it comes to "get the resource contents" (which is what you do
when getting its InputStream), returning a null value does not provide
the right semantics. The calling code doesn't know if the resource
does not exist, if the resource exists but has no content, etc, and
will have to do the same existence checks anyway.


I think failing is the right thing to do there, although an NPE is not
the best exception to propagate. We should be propagating a
ResourceNotFoundException there.

From a calling code perspective, a getBlog or blobExists call before
calling streamBlob looks like the right thing to do.


Regards,

I.
On Wed, 22 Aug 2018 at 11:34, Jean Helou <se...@byjean.eu> wrote:
>
> Hello,
>
> I am currently working on integrating JClouds to create a blobstore storage for apache james. I noticed that using
>
>     blobStore.streamBlob("container", "wrongid");
>
> yields a NullPointerException when trying to access a blob which doesn't exist. The NPE is raised in RegionScopedSwiftBlobStore when the streamBlob method tries to read the blob metadata.
>
> I think it should null check and return null or an empty inputstream but not raise an NPE
>
> see https://github.com/jclouds/jclouds/blob/46759f8bda00f86ef934345846e22e2bd2b0d7ae/apis/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/blobstore/RegionScopedSwiftBlobStore.java#L691
>
> for now I work around by using
>
>     blobStore.getBlob("container","id");
>
> doing the nullcheck myself and then getting the inputstream from the blob's payload.
>
> best regards,
> jean
>