Azure / Azure/azure-libraries-for-java

NPE when listing resources with an invalid subscriptionid

Abierto
#201 0 comentarios 1 reacción 1 asignado Reclamado por @anuchandy Ver en GitHub
Bug customer-reported Investigate Storage
Lenguaje dominante
Java
Estrellas
97
Forks
102
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

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}

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.