Quantcast
Viewing all articles
Browse latest Browse all 208545

Re: node.getSnapshot() returns null

Auto-response in case somebody has the same problem: The example code is wrong:

The full code of traverseSnapshotInTree:

1    private static ManagedObjectReference traverseSnapshotInTree(List<VirtualMachineSnapshotTree> snapTree, String findName, boolean print) {

3        ManagedObjectReference snapmor = null;

4        if (snapTree == null) {

5            return snapmor;

6        }

7        for (VirtualMachineSnapshotTree node : snapTree) {

8            if (print) {

9                System.out.println("Snapshot Name : " + node.getName());

10            }

11           if (findName != null && node.getName().equalsIgnoreCase(findName)) {

12              return node.getSnapshot();

13            } else {

14                List<VirtualMachineSnapshotTree> listvmst = node.getChildSnapshotList();

15                List<VirtualMachineSnapshotTree> childTree = listvmst;

16                snapmor = traverseSnapshotInTree(childTree, findName, print);

17            }

18        }

19        return snapmor;

20    }

If your snapshots tree is as this:

  • Snapshot 1
    • Snapshot 1.1
  • Snapshot 2

and you are looking for Snapshot 1.1 you will find it at line 12 but when back at the calling level at line 7 you will go on looking for it.

As the next branch of the tree is Snapshot 2 you will not find it, and so will try to explore sub tree of Snapshot 2: This will reset snapmor to null at lines 3 + 19 in the sub level.

Correction: Enclose lines 8 to 17 with: if (snapmor != null)


Viewing all articles
Browse latest Browse all 208545

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>