Azure-sdk-for-java: [BUG] getByResourceGroup throws an NPE when the resource is a Gallery, GalleryImage or GalleryImageVersion

Created on 11 Sep 2020  路  4Comments  路  Source: Azure/azure-sdk-for-java

Describe the bug
getByResourceGroup throws an NPE when the resource is a Gallery, GalleryImage or GalleryImageVersion which it shouldn't. I am just using this function to check whether the resource exists.

Exception or Stack Trace
java.lang.NullPointerException: null
at com.microsoft.azure.management.compute.implementation.GalleryImageImpl.(GalleryImageImpl.java:56)
at com.microsoft.azure.management.compute.implementation.GalleryImagesImpl.wrapModel(GalleryImagesImpl.java:42)
at com.microsoft.azure.management.compute.implementation.GalleryImagesImpl.access$000(GalleryImagesImpl.java:24)
at com.microsoft.azure.management.compute.implementation.GalleryImagesImpl$4.call(GalleryImagesImpl.java:84)
at com.microsoft.azure.management.compute.implementation.GalleryImagesImpl$4.call(GalleryImagesImpl.java:81)
at rx.internal.operators.OnSubscribeMap$MapSubscriber.onNext(OnSubscribeMap.java:69)
at rx.internal.operators.OnSubscribeMap$MapSubscriber.onNext(OnSubscribeMap.java:77)
at rx.internal.operators.OperatorMerge$MergeSubscriber.emitScalar(OperatorMerge.java:511)
at rx.internal.operators.OperatorMerge$MergeSubscriber.tryEmit(OperatorMerge.java:466)
at rx.internal.operators.OperatorMerge$MergeSubscriber.onNext(OperatorMerge.java:244)
at rx.internal.operators.OperatorMerge$MergeSubscriber.onNext(OperatorMerge.java:148)
at rx.internal.operators.OnSubscribeMap$MapSubscriber.onNext(OnSubscribeMap.java:77)
at retrofit2.adapter.rxjava.CallArbiter.deliverResponse(CallArbiter.java:120)
at retrofit2.adapter.rxjava.CallArbiter.emitResponse(CallArbiter.java:102)
at retrofit2.adapter.rxjava.CallExecuteOnSubscribe.call(CallExecuteOnSubscribe.java:46)
at retrofit2.adapter.rxjava.CallExecuteOnSubscribe.call(CallExecuteOnSubscribe.java:24)
at rx.Observable.unsafeSubscribe(Observable.java:10327)
at rx.internal.operators.OnSubscribeMap.call(OnSubscribeMap.java:48)
at rx.internal.operators.OnSubscribeMap.call(OnSubscribeMap.java:33)
at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48)
at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30)
at rx.Observable.unsafeSubscribe(Observable.java:10327)
at rx.internal.operators.OnSubscribeMap.call(OnSubscribeMap.java:48)
at rx.internal.operators.OnSubscribeMap.call(OnSubscribeMap.java:33)
at rx.Observable.unsafeSubscribe(Observable.java:10327)
at rx.internal.operators.OnSubscribeMap.call(OnSubscribeMap.java:48)
at rx.internal.operators.OnSubscribeMap.call(OnSubscribeMap.java:33)
at rx.Observable.unsafeSubscribe(Observable.java:10327)
at rx.internal.operators.DeferredScalarSubscriber.subscribeTo(DeferredScalarSubscriber.java:153)
at rx.internal.operators.OnSubscribeTakeLastOne.call(OnSubscribeTakeLastOne.java:32)
at rx.internal.operators.OnSubscribeTakeLastOne.call(OnSubscribeTakeLastOne.java:22)
at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48)
at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30)
at rx.Observable.subscribe(Observable.java:10423)
at rx.Observable.subscribe(Observable.java:10390)
at rx.observables.BlockingObservable.blockForSingle(BlockingObservable.java:443)
at rx.observables.BlockingObservable.last(BlockingObservable.java:226)
at com.microsoft.azure.management.compute.implementation.GalleryImagesImpl.getByGallery(GalleryImagesImpl.java:91)
at com.some.package.AzureClient.getGalleryImage(MyAzureClient.java:348)

To Reproduce
Just use the below code and ensure the gallery doesn't exist:

azure.galleries().getByResourceGroup(targetRg, galleryName);

Code Snippet
Added above.

Expected behavior
It should return null and let the consumer work with it how it does for other resource types.
For e.g. when I do the same for a public IP address, the below code will print null.

PublicIPAddress pubIp = azure.publicIPAddresses().getByResourceGroup(targetRg, "tempPip");
System.out.println("Public IP:" + pubIp);

Screenshots
N/A

Setup (please complete the following information):

  • OS: iOS
  • IDE : IntelliJ
  • 1.36

Additional Context
Btw the below code works just fine if I supply the resourceId of a Gallery or GalleryImage and prints null but isn't an ideal workaround if I want to only work with the resource group name and the resource name.

GenericResource genericResource = azure.genericResources().getById(sigResourceId);
System.out.println("Some resource:" + genericResource);

Information Checklist
Kindly make sure that you have added all the following information above and checkoff the required fields otherwise we will treat the issuer as an incomplete report

  • [x] Bug Description Added
  • [x] Repro Steps Added
  • [x] Setup information Added
Compute Mgmt bug customer-reported question

All 4 comments

Thanks for reporting this issue. Someone from the Mgmt plane SDK team will follow up shortly.

/cc @yungezz

@Shanky2304 Thanks for reporting this. I have created PR to fix this. Before it got released, you may try below code:

azure.galleries().inner().getByResourceGroup(targetRg, galleryName);

@Shanky2304 Thanks for reporting this. I have created PR to fix this. Before it got released, you may try below code:

azure.galleries().inner().getByResourceGroup(targetRg, galleryName);

Hi @xccc-msft ,
I see that your fix includes changes to GalleryImagesImpl and GalleryImageVersionsImpl, should this suggested change be applied when fetching GalleryImage and GalleryImageVersion as well?

@knspatavardhan yes

Was this page helpful?
0 / 5 - 0 ratings