Skip to content

Commit

Permalink
Merge pull request #285 from arunvenmany-ibm/sast_issue_fix_1.0
Browse files Browse the repository at this point in the history
Sast issue fix 1.0
  • Loading branch information
arunvenmany-ibm authored Aug 7, 2024
2 parents 229f707 + a42af18 commit 4329148
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@
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());
Expand Down Expand Up @@ -62,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()) {
Expand All @@ -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.");
}
Expand All @@ -118,7 +119,7 @@ public static Map<String, String> getElementValues(Path file, Set<String> 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()) {
Expand Down

0 comments on commit 4329148

Please sign in to comment.