diff options
author | Manuel Bentele | 2021-03-25 11:01:52 +0100 |
---|---|---|
committer | Manuel Bentele | 2021-03-25 11:16:42 +0100 |
commit | 9b1ab8ea115c88bbcecadbf53d420a09240d6ba8 (patch) | |
tree | 200be1aae30f2936007a086e7a7b324e2bcf5f6b | |
parent | Add shared folder support to Libvirt domain XML documents (diff) | |
download | master-sync-shared-9b1ab8ea115c88bbcecadbf53d420a09240d6ba8.tar.gz master-sync-shared-9b1ab8ea115c88bbcecadbf53d420a09240d6ba8.tar.xz master-sync-shared-9b1ab8ea115c88bbcecadbf53d420a09240d6ba8.zip |
Fix issues related to a XPath query used in the Libvirt device lookup
The issue occurs if a Libvirt device lookup via getDevices() takes
place after a device node was removed. After the removal, a bunch of
empty XML text nodes remain which leads to problems in the underlying
XML element nodes. Those nodes are queried with the help of relative
XPath expressions which depend on valid XML element nodes.
This patch restricts queries of underlying child nodes to valid XML
element nodes avoiding the occurence of XPath runtime exceptions.
-rw-r--r-- | src/main/java/org/openslx/libvirt/domain/Domain.java | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/src/main/java/org/openslx/libvirt/domain/Domain.java b/src/main/java/org/openslx/libvirt/domain/Domain.java index f29fcd0..727da13 100644 --- a/src/main/java/org/openslx/libvirt/domain/Domain.java +++ b/src/main/java/org/openslx/libvirt/domain/Domain.java @@ -674,12 +674,14 @@ public class Domain extends LibvirtXmlDocument NodeList devicesElements = devicesNode.getChildNodes(); for ( int i = 0; i < devicesElements.getLength(); i++ ) { - LibvirtXmlNode deviceNode = null; - deviceNode = new LibvirtXmlNode( this.getRootXmlNode().getXmlDocument(), devicesElements.item( i ) ); - Device device = Device.newInstance( deviceNode ); - - if ( device != null ) { - devices.add( device ); + final Node childNode = devicesElements.item( i ); + if ( childNode.getNodeType() == Node.ELEMENT_NODE ) { + LibvirtXmlNode deviceNode = new LibvirtXmlNode( this.getRootXmlNode().getXmlDocument(), childNode ); + Device device = Device.newInstance( deviceNode ); + + if ( device != null ) { + devices.add( device ); + } } } } |