Skip to content

Commit

Permalink
Merge pull request #284 from arunvenmany-ibm/sast_issue_fix_1.0
Browse files Browse the repository at this point in the history
using streamsource in xmleventreader of lemminx
  • Loading branch information
arunvenmany-ibm authored Aug 7, 2024
2 parents 7f84923 + ccabfb6 commit 229f707
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -117,7 +118,7 @@ public static Map<String, String> getElementValues(Path file, Set<String> 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()) {
Expand Down

0 comments on commit 229f707

Please sign in to comment.