From ff7f34ae848309d7768ff7985bb38d4dde0fcda1 Mon Sep 17 00:00:00 2001 From: Liran Rotenberg Date: Mon, 13 Nov 2023 15:07:55 +0200 Subject: [PATCH] Make the OvfOvirtReader disk read more robust Some OVA files might miss one (or more) of the attributes. This might result in NullPointerException. This change will make the disk read to be more robust and prevent the exception. Signed-off-by: Liran Rotenberg --- .../java/org/ovirt/engine/core/utils/ovf/OvfOvirtReader.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ovf/OvfOvirtReader.java b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ovf/OvfOvirtReader.java index 1ca96f60ccd..bdb0285c8a3 100644 --- a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ovf/OvfOvirtReader.java +++ b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ovf/OvfOvirtReader.java @@ -260,10 +260,10 @@ public void buildDisk() { protected void readDisk(XmlNode node, DiskImage image) { super.readDisk(node, image); - if (!StringUtils.isEmpty(node.attributes.get("ovf:size").getValue())) { + if (node.attributes.get("ovf:size").getValue() != null && !StringUtils.isEmpty(node.attributes.get("ovf:size").getValue())) { image.setSize(convertGigabyteToBytes(Long.parseLong(node.attributes.get("ovf:size").getValue()))); } - if (!StringUtils.isEmpty(node.attributes.get("ovf:actual_size").getValue())) { + if (node.attributes.get("ovf:actual_size").getValue() != null && !StringUtils.isEmpty(node.attributes.get("ovf:actual_size").getValue())) { image.setActualSizeInBytes( convertGigabyteToBytes(Long.parseLong(node.attributes.get("ovf:actual_size").getValue()))); }