Skip to content

Commit

Permalink
Merge pull request #291 from arunvenmany-ibm/sast_issue_fix_1.0
Browse files Browse the repository at this point in the history
reader moved to private
  • Loading branch information
arunvenmany-ibm authored Aug 7, 2024
2 parents 4e74646 + f189202 commit c1206c0
Showing 1 changed file with 24 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,38 +58,37 @@ 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());
}

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() {
Expand Down Expand Up @@ -125,7 +124,6 @@ public static Map<String, String> getElementValues(Path file, Set<String> elemen

XMLInputFactory factory = getXmlInputFactory();
readElementValues(file, elementNames, factory, returnValues);

return returnValues;
}

Expand Down

0 comments on commit c1206c0

Please sign in to comment.