google / java-photoslibrary

Java client library for the Google Photos Library API
http://developers.google.com/photos
Apache License 2.0
107 stars 64 forks source link

NullPointerException in PhotosLibraryUploadCallable #32

Closed ylexus closed 2 years ago

ylexus commented 4 years ago

Using version 1.5.0.

One of users of my app have recently reported an issue (https://github.com/ylexus/jiotty-photos-uploader/issues/34#issuecomment-639217788) which was partially caused by a NPE in the google photos client. Seems like it assumes "X-Goog-Upload-Status" header should always be there but it was not. The API call was "uploadMediaItem".

Caused by: java.lang.RuntimeException: Failed uploading D:\_Pictures\2015-2\20159999_Âø¶µÀH¤â©ç\IMG_1075.JPG
    at net.yudichev.jiotty.connector.google.photos.GooglePhotosClientImpl.lambda$null$1(GooglePhotosClientImpl.java:69) ~[jiotty-connector-google-photos-1.5.0.jar:?]
    at java.util.Optional.ifPresent(Unknown Source) ~[?:?]
    at net.yudichev.jiotty.connector.google.photos.GooglePhotosClientImpl.lambda$null$2(GooglePhotosClientImpl.java:69) ~[jiotty-connector-google-photos-1.5.0.jar:?]
    at net.yudichev.jiotty.common.inject.BaseLifecycleComponent.lambda$whenStartedAndNotLifecycling$5(BaseLifecycleComponent.java:60) ~[jiotty-common-1.5.0.jar:?]
    at net.yudichev.jiotty.common.lang.Locks.inLock(Locks.java:22) ~[jiotty-common-1.5.0.jar:?]
    at net.yudichev.jiotty.common.inject.BaseLifecycleComponent.whenNotLifecycling(BaseLifecycleComponent.java:54) ~[jiotty-common-1.5.0.jar:?]
    at net.yudichev.jiotty.common.inject.BaseLifecycleComponent.whenStartedAndNotLifecycling(BaseLifecycleComponent.java:58) ~[jiotty-common-1.5.0.jar:?]
    at net.yudichev.jiotty.connector.google.photos.GooglePhotosClientImpl.lambda$uploadMediaData$3(GooglePhotosClientImpl.java:56) ~[jiotty-connector-google-photos-1.5.0.jar:?]
    ... 4 more
Caused by: com.google.api.gax.rpc.ApiException: java.lang.NullPointerException
    at com.google.photos.library.v1.upload.PhotosLibraryUploadExceptionMappingFn.apply(PhotosLibraryUploadExceptionMappingFn.java:48) ~[google-photos-library-client-1.5.0.jar:1.5.0]
    at com.google.photos.library.v1.upload.PhotosLibraryUploadExceptionMappingFn.apply(PhotosLibraryUploadExceptionMappingFn.java:29) ~[google-photos-library-client-1.5.0.jar:1.5.0]
    at com.google.api.core.ApiFutures$GaxFunctionToGuavaFunction.apply(ApiFutures.java:204) ~[api-common-1.8.1.jar:?]
    at com.google.common.util.concurrent.AbstractCatchingFuture$CatchingFuture.doFallback(AbstractCatchingFuture.java:223) ~[guava-28.2-jre.jar:?]
    at com.google.common.util.concurrent.AbstractCatchingFuture$CatchingFuture.doFallback(AbstractCatchingFuture.java:211) ~[guava-28.2-jre.jar:?]
    at com.google.common.util.concurrent.AbstractCatchingFuture.run(AbstractCatchingFuture.java:124) ~[guava-28.2-jre.jar:?]
    at com.google.common.util.concurrent.DirectExecutor.execute(DirectExecutor.java:30) ~[guava-28.2-jre.jar:?]
    at com.google.common.util.concurrent.ExecutionList.executeListener(ExecutionList.java:141) ~[guava-28.2-jre.jar:?]
    at com.google.common.util.concurrent.ExecutionList.execute(ExecutionList.java:130) ~[guava-28.2-jre.jar:?]
    at com.google.common.util.concurrent.ListenableFutureTask.done(ListenableFutureTask.java:86) ~[guava-28.2-jre.jar:?]
    at java.util.concurrent.FutureTask.finishCompletion(Unknown Source) ~[?:?]
    at java.util.concurrent.FutureTask.setException(Unknown Source) ~[?:?]
    at java.util.concurrent.FutureTask.run(Unknown Source) ~[?:?]
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) ~[?:?]
    at java.util.concurrent.FutureTask.run(Unknown Source) ~[?:?]
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source) ~[?:?]
    ... 3 more
Caused by: java.lang.NullPointerException
    at com.google.photos.library.v1.upload.PhotosLibraryUploadCallable.getUploadUrl(PhotosLibraryUploadCallable.java:228) ~[google-photos-library-client-1.5.0.jar:1.5.0]
    at com.google.photos.library.v1.upload.PhotosLibraryUploadCallable.call(PhotosLibraryUploadCallable.java:110) ~[google-photos-library-client-1.5.0.jar:1.5.0]
    at com.google.photos.library.v1.upload.PhotosLibraryUploadCallable.call(PhotosLibraryUploadCallable.java:45) ~[google-photos-library-client-1.5.0.jar:1.5.0]
    at java.util.concurrent.FutureTask.run(Unknown Source) ~[?:?]
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) ~[?:?]
    at java.util.concurrent.FutureTask.run(Unknown Source) ~[?:?]
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source) ~[?:?]
    ... 3 more
jfschmakeit commented 3 years ago

Yes, there is an assumption that the API always returns the UPLOAD_STATUS_HEADER field. I'm not sure when this could fail, but it makes sense to avoid this NullPointerException at least.

I'm preparing a change that will throw an IllegalStateException and guard against the NPE, similar to how other unexpected upload statuses are handled.

shreelakshmijoshi commented 2 years ago

Hi @ylexus ! I am a new open source contributor and would love to solve this issue, could you help me understand the issue better by providing some extra references ? Is this is issue open to contribute ?

ylexus commented 2 years ago

@shreelakshmijoshi seems like @jfschmakeit has already started working on this - can you liaise with them? I am a issue reporter, I am not familiar with the design of the library to help.

Not sure what you mean by providing extra references.