From 9b1ab8ea115c88bbcecadbf53d420a09240d6ba8 Mon Sep 17 00:00:00 2001 From: Manuel Bentele Date: Thu, 25 Mar 2021 11:01:52 +0100 Subject: 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. --- src/main/java/org/openslx/libvirt/domain/Domain.java | 14 ++++++++------ 1 file 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 ); + } } } } -- cgit v1.2.3-55-g7522