Azure / azure-libraries-for-java

Azure Management Libraries for Java
https://docs.microsoft.com/en-us/java/azure/
MIT License
94 stars 98 forks source link

[BUG] NullPointerException in VirtualMachineScaleSets list() operation #1303

Closed tsarna closed 3 years ago

tsarna commented 3 years ago

Describe the bug

trying to list Virtual Machine Scale Sets that exists results in an NPE thrown from VirtualMachineScaleSetImpl:initializeChildrenFromInner, line 195, which is the first IF statement:

    protected void initializeChildrenFromInner() {
        this.extensions = new HashMap<>();
        if (this.inner().virtualMachineProfile().extensionProfile() != null) {
            if (this.inner().virtualMachineProfile().extensionProfile().extensions() != null) {
                for (VirtualMachineScaleSetExtensionInner inner : this.inner().virtualMachineProfile().extensionProfile().extensions()) {
                    this.extensions.put(inner.name(), new VirtualMachineScaleSetExtensionImpl(inner, this));
                }
            }
        }
    }

This means either this.inner() or this.inner().virtualMachineProfile() must be null, but I can't tell which from the stack trace and I was not able to debug in situ (observed in logs from a customer).

Exception or Stack Trace

The relevant section is:

java.lang.NullPointerException
Caused by: rx.exceptions.OnErrorThrowable$OnNextValue: OnError while emitting onNext value: com.microsoft.azure.management.compute.implementation.VirtualMachineScaleSetInner.class
com.microsoft.azure.management.compute.implementation.VirtualMachineScaleSetImpl.initializeChildrenFromInner(VirtualMachineScaleSetImpl.java:195)

To Reproduce It's not clear what data the Azure API is returning to cause this, nor under what circumstances it does this. I am not able to reproduce it on any of the subscriptions I have access to, I have only observed it in a customer's log file.

Code Snippet Just calling .list() on a VirtualMachineScaleSets.

Expected behavior The list() call should be tolerant of whatever it is that the REST API is returning in this case and return a list of scale sets and not fail in this case. It would be better to return VMSS instances with missing data (say, missing the VM profile, if that's the issue) or to skip the problem instances entirely than to fail completely, as currently there is no way to work around this failure so all functionality related to scale sets must be disabled in my application.

Screenshots N/A

Setup (please complete the following information):

Additional context Add any other context about the problem here.

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

weidongxu-microsoft commented 3 years ago

@xccc-msft Please take a look.

xseeseesee commented 3 years ago

@tsarna Thanks for reporting this. I have created #1304 to fix this. Before we release new version, you may take below workaround

computeManager.virtualMachineScaleSets().inner().list();