From cb11754a767e17bbf5561a7c25da9cf658ed69ef Mon Sep 17 00:00:00 2001 From: Jean-Christian Kouame Date: Wed, 10 Feb 2016 15:37:12 -0500 Subject: [PATCH] tmf : Fix potential null pointer dereference in XmlUtils There is a possible null pointer exception that would have happened if I/O errors occur. Change-Id: I89bde3aaf4d82c71fb46fe6b4e9720603ad481bf Signed-off-by: Jean-Christian Kouame Reviewed-on: https://git.eclipse.org/r/66347 Reviewed-by: Hudson CI Reviewed-by: Bernd Hufmann Tested-by: Bernd Hufmann Reviewed-by: Matthew Khouzam --- .../tmf/analysis/xml/core/module/XmlUtils.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/module/XmlUtils.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/module/XmlUtils.java index 9fe69a03d7..175e9235f6 100644 --- a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/module/XmlUtils.java +++ b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/module/XmlUtils.java @@ -157,12 +157,16 @@ public class XmlUtils { Map fileMap = new HashMap<>(); if ((folder.isDirectory() && folder.exists())) { - File[] listOfFiles = getXmlFilesPath().toFile().listFiles(); - for (File file : listOfFiles) { - IPath path = new Path(file.getName()); - if (path.getFileExtension().equals(XML_EXTENSION)) { - fileMap.put(file.getName(), file); + File[] listOfFiles = folder.listFiles(); + if (listOfFiles != null) { + for (File file : listOfFiles) { + IPath path = new Path(file.getName()); + if (path.getFileExtension().equals(XML_EXTENSION)) { + fileMap.put(file.getName(), file); + } } + } else { + Activator.logError("I/O error occured while accessing files in folder " + folder.getPath()); //$NON-NLS-1$ } } return Collections.unmodifiableMap(fileMap); -- 2.34.1