Skip to content

Commit

Permalink
Merge pull request #293 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 6d75f15 + 5a7a585 commit 45b1937
Showing 1 changed file with 30 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,38 +61,42 @@ public static Map<String, String> getElementValues(File file, Set<String> elemen

private static void readElementValues(File file, Set<String> elementNames, Map<String, String> returnValues) {
XMLInputFactory factory = getXmlInputFactory();
try {
readElements(file, elementNames, returnValues, factory);
} catch (Exception e) {
LOGGER.severe("Unable to access XML file "+ file.getAbsolutePath());
}
}

private static void readElements(File file, Set<String> elementNames, Map<String, String> returnValues, XMLInputFactory factory) {
XMLEventReader reader = null;
try {
try {
FileInputStream fis = new FileInputStream(file);
reader = factory.createXMLEventReader(fis);
while (reader.hasNext()) {
XMLEvent nextEvent = reader.nextEvent();
if (!nextEvent.isStartElement()) {
continue;
}
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());
}
}
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) {
}
}
}
}

Expand Down

0 comments on commit 45b1937

Please sign in to comment.