Menu

#102 NullPointerException in HostSystem.getHostDatastoreSystem

2.1
open
Steve
API (125)
2
2010-09-17
2010-09-14
Rosanna Lee
No

Exception in thread "main" java.lang.NullPointerException
at com.vmware.vim25.mo.HostSystem.getHostDatastoreSystem(HostSystem.java:259)

I have a program that enumerates the HostSystems in a datacenter, connecting to a vCenter using vi-java API. When the enumeration hits a 'disconnected' HostSystem, it gets the NullPointerException. The NPE might happen for other methods on HostSystem as well.

Using vijava2120100824.jar.

Discussion

  • Steve

    Steve - 2010-09-17

    Throwing a NPE is not good. I think you can work around this issue by checking the state of a HostSystem.

    When a HostSytem is disconnected, I can let the method return you a null. But then without checking it, you may have NPE in your code...

     
  • Steve

    Steve - 2010-09-17
    • priority: 5 --> 2