Azure / Azure/azure-libraries-for-java

NPE when listing resources with an invalid subscriptionid

Đang mở
#201 0 bình luận 1 reaction 1 người được giao Được @anuchandy nhận Xem trên GitHub
Bug customer-reported Investigate Storage
Ngôn ngữ chính
Java
Star
97
Fork
102
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

Found following bug on my first test with this library (in Groovy):

`import com.microsoft.azure.AzureEnvironment
import com.microsoft.azure.credentials.ApplicationTokenCredentials
import com.microsoft.azure.management.Azure

// authentication according to: https://github.com/Azure/azure-libraries-for-java/blob/master/AUTH.md
def client = "xxxxxxxxxxxxxxx"
def tenant = "xxxxxxxxxxxxxxx"
def key = "xxxxxxxxxxxxxxx"
def subscriptionId = "xxxxxxxxxxxxxxxxxx"

ApplicationTokenCredentials credentials = new ApplicationTokenCredentials(client, tenant, key, AzureEnvironment.AZURE)
Azure azure = Azure.authenticate(credentials).withSubscription(subscriptionId)

storageAccounts = azure.storageAccounts()
accounts = storageAccounts.listByResourceGroup("RG_DTA")
accounts.each { account ->
println account.name()
}`

I accidentally used a wrong subscriptionid and got a npe:
`java.lang.NullPointerException
at com.microsoft.azure.management.storage.implementation.StorageAccountsInner$26.call(StorageAccountsInner.java:782)
at com.microsoft.azure.management.storage.implementation.StorageAccountsInner$26.call(StorageAccountsInner.java:777)
at rx.internal.operators.OnSubscribeMap$MapSubscriber.onNext(OnSubscribeMap.java:69)
at retrofit2.adapter.rxjava.RxJavaCallAdapterFactory$RequestArbiter.request(RxJavaCallAdapterFactory.java:173)
at rx.Subscriber.setProducer(Subscriber.java:211)
at rx.internal.operators.OnSubscribeMap$MapSubscriber.setProducer(OnSubscribeMap.java:102)
at retrofit2.adapter.rxjava.RxJavaCallAdapterFactory$CallOnSubscribe.call(RxJavaCallAdapterFactory.java:152)
at retrofit2.adapter.rxjava.RxJavaCallAdapterFactory$CallOnSubscribe.call(RxJavaCallAdapterFactory.java:138)
at rx.Observable.unsafeSubscribe(Observable.java:10142)
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.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48)
at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30)
at rx.Observable.subscribe(Observable.java:10238)
at rx.Observable.subscribe(Observable.java:10205)
at rx.observables.BlockingObservable.blockForSingle(BlockingObservable.java:444)
at rx.observables.BlockingObservable.single(BlockingObservable.java:341)
at com.microsoft.azure.management.storage.implementation.StorageAccountsInner.listByResourceGroup(StorageAccountsInner.java:722)
at com.microsoft.azure.management.resources.fluentcore.arm.collection.implementation.TopLevelModifiableResourcesImpl.listByResourceGroup(TopLevelModifiableResourcesImpl.java:123)
at com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsListingByResourceGroup$listByResourceGroup.call(Unknown Source)
at deploy.run(deploy.groovy:15)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)`

This line: ServiceResponse> clientResponse = new ServiceResponse>(result.body().items(), result.response()); in StorageAccountsInner should check if body is null (which it is with a wrong subscriptionid) and throw an exception with a more descriptive error. The raw response on result contains the error: Response{protocol=http/1.1, code=404, message=Not Found, url=https://management.azure.com/subscriptions/xxxxxxxxxxxxxxxx/resourceGroups/RG_xxx/providers/Microsoft.Storage/storageAccounts?api-version=2017-10-01}

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.