From 031272a5c0400dee958deeac42975b69c40b2833 Mon Sep 17 00:00:00 2001 From: Arun Venmany Date: Tue, 6 Aug 2024 20:59:44 +0530 Subject: [PATCH 01/17] adding property to xmlreader of lemminx Signed-off-by: Arun Venmany --- .../tools/langserver/lemminx/util/DocumentUtil.java | 2 ++ .../openliberty/tools/langserver/lemminx/util/XmlReader.java | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lemminx-liberty/src/main/java/io/openliberty/tools/langserver/lemminx/util/DocumentUtil.java b/lemminx-liberty/src/main/java/io/openliberty/tools/langserver/lemminx/util/DocumentUtil.java index 7a63335e..dae80f41 100644 --- a/lemminx-liberty/src/main/java/io/openliberty/tools/langserver/lemminx/util/DocumentUtil.java +++ b/lemminx-liberty/src/main/java/io/openliberty/tools/langserver/lemminx/util/DocumentUtil.java @@ -87,6 +87,8 @@ public static void writeDocToXmlFile(Document doc, File inputFile) throws Except private static TransformerFactory getTransformerFactory() throws TransformerConfigurationException { TransformerFactory transformerFactory = TransformerFactory.newInstance(); transformerFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, Boolean.TRUE); + transformerFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, ""); + transformerFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_STYLESHEET, ""); return transformerFactory; } diff --git a/lemminx-liberty/src/main/java/io/openliberty/tools/langserver/lemminx/util/XmlReader.java b/lemminx-liberty/src/main/java/io/openliberty/tools/langserver/lemminx/util/XmlReader.java index c730ab88..1f9b433d 100644 --- a/lemminx-liberty/src/main/java/io/openliberty/tools/langserver/lemminx/util/XmlReader.java +++ b/lemminx-liberty/src/main/java/io/openliberty/tools/langserver/lemminx/util/XmlReader.java @@ -86,7 +86,7 @@ public static boolean hasServerRoot(File xmlFile) { } private static XMLInputFactory getXmlInputFactory() { - XMLInputFactory factory = XMLInputFactory.newInstance(); + XMLInputFactory factory = XMLInputFactory.newFactory(); try { factory.setProperty(XMLInputFactory.IS_VALIDATING, Boolean.FALSE); factory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, Boolean.FALSE); @@ -114,7 +114,7 @@ public static Map getElementValues(Path file, Set elemen } Map returnValues = new HashMap (); - XMLInputFactory factory = XMLInputFactory.newInstance(); + XMLInputFactory factory = getXmlInputFactory(); XMLEventReader reader = null; try { reader = factory.createXMLEventReader(new FileInputStream(file.toFile())); From ccabfb674e36ec40cdc20955a294c02138d185eb Mon Sep 17 00:00:00 2001 From: Arun Venmany Date: Wed, 7 Aug 2024 09:12:17 +0530 Subject: [PATCH 02/17] using streamsource in xmleventreader of lemminx Signed-off-by: Arun Venmany --- .../tools/langserver/lemminx/util/DocumentUtil.java | 8 ++++++-- .../tools/langserver/lemminx/util/XmlReader.java | 5 +++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lemminx-liberty/src/main/java/io/openliberty/tools/langserver/lemminx/util/DocumentUtil.java b/lemminx-liberty/src/main/java/io/openliberty/tools/langserver/lemminx/util/DocumentUtil.java index dae80f41..6ef99897 100644 --- a/lemminx-liberty/src/main/java/io/openliberty/tools/langserver/lemminx/util/DocumentUtil.java +++ b/lemminx-liberty/src/main/java/io/openliberty/tools/langserver/lemminx/util/DocumentUtil.java @@ -80,8 +80,12 @@ public static void writeDocToXmlFile(Document doc, File inputFile) throws Except transformer.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC, "yes"); doc.setXmlStandalone(true); DOMSource source = new DOMSource(doc); - StreamResult file = new StreamResult(new OutputStreamWriter(new FileOutputStream(inputFile), "UTF-8")); - transformer.transform(source, file); + try { + StreamResult file = new StreamResult(new OutputStreamWriter(new FileOutputStream(inputFile), "UTF-8")); + transformer.transform(source, file); + } catch (Exception ex) { + LOGGER.warning("Received exception during post processing of schema file " + inputFile.getAbsolutePath() + " : " + ex.getMessage()); + } } private static TransformerFactory getTransformerFactory() throws TransformerConfigurationException { diff --git a/lemminx-liberty/src/main/java/io/openliberty/tools/langserver/lemminx/util/XmlReader.java b/lemminx-liberty/src/main/java/io/openliberty/tools/langserver/lemminx/util/XmlReader.java index 1f9b433d..c12809b3 100644 --- a/lemminx-liberty/src/main/java/io/openliberty/tools/langserver/lemminx/util/XmlReader.java +++ b/lemminx-liberty/src/main/java/io/openliberty/tools/langserver/lemminx/util/XmlReader.java @@ -30,6 +30,7 @@ import javax.xml.stream.XMLStreamException; import javax.xml.stream.events.Characters; import javax.xml.stream.events.XMLEvent; +import javax.xml.transform.stream.StreamSource; public class XmlReader { private static final Logger LOGGER = Logger.getLogger(XmlReader.class.getName()); @@ -61,7 +62,7 @@ public static boolean hasServerRoot(File xmlFile) { XMLEventReader reader = null; try (FileInputStream fis = new FileInputStream(xmlFile)) { - reader = factory.createXMLEventReader(fis); + reader = factory.createXMLEventReader(new StreamSource(fis)); while (reader.hasNext()) { XMLEvent nextEvent = reader.nextEvent(); if (nextEvent.isStartElement()) { @@ -117,7 +118,7 @@ public static Map getElementValues(Path file, Set elemen XMLInputFactory factory = getXmlInputFactory(); XMLEventReader reader = null; try { - reader = factory.createXMLEventReader(new FileInputStream(file.toFile())); + reader = factory.createXMLEventReader(new StreamSource(new FileInputStream(file.toFile()))); while (reader.hasNext()) { XMLEvent event = reader.nextEvent(); if (!event.isStartElement()) { From a94282bd1e85f0180986d58a2d48efc4d890dd10 Mon Sep 17 00:00:00 2001 From: Arun Venmany Date: Wed, 7 Aug 2024 09:34:48 +0530 Subject: [PATCH 03/17] using access extenal dtd property as not allowed in xmleventreader of lemminx Signed-off-by: Arun Venmany --- .../langserver/lemminx/util/XmlReader.java | 45 ++++++++++--------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/lemminx-liberty/src/main/java/io/openliberty/tools/langserver/lemminx/util/XmlReader.java b/lemminx-liberty/src/main/java/io/openliberty/tools/langserver/lemminx/util/XmlReader.java index c12809b3..5e0ad64d 100644 --- a/lemminx-liberty/src/main/java/io/openliberty/tools/langserver/lemminx/util/XmlReader.java +++ b/lemminx-liberty/src/main/java/io/openliberty/tools/langserver/lemminx/util/XmlReader.java @@ -1,15 +1,15 @@ /******************************************************************************* -* Copyright (c) 2023, 2024 IBM Corporation and others. -* -* This program and the accompanying materials are made available under the -* terms of the Eclipse Public License v. 2.0 which is available at -* http://www.eclipse.org/legal/epl-2.0. -* -* SPDX-License-Identifier: EPL-2.0 -* -* Contributors: -* IBM Corporation - initial API and implementation -*******************************************************************************/ + * Copyright (c) 2023, 2024 IBM Corporation and others. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ package io.openliberty.tools.langserver.lemminx.util; @@ -25,19 +25,19 @@ import java.util.Set; import java.util.logging.Logger; +import javax.xml.XMLConstants; import javax.xml.stream.XMLEventReader; import javax.xml.stream.XMLInputFactory; import javax.xml.stream.XMLStreamException; import javax.xml.stream.events.Characters; import javax.xml.stream.events.XMLEvent; -import javax.xml.transform.stream.StreamSource; public class XmlReader { private static final Logger LOGGER = Logger.getLogger(XmlReader.class.getName()); public static boolean hasServerRoot(String filePath) { File file = null; - + try { file = new File(new URI(filePath).getPath()); return hasServerRoot(file); @@ -55,14 +55,14 @@ public static boolean hasServerRoot(File xmlFile) { if (!xmlFile.exists() || xmlFile.length() == 0) { return false; } - + try { XMLInputFactory factory = getXmlInputFactory(); XMLEventReader reader = null; try (FileInputStream fis = new FileInputStream(xmlFile)) { - reader = factory.createXMLEventReader(new StreamSource(fis)); + reader = factory.createXMLEventReader(fis); while (reader.hasNext()) { XMLEvent nextEvent = reader.nextEvent(); if (nextEvent.isStartElement()) { @@ -70,15 +70,15 @@ public static boolean hasServerRoot(File xmlFile) { } } } catch (XMLStreamException | FileNotFoundException e) { - LOGGER.severe("Error received trying to read XML file: " + xmlFile.getAbsolutePath()); + LOGGER.severe("Error received trying to read XML file: " + xmlFile.getAbsolutePath()); } finally { if (reader != null) { try { reader.close(); - } catch (Exception ignored) { + } catch (Exception ignored) { } } - } + } } catch (Exception e) { LOGGER.severe("Unable to access XML file "+ xmlFile.getAbsolutePath()); } @@ -87,12 +87,13 @@ public static boolean hasServerRoot(File xmlFile) { } private static XMLInputFactory getXmlInputFactory() { - XMLInputFactory factory = XMLInputFactory.newFactory(); + XMLInputFactory factory = XMLInputFactory.newInstance(); try { factory.setProperty(XMLInputFactory.IS_VALIDATING, Boolean.FALSE); factory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, Boolean.FALSE); factory.setProperty(XMLInputFactory.SUPPORT_DTD, Boolean.FALSE); factory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, Boolean.FALSE); + factory.setProperty(XMLConstants.ACCESS_EXTERNAL_DTD,""); } catch (Exception e) { LOGGER.warning("Could not set properties on XMLInputFactory."); } @@ -118,7 +119,7 @@ public static Map getElementValues(Path file, Set elemen XMLInputFactory factory = getXmlInputFactory(); XMLEventReader reader = null; try { - reader = factory.createXMLEventReader(new StreamSource(new FileInputStream(file.toFile()))); + reader = factory.createXMLEventReader(new FileInputStream(file.toFile())); while (reader.hasNext()) { XMLEvent event = reader.nextEvent(); if (!event.isStartElement()) { @@ -132,7 +133,7 @@ public static Map getElementValues(Path file, Set elemen returnValues.put(elementName, value.getData()); } } - } + } } catch (FileNotFoundException e) { LOGGER.severe("Unable to access file "+ file.toFile().getName()); } catch (XMLStreamException e) { @@ -141,7 +142,7 @@ public static Map getElementValues(Path file, Set elemen if (reader != null) { try { reader.close(); - } catch (Exception ignored) { + } catch (Exception ignored) { } } } From 103116d46c85d516aef70f2786c000e6d78107f6 Mon Sep 17 00:00:00 2001 From: Arun Venmany Date: Tue, 6 Aug 2024 18:08:00 +0530 Subject: [PATCH 04/17] adding property to xmlreader of lemminx Signed-off-by: Arun Venmany --- .../langserver/lemminx/util/XmlReader.java | 40 +++++++++---------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/lemminx-liberty/src/main/java/io/openliberty/tools/langserver/lemminx/util/XmlReader.java b/lemminx-liberty/src/main/java/io/openliberty/tools/langserver/lemminx/util/XmlReader.java index 5e0ad64d..c730ab88 100644 --- a/lemminx-liberty/src/main/java/io/openliberty/tools/langserver/lemminx/util/XmlReader.java +++ b/lemminx-liberty/src/main/java/io/openliberty/tools/langserver/lemminx/util/XmlReader.java @@ -1,15 +1,15 @@ /******************************************************************************* - * Copyright (c) 2023, 2024 IBM Corporation and others. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ +* Copyright (c) 2023, 2024 IBM Corporation and others. +* +* This program and the accompanying materials are made available under the +* terms of the Eclipse Public License v. 2.0 which is available at +* http://www.eclipse.org/legal/epl-2.0. +* +* SPDX-License-Identifier: EPL-2.0 +* +* Contributors: +* IBM Corporation - initial API and implementation +*******************************************************************************/ package io.openliberty.tools.langserver.lemminx.util; @@ -25,7 +25,6 @@ import java.util.Set; import java.util.logging.Logger; -import javax.xml.XMLConstants; import javax.xml.stream.XMLEventReader; import javax.xml.stream.XMLInputFactory; import javax.xml.stream.XMLStreamException; @@ -37,7 +36,7 @@ public class XmlReader { public static boolean hasServerRoot(String filePath) { File file = null; - + try { file = new File(new URI(filePath).getPath()); return hasServerRoot(file); @@ -55,7 +54,7 @@ public static boolean hasServerRoot(File xmlFile) { if (!xmlFile.exists() || xmlFile.length() == 0) { return false; } - + try { XMLInputFactory factory = getXmlInputFactory(); @@ -70,15 +69,15 @@ public static boolean hasServerRoot(File xmlFile) { } } } catch (XMLStreamException | FileNotFoundException e) { - LOGGER.severe("Error received trying to read XML file: " + xmlFile.getAbsolutePath()); + LOGGER.severe("Error received trying to read XML file: " + xmlFile.getAbsolutePath()); } finally { if (reader != null) { try { reader.close(); - } catch (Exception ignored) { + } catch (Exception ignored) { } } - } + } } catch (Exception e) { LOGGER.severe("Unable to access XML file "+ xmlFile.getAbsolutePath()); } @@ -93,7 +92,6 @@ private static XMLInputFactory getXmlInputFactory() { factory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, Boolean.FALSE); factory.setProperty(XMLInputFactory.SUPPORT_DTD, Boolean.FALSE); factory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, Boolean.FALSE); - factory.setProperty(XMLConstants.ACCESS_EXTERNAL_DTD,""); } catch (Exception e) { LOGGER.warning("Could not set properties on XMLInputFactory."); } @@ -116,7 +114,7 @@ public static Map getElementValues(Path file, Set elemen } Map returnValues = new HashMap (); - XMLInputFactory factory = getXmlInputFactory(); + XMLInputFactory factory = XMLInputFactory.newInstance(); XMLEventReader reader = null; try { reader = factory.createXMLEventReader(new FileInputStream(file.toFile())); @@ -133,7 +131,7 @@ public static Map getElementValues(Path file, Set elemen returnValues.put(elementName, value.getData()); } } - } + } } catch (FileNotFoundException e) { LOGGER.severe("Unable to access file "+ file.toFile().getName()); } catch (XMLStreamException e) { @@ -142,7 +140,7 @@ public static Map getElementValues(Path file, Set elemen if (reader != null) { try { reader.close(); - } catch (Exception ignored) { + } catch (Exception ignored) { } } } From a42af181532d497583767a07ace4ef8c46f0a05e Mon Sep 17 00:00:00 2001 From: Arun Venmany Date: Wed, 7 Aug 2024 09:46:03 +0530 Subject: [PATCH 05/17] using access extenal dtd property as not allowed in xmleventreader of lemminx Signed-off-by: Arun Venmany --- .../openliberty/tools/langserver/lemminx/util/XmlReader.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lemminx-liberty/src/main/java/io/openliberty/tools/langserver/lemminx/util/XmlReader.java b/lemminx-liberty/src/main/java/io/openliberty/tools/langserver/lemminx/util/XmlReader.java index c730ab88..138bcefe 100644 --- a/lemminx-liberty/src/main/java/io/openliberty/tools/langserver/lemminx/util/XmlReader.java +++ b/lemminx-liberty/src/main/java/io/openliberty/tools/langserver/lemminx/util/XmlReader.java @@ -25,6 +25,7 @@ import java.util.Set; import java.util.logging.Logger; +import javax.xml.XMLConstants; import javax.xml.stream.XMLEventReader; import javax.xml.stream.XMLInputFactory; import javax.xml.stream.XMLStreamException; @@ -92,6 +93,7 @@ private static XMLInputFactory getXmlInputFactory() { factory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, Boolean.FALSE); factory.setProperty(XMLInputFactory.SUPPORT_DTD, Boolean.FALSE); factory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, Boolean.FALSE); + factory.setProperty(XMLConstants.ACCESS_EXTERNAL_DTD, ""); } catch (Exception e) { LOGGER.warning("Could not set properties on XMLInputFactory."); } @@ -114,7 +116,7 @@ public static Map getElementValues(Path file, Set elemen } Map returnValues = new HashMap (); - XMLInputFactory factory = XMLInputFactory.newInstance(); + XMLInputFactory factory = getXmlInputFactory(); XMLEventReader reader = null; try { reader = factory.createXMLEventReader(new FileInputStream(file.toFile())); From 8da183da4cb915b661e33df5c0799e6649fc43d4 Mon Sep 17 00:00:00 2001 From: Arun Venmany Date: Wed, 7 Aug 2024 09:55:59 +0530 Subject: [PATCH 06/17] using access extenal dtd property as not allowed in xmleventreader of lemminx Signed-off-by: Arun Venmany --- .../tools/langserver/lemminx/util/XmlReader.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lemminx-liberty/src/main/java/io/openliberty/tools/langserver/lemminx/util/XmlReader.java b/lemminx-liberty/src/main/java/io/openliberty/tools/langserver/lemminx/util/XmlReader.java index 138bcefe..f6748578 100644 --- a/lemminx-liberty/src/main/java/io/openliberty/tools/langserver/lemminx/util/XmlReader.java +++ b/lemminx-liberty/src/main/java/io/openliberty/tools/langserver/lemminx/util/XmlReader.java @@ -31,6 +31,7 @@ import javax.xml.stream.XMLStreamException; import javax.xml.stream.events.Characters; import javax.xml.stream.events.XMLEvent; +import javax.xml.transform.stream.StreamSource; public class XmlReader { private static final Logger LOGGER = Logger.getLogger(XmlReader.class.getName()); @@ -87,7 +88,7 @@ public static boolean hasServerRoot(File xmlFile) { } private static XMLInputFactory getXmlInputFactory() { - XMLInputFactory factory = XMLInputFactory.newInstance(); + XMLInputFactory factory = XMLInputFactory.newFactory(); try { factory.setProperty(XMLInputFactory.IS_VALIDATING, Boolean.FALSE); factory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, Boolean.FALSE); @@ -119,7 +120,7 @@ public static Map getElementValues(Path file, Set elemen XMLInputFactory factory = getXmlInputFactory(); XMLEventReader reader = null; try { - reader = factory.createXMLEventReader(new FileInputStream(file.toFile())); + reader = factory.createXMLEventReader(new StreamSource(file.toFile())); while (reader.hasNext()) { XMLEvent event = reader.nextEvent(); if (!event.isStartElement()) { @@ -134,9 +135,7 @@ public static Map getElementValues(Path file, Set elemen } } } - } catch (FileNotFoundException e) { - LOGGER.severe("Unable to access file "+ file.toFile().getName()); - } catch (XMLStreamException e) { + } catch (XMLStreamException e) { LOGGER.severe("Error received trying to read XML file " + file.toFile().getName() + " : "+e.getMessage()); } finally { if (reader != null) { From 7af3dec7671f1b3170a54163e8fba6281729e73f Mon Sep 17 00:00:00 2001 From: Arun Venmany Date: Wed, 7 Aug 2024 10:24:53 +0530 Subject: [PATCH 07/17] using access extenal schema property Signed-off-by: Arun Venmany --- .../tools/langserver/lemminx/util/XmlReader.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lemminx-liberty/src/main/java/io/openliberty/tools/langserver/lemminx/util/XmlReader.java b/lemminx-liberty/src/main/java/io/openliberty/tools/langserver/lemminx/util/XmlReader.java index f6748578..d770d2a5 100644 --- a/lemminx-liberty/src/main/java/io/openliberty/tools/langserver/lemminx/util/XmlReader.java +++ b/lemminx-liberty/src/main/java/io/openliberty/tools/langserver/lemminx/util/XmlReader.java @@ -63,7 +63,7 @@ public static boolean hasServerRoot(File xmlFile) { XMLEventReader reader = null; try (FileInputStream fis = new FileInputStream(xmlFile)) { - reader = factory.createXMLEventReader(fis); + reader = factory.createXMLEventReader(new StreamSource(fis)); while (reader.hasNext()) { XMLEvent nextEvent = reader.nextEvent(); if (nextEvent.isStartElement()) { @@ -88,13 +88,14 @@ public static boolean hasServerRoot(File xmlFile) { } private static XMLInputFactory getXmlInputFactory() { - XMLInputFactory factory = XMLInputFactory.newFactory(); + XMLInputFactory factory = XMLInputFactory.newInstance(); try { factory.setProperty(XMLInputFactory.IS_VALIDATING, Boolean.FALSE); factory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, Boolean.FALSE); factory.setProperty(XMLInputFactory.SUPPORT_DTD, Boolean.FALSE); factory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, Boolean.FALSE); factory.setProperty(XMLConstants.ACCESS_EXTERNAL_DTD, ""); + factory.setProperty(XMLConstants.ACCESS_EXTERNAL_SCHEMA, ""); } catch (Exception e) { LOGGER.warning("Could not set properties on XMLInputFactory."); } @@ -120,7 +121,8 @@ public static Map getElementValues(Path file, Set elemen XMLInputFactory factory = getXmlInputFactory(); XMLEventReader reader = null; try { - reader = factory.createXMLEventReader(new StreamSource(file.toFile())); + reader = factory.createXMLEventReader(new StreamSource(new FileInputStream(file.toFile()))); + while (reader.hasNext()) { XMLEvent event = reader.nextEvent(); if (!event.isStartElement()) { @@ -135,7 +137,9 @@ public static Map getElementValues(Path file, Set elemen } } } - } catch (XMLStreamException e) { + } catch (FileNotFoundException e) { + LOGGER.severe("Unable to access file "+ file.toFile().getName()); + } catch (XMLStreamException e) { LOGGER.severe("Error received trying to read XML file " + file.toFile().getName() + " : "+e.getMessage()); } finally { if (reader != null) { From 4f5fcb89dec8ee6a84b0f5c1327036030d0238e3 Mon Sep 17 00:00:00 2001 From: Arun Venmany Date: Wed, 7 Aug 2024 12:09:54 +0530 Subject: [PATCH 08/17] reader moved to private method Signed-off-by: Arun Venmany --- .../langserver/lemminx/util/XmlReader.java | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/lemminx-liberty/src/main/java/io/openliberty/tools/langserver/lemminx/util/XmlReader.java b/lemminx-liberty/src/main/java/io/openliberty/tools/langserver/lemminx/util/XmlReader.java index d770d2a5..095c8d38 100644 --- a/lemminx-liberty/src/main/java/io/openliberty/tools/langserver/lemminx/util/XmlReader.java +++ b/lemminx-liberty/src/main/java/io/openliberty/tools/langserver/lemminx/util/XmlReader.java @@ -31,7 +31,6 @@ import javax.xml.stream.XMLStreamException; import javax.xml.stream.events.Characters; import javax.xml.stream.events.XMLEvent; -import javax.xml.transform.stream.StreamSource; public class XmlReader { private static final Logger LOGGER = Logger.getLogger(XmlReader.class.getName()); @@ -63,7 +62,7 @@ public static boolean hasServerRoot(File xmlFile) { XMLEventReader reader = null; try (FileInputStream fis = new FileInputStream(xmlFile)) { - reader = factory.createXMLEventReader(new StreamSource(fis)); + reader = factory.createXMLEventReader(fis); while (reader.hasNext()) { XMLEvent nextEvent = reader.nextEvent(); if (nextEvent.isStartElement()) { @@ -96,6 +95,7 @@ private static XMLInputFactory getXmlInputFactory() { factory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, Boolean.FALSE); factory.setProperty(XMLConstants.ACCESS_EXTERNAL_DTD, ""); factory.setProperty(XMLConstants.ACCESS_EXTERNAL_SCHEMA, ""); + factory.setProperty("http://java.sun.com/xml/stream/properties/ignore-external-dtd",Boolean.TRUE); } catch (Exception e) { LOGGER.warning("Could not set properties on XMLInputFactory."); } @@ -119,9 +119,15 @@ public static Map getElementValues(Path file, Set elemen Map returnValues = new HashMap (); XMLInputFactory factory = getXmlInputFactory(); + readElementValues(file, elementNames, factory, returnValues); + + return returnValues; + } + + private static void readElementValues(Path file, Set elementNames, XMLInputFactory factory, Map returnValues) { XMLEventReader reader = null; try { - reader = factory.createXMLEventReader(new StreamSource(new FileInputStream(file.toFile()))); + reader = factory.createXMLEventReader(new FileInputStream(file.toFile())); while (reader.hasNext()) { XMLEvent event = reader.nextEvent(); @@ -136,7 +142,7 @@ public static Map getElementValues(Path file, Set elemen returnValues.put(elementName, value.getData()); } } - } + } } catch (FileNotFoundException e) { LOGGER.severe("Unable to access file "+ file.toFile().getName()); } catch (XMLStreamException e) { @@ -145,12 +151,10 @@ public static Map getElementValues(Path file, Set elemen if (reader != null) { try { reader.close(); - } catch (Exception ignored) { + } catch (Exception ignored) { } } } - - return returnValues; } protected static String getElementName(XMLEvent event) { From e4d37750e8ca14654833e7dba7dce5fd8ffbc9cd Mon Sep 17 00:00:00 2001 From: Arun Venmany Date: Wed, 7 Aug 2024 12:14:56 +0530 Subject: [PATCH 09/17] reader moved to private method Signed-off-by: Arun Venmany --- .../io/openliberty/tools/langserver/lemminx/util/XmlReader.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lemminx-liberty/src/main/java/io/openliberty/tools/langserver/lemminx/util/XmlReader.java b/lemminx-liberty/src/main/java/io/openliberty/tools/langserver/lemminx/util/XmlReader.java index 095c8d38..14aa03c9 100644 --- a/lemminx-liberty/src/main/java/io/openliberty/tools/langserver/lemminx/util/XmlReader.java +++ b/lemminx-liberty/src/main/java/io/openliberty/tools/langserver/lemminx/util/XmlReader.java @@ -51,7 +51,7 @@ public static boolean hasServerRoot(Path filePath) { return hasServerRoot(filePath.toFile()); } - public static boolean hasServerRoot(File xmlFile) { + private static boolean hasServerRoot(File xmlFile) { if (!xmlFile.exists() || xmlFile.length() == 0) { return false; } From aeb91b7117e4dec1aa25f9db1474a03e8427ca6f Mon Sep 17 00:00:00 2001 From: Arun Venmany Date: Wed, 7 Aug 2024 12:36:42 +0530 Subject: [PATCH 10/17] reader moved to private method Signed-off-by: Arun Venmany --- .../langserver/lemminx/util/XmlReader.java | 17 +++++++++++------ .../tools/langserver/utils/XmlReader.java | 17 +++++++++++------ 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/lemminx-liberty/src/main/java/io/openliberty/tools/langserver/lemminx/util/XmlReader.java b/lemminx-liberty/src/main/java/io/openliberty/tools/langserver/lemminx/util/XmlReader.java index 14aa03c9..f64e26cc 100644 --- a/lemminx-liberty/src/main/java/io/openliberty/tools/langserver/lemminx/util/XmlReader.java +++ b/lemminx-liberty/src/main/java/io/openliberty/tools/langserver/lemminx/util/XmlReader.java @@ -61,8 +61,8 @@ private static boolean hasServerRoot(File xmlFile) { XMLEventReader reader = null; - try (FileInputStream fis = new FileInputStream(xmlFile)) { - reader = factory.createXMLEventReader(fis); + try { + reader = getReader(factory, xmlFile); while (reader.hasNext()) { XMLEvent nextEvent = reader.nextEvent(); if (nextEvent.isStartElement()) { @@ -70,15 +70,15 @@ private static boolean hasServerRoot(File xmlFile) { } } } catch (XMLStreamException | FileNotFoundException e) { - LOGGER.severe("Error received trying to read XML file: " + xmlFile.getAbsolutePath()); + LOGGER.severe("Error received trying to read XML file: " + xmlFile.getAbsolutePath()); } finally { if (reader != null) { try { reader.close(); - } catch (Exception ignored) { + } catch (Exception ignored) { } } - } + } } catch (Exception e) { LOGGER.severe("Unable to access XML file "+ xmlFile.getAbsolutePath()); } @@ -86,6 +86,12 @@ private static boolean hasServerRoot(File xmlFile) { return false; } + private static XMLEventReader getReader(XMLInputFactory factory, File xmlFile) + throws FileNotFoundException, XMLStreamException { + FileInputStream fis = new FileInputStream(xmlFile); + return factory.createXMLEventReader(fis); + } + private static XMLInputFactory getXmlInputFactory() { XMLInputFactory factory = XMLInputFactory.newInstance(); try { @@ -95,7 +101,6 @@ private static XMLInputFactory getXmlInputFactory() { factory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, Boolean.FALSE); factory.setProperty(XMLConstants.ACCESS_EXTERNAL_DTD, ""); factory.setProperty(XMLConstants.ACCESS_EXTERNAL_SCHEMA, ""); - factory.setProperty("http://java.sun.com/xml/stream/properties/ignore-external-dtd",Boolean.TRUE); } catch (Exception e) { LOGGER.warning("Could not set properties on XMLInputFactory."); } diff --git a/liberty-ls/src/main/java/io/openliberty/tools/langserver/utils/XmlReader.java b/liberty-ls/src/main/java/io/openliberty/tools/langserver/utils/XmlReader.java index 16f3010a..e3fc8ceb 100644 --- a/liberty-ls/src/main/java/io/openliberty/tools/langserver/utils/XmlReader.java +++ b/liberty-ls/src/main/java/io/openliberty/tools/langserver/utils/XmlReader.java @@ -54,6 +54,12 @@ public static Map getElementValues(File file, Set elemen return returnValues; } + readElementValues(file, elementNames, returnValues); + + return returnValues; + } + + private static void readElementValues(File file, Set elementNames, Map returnValues) { XMLInputFactory factory = getXmlInputFactory(); XMLEventReader reader = null; try { @@ -74,21 +80,19 @@ public static Map getElementValues(File file, Set elemen } } } catch (XMLStreamException | FileNotFoundException e) { - LOGGER.severe("Error received trying to read XML file: " + file.getName() + + LOGGER.severe("Error received trying to read XML file: " + file.getName() + "\n\tError" + e.getMessage()); } finally { if (reader != null) { try { reader.close(); - } catch (Exception ignored) { + } catch (Exception ignored) { } } - } + } } catch (Exception e) { LOGGER.severe("Unable to access XML file "+ file.getAbsolutePath()); } - - return returnValues; } private static XMLInputFactory getXmlInputFactory() { @@ -98,7 +102,8 @@ private static XMLInputFactory getXmlInputFactory() { factory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, Boolean.FALSE); factory.setProperty(XMLInputFactory.SUPPORT_DTD, Boolean.FALSE); factory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, Boolean.FALSE); - + factory.setProperty(XMLConstants.ACCESS_EXTERNAL_DTD, ""); + factory.setProperty(XMLConstants.ACCESS_EXTERNAL_SCHEMA, ""); } catch (Exception e) { LOGGER.warning("Could not set properties on XMLInputFactory."); } From f1892029930456478d6e1fdf846fd47731163b90 Mon Sep 17 00:00:00 2001 From: Arun Venmany Date: Wed, 7 Aug 2024 12:51:23 +0530 Subject: [PATCH 11/17] reader moved to private Signed-off-by: Arun Venmany --- .../langserver/lemminx/util/XmlReader.java | 50 +++++++++---------- 1 file changed, 24 insertions(+), 26 deletions(-) diff --git a/lemminx-liberty/src/main/java/io/openliberty/tools/langserver/lemminx/util/XmlReader.java b/lemminx-liberty/src/main/java/io/openliberty/tools/langserver/lemminx/util/XmlReader.java index f64e26cc..8cca69b2 100644 --- a/lemminx-liberty/src/main/java/io/openliberty/tools/langserver/lemminx/util/XmlReader.java +++ b/lemminx-liberty/src/main/java/io/openliberty/tools/langserver/lemminx/util/XmlReader.java @@ -58,27 +58,7 @@ private static boolean hasServerRoot(File xmlFile) { try { XMLInputFactory factory = getXmlInputFactory(); - - XMLEventReader reader = null; - - try { - reader = getReader(factory, xmlFile); - while (reader.hasNext()) { - XMLEvent nextEvent = reader.nextEvent(); - if (nextEvent.isStartElement()) { - return isServerElement(nextEvent); - } - } - } catch (XMLStreamException | FileNotFoundException e) { - LOGGER.severe("Error received trying to read XML file: " + xmlFile.getAbsolutePath()); - } finally { - if (reader != null) { - try { - reader.close(); - } catch (Exception ignored) { - } - } - } + return hasSeverRootValues(factory,xmlFile); } catch (Exception e) { LOGGER.severe("Unable to access XML file "+ xmlFile.getAbsolutePath()); } @@ -86,10 +66,29 @@ private static boolean hasServerRoot(File xmlFile) { return false; } - private static XMLEventReader getReader(XMLInputFactory factory, File xmlFile) - throws FileNotFoundException, XMLStreamException { - FileInputStream fis = new FileInputStream(xmlFile); - return factory.createXMLEventReader(fis); + private static boolean hasSeverRootValues(XMLInputFactory factory, File xmlFile) { + XMLEventReader reader=null; + try { + FileInputStream fis = new FileInputStream(xmlFile); + + reader = factory.createXMLEventReader(fis); + while (reader.hasNext()) { + XMLEvent nextEvent = reader.nextEvent(); + if (nextEvent.isStartElement()) { + return isServerElement(nextEvent); + } + } + } catch (XMLStreamException | FileNotFoundException e) { + LOGGER.severe("Error received trying to read XML file: " + xmlFile.getAbsolutePath()); + } finally { + if (reader != null) { + try { + reader.close(); + } catch (Exception ignored) { + } + } + } + return false; } private static XMLInputFactory getXmlInputFactory() { @@ -125,7 +124,6 @@ public static Map getElementValues(Path file, Set elemen XMLInputFactory factory = getXmlInputFactory(); readElementValues(file, elementNames, factory, returnValues); - return returnValues; } From 7c7ffc8fd5cd53fcbdfa2b8d514e3a82cef67bbf Mon Sep 17 00:00:00 2001 From: Arun Venmany Date: Wed, 7 Aug 2024 12:59:54 +0530 Subject: [PATCH 12/17] removing try with resources Signed-off-by: Arun Venmany --- .../java/io/openliberty/tools/langserver/utils/XmlReader.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/liberty-ls/src/main/java/io/openliberty/tools/langserver/utils/XmlReader.java b/liberty-ls/src/main/java/io/openliberty/tools/langserver/utils/XmlReader.java index e3fc8ceb..d9bd7898 100644 --- a/liberty-ls/src/main/java/io/openliberty/tools/langserver/utils/XmlReader.java +++ b/liberty-ls/src/main/java/io/openliberty/tools/langserver/utils/XmlReader.java @@ -63,7 +63,8 @@ private static void readElementValues(File file, Set elementNames, Map Date: Wed, 7 Aug 2024 13:04:52 +0530 Subject: [PATCH 13/17] moving readelementvalues reader to private method Signed-off-by: Arun Venmany --- .../tools/langserver/utils/XmlReader.java | 56 ++++++++++--------- 1 file changed, 30 insertions(+), 26 deletions(-) diff --git a/liberty-ls/src/main/java/io/openliberty/tools/langserver/utils/XmlReader.java b/liberty-ls/src/main/java/io/openliberty/tools/langserver/utils/XmlReader.java index d9bd7898..26c70d8e 100644 --- a/liberty-ls/src/main/java/io/openliberty/tools/langserver/utils/XmlReader.java +++ b/liberty-ls/src/main/java/io/openliberty/tools/langserver/utils/XmlReader.java @@ -63,36 +63,40 @@ private static void readElementValues(File file, Set elementNames, Map elementNames, Map returnValues, XMLEventReader reader, XMLInputFactory factory) { + try { + FileInputStream fis = new FileInputStream(file); + reader = factory.createXMLEventReader(fis); + while (reader.hasNext()) { + XMLEvent nextEvent = reader.nextEvent(); + if (!nextEvent.isStartElement()) { + continue; } - } catch (XMLStreamException | FileNotFoundException e) { - LOGGER.severe("Error received trying to read XML file: " + file.getName() + - "\n\tError" + e.getMessage()); - } finally { - if (reader != null) { - try { - reader.close(); - } catch (Exception ignored) { + String elementName = getElementName(nextEvent); + if (elementNames.contains(elementName) && reader.hasNext()) { + XMLEvent elementContent = reader.nextEvent(); + if (elementContent.isCharacters()) { + Characters value = elementContent.asCharacters(); + returnValues.put(elementName, value.getData()); } } } - } catch (Exception e) { - LOGGER.severe("Unable to access XML file "+ file.getAbsolutePath()); + } catch (XMLStreamException | FileNotFoundException e) { + LOGGER.severe("Error received trying to read XML file: " + file.getName() + + "\n\tError" + e.getMessage()); + } finally { + if (reader != null) { + try { + reader.close(); + } catch (Exception ignored) { + } + } } } From 399e9445aaa2ce0efb9d62d7973f12269b17abec Mon Sep 17 00:00:00 2001 From: Arun Venmany Date: Wed, 7 Aug 2024 13:06:13 +0530 Subject: [PATCH 14/17] moving readelementvalues reader to private method Signed-off-by: Arun Venmany --- .../java/io/openliberty/tools/langserver/utils/XmlReader.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/liberty-ls/src/main/java/io/openliberty/tools/langserver/utils/XmlReader.java b/liberty-ls/src/main/java/io/openliberty/tools/langserver/utils/XmlReader.java index 26c70d8e..1b935956 100644 --- a/liberty-ls/src/main/java/io/openliberty/tools/langserver/utils/XmlReader.java +++ b/liberty-ls/src/main/java/io/openliberty/tools/langserver/utils/XmlReader.java @@ -63,13 +63,13 @@ private static void readElementValues(File file, Set elementNames, Map elementNames, Map returnValues, XMLEventReader reader, XMLInputFactory factory) { + private static void readElements(File file, Set elementNames, Map returnValues, XMLEventReader reader, XMLInputFactory factory) { try { FileInputStream fis = new FileInputStream(file); reader = factory.createXMLEventReader(fis); From 5a7a5857ebddd19a5696c0cc8ebe0bfd9c91dc0a Mon Sep 17 00:00:00 2001 From: Arun Venmany Date: Wed, 7 Aug 2024 13:07:19 +0530 Subject: [PATCH 15/17] moving readelementvalues reader to private method Signed-off-by: Arun Venmany --- .../io/openliberty/tools/langserver/utils/XmlReader.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/liberty-ls/src/main/java/io/openliberty/tools/langserver/utils/XmlReader.java b/liberty-ls/src/main/java/io/openliberty/tools/langserver/utils/XmlReader.java index 1b935956..ac9a6386 100644 --- a/liberty-ls/src/main/java/io/openliberty/tools/langserver/utils/XmlReader.java +++ b/liberty-ls/src/main/java/io/openliberty/tools/langserver/utils/XmlReader.java @@ -61,15 +61,15 @@ public static Map getElementValues(File file, Set elemen private static void readElementValues(File file, Set elementNames, Map returnValues) { XMLInputFactory factory = getXmlInputFactory(); - XMLEventReader reader = null; try { - readElements(file, elementNames, returnValues, reader, factory); + readElements(file, elementNames, returnValues, factory); } catch (Exception e) { LOGGER.severe("Unable to access XML file "+ file.getAbsolutePath()); } } - private static void readElements(File file, Set elementNames, Map returnValues, XMLEventReader reader, XMLInputFactory factory) { + private static void readElements(File file, Set elementNames, Map returnValues, XMLInputFactory factory) { + XMLEventReader reader = null; try { FileInputStream fis = new FileInputStream(file); reader = factory.createXMLEventReader(fis); From cffbe8d09cb08b657d0b4916e6036081cd292c83 Mon Sep 17 00:00:00 2001 From: Arun Venmany Date: Wed, 7 Aug 2024 19:04:54 +0530 Subject: [PATCH 16/17] incorparating review comments Signed-off-by: Arun Venmany --- .../tools/langserver/lemminx/util/DocumentUtil.java | 2 ++ .../tools/langserver/lemminx/util/XmlReader.java | 11 ++++++++++- .../openliberty/tools/langserver/utils/XmlReader.java | 11 ++++++++++- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/lemminx-liberty/src/main/java/io/openliberty/tools/langserver/lemminx/util/DocumentUtil.java b/lemminx-liberty/src/main/java/io/openliberty/tools/langserver/lemminx/util/DocumentUtil.java index 6ef99897..374c0938 100644 --- a/lemminx-liberty/src/main/java/io/openliberty/tools/langserver/lemminx/util/DocumentUtil.java +++ b/lemminx-liberty/src/main/java/io/openliberty/tools/langserver/lemminx/util/DocumentUtil.java @@ -91,7 +91,9 @@ public static void writeDocToXmlFile(Document doc, File inputFile) throws Except private static TransformerFactory getTransformerFactory() throws TransformerConfigurationException { TransformerFactory transformerFactory = TransformerFactory.newInstance(); transformerFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, Boolean.TRUE); + // XMLConstants.ACCESS_EXTERNAL_DTD uses an empty string to deny all access to external references; transformerFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, ""); + // XMLConstants.ACCESS_EXTERNAL_STYLESHEET uses an empty string to deny all access to external references; transformerFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_STYLESHEET, ""); return transformerFactory; } diff --git a/lemminx-liberty/src/main/java/io/openliberty/tools/langserver/lemminx/util/XmlReader.java b/lemminx-liberty/src/main/java/io/openliberty/tools/langserver/lemminx/util/XmlReader.java index 8cca69b2..f8d6eeaa 100644 --- a/lemminx-liberty/src/main/java/io/openliberty/tools/langserver/lemminx/util/XmlReader.java +++ b/lemminx-liberty/src/main/java/io/openliberty/tools/langserver/lemminx/util/XmlReader.java @@ -68,8 +68,9 @@ private static boolean hasServerRoot(File xmlFile) { private static boolean hasSeverRootValues(XMLInputFactory factory, File xmlFile) { XMLEventReader reader=null; + FileInputStream fis = null; try { - FileInputStream fis = new FileInputStream(xmlFile); + fis = new FileInputStream(xmlFile); reader = factory.createXMLEventReader(fis); while (reader.hasNext()) { @@ -81,6 +82,12 @@ private static boolean hasSeverRootValues(XMLInputFactory factory, File xmlFile) } catch (XMLStreamException | FileNotFoundException e) { LOGGER.severe("Error received trying to read XML file: " + xmlFile.getAbsolutePath()); } finally { + if (fis != null) { + try { + fis.close(); + } catch (Exception ignored) { + } + } if (reader != null) { try { reader.close(); @@ -98,7 +105,9 @@ private static XMLInputFactory getXmlInputFactory() { factory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, Boolean.FALSE); factory.setProperty(XMLInputFactory.SUPPORT_DTD, Boolean.FALSE); factory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, Boolean.FALSE); + // XMLConstants.ACCESS_EXTERNAL_DTD an empty string to deny all access to external references; factory.setProperty(XMLConstants.ACCESS_EXTERNAL_DTD, ""); + // XMLConstants.ACCESS_EXTERNAL_SCHEMA uses an empty string to deny all access to external references; factory.setProperty(XMLConstants.ACCESS_EXTERNAL_SCHEMA, ""); } catch (Exception e) { LOGGER.warning("Could not set properties on XMLInputFactory."); diff --git a/liberty-ls/src/main/java/io/openliberty/tools/langserver/utils/XmlReader.java b/liberty-ls/src/main/java/io/openliberty/tools/langserver/utils/XmlReader.java index ac9a6386..ad722a36 100644 --- a/liberty-ls/src/main/java/io/openliberty/tools/langserver/utils/XmlReader.java +++ b/liberty-ls/src/main/java/io/openliberty/tools/langserver/utils/XmlReader.java @@ -70,8 +70,9 @@ private static void readElementValues(File file, Set elementNames, Map elementNames, Map returnValues, XMLInputFactory factory) { XMLEventReader reader = null; + FileInputStream fis = null; try { - FileInputStream fis = new FileInputStream(file); + fis = new FileInputStream(file); reader = factory.createXMLEventReader(fis); while (reader.hasNext()) { XMLEvent nextEvent = reader.nextEvent(); @@ -97,6 +98,12 @@ private static void readElements(File file, Set elementNames, Map Date: Wed, 7 Aug 2024 19:16:09 +0530 Subject: [PATCH 17/17] incorparating review comments Signed-off-by: Arun Venmany --- .../tools/langserver/lemminx/util/XmlReader.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lemminx-liberty/src/main/java/io/openliberty/tools/langserver/lemminx/util/XmlReader.java b/lemminx-liberty/src/main/java/io/openliberty/tools/langserver/lemminx/util/XmlReader.java index f8d6eeaa..0037f549 100644 --- a/lemminx-liberty/src/main/java/io/openliberty/tools/langserver/lemminx/util/XmlReader.java +++ b/lemminx-liberty/src/main/java/io/openliberty/tools/langserver/lemminx/util/XmlReader.java @@ -138,8 +138,10 @@ public static Map getElementValues(Path file, Set elemen private static void readElementValues(Path file, Set elementNames, XMLInputFactory factory, Map returnValues) { XMLEventReader reader = null; + FileInputStream fis = null; try { - reader = factory.createXMLEventReader(new FileInputStream(file.toFile())); + fis = new FileInputStream(file.toFile()); + reader = factory.createXMLEventReader(fis); while (reader.hasNext()) { XMLEvent event = reader.nextEvent(); @@ -160,6 +162,12 @@ private static void readElementValues(Path file, Set elementNames, XMLIn } catch (XMLStreamException e) { LOGGER.severe("Error received trying to read XML file " + file.toFile().getName() + " : "+e.getMessage()); } finally { + if (fis != null) { + try { + fis.close(); + } catch (Exception ignored) { + } + } if (reader != null) { try { reader.close();