analysis.xml: fix potential null dereference
authorMatthew Khouzam <matthew.khouzam@ericsson.com>
Thu, 28 Jan 2016 03:40:16 +0000 (22:40 -0500)
committerMatthew Khouzam <matthew.khouzam@ericsson.com>
Thu, 28 Jan 2016 16:25:23 +0000 (11:25 -0500)
File#listFiles() can return null. Even though the test
"isDirectory()" and "exists()" are able to pick it up, executing
the command and null checking it is the best garanty.

Change-Id: Ic3cefdaecf3d5d88dbeaeb3f3d58689abdb05347
Signed-off-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/65332
Reviewed-by: Hudson CI
Reviewed-by: Genevieve Bastien <gbastien+lttng@versatic.net>
Tested-by: Genevieve Bastien <gbastien+lttng@versatic.net>
tmf/org.eclipse.tracecompass.tmf.analysis.xml.core/src/org/eclipse/tracecompass/tmf/analysis/xml/core/module/XmlAnalysisModuleSource.java

index 9a7e9afc856f1dc14fc88acc47d7db27733cd072..8d9c942ae0d1dde8d537f51e9f3f01b35ee2f2bb 100644 (file)
@@ -151,17 +151,17 @@ public class XmlAnalysisModuleSource implements IAnalysisModuleSource {
 
     private static void populateAnalysisModules() {
         IPath pathToFiles = XmlUtils.getXmlFilesPath();
-        File fFolder = pathToFiles.toFile();
-        if (!(fFolder.isDirectory() && fFolder.exists())) {
+        File folder = pathToFiles.toFile();
+        if (!(folder.isDirectory() && folder.exists())) {
             return;
         }
-
         /*
          * Transfer files from Linux Tools directory.
          */
-        File fOldFolder = XML_DIRECTORY_LEGACY.toFile();
-        if ((fOldFolder.isDirectory() && fOldFolder.exists())) {
-            for (File fromFile : fOldFolder.listFiles()) {
+        File oldFolder = XML_DIRECTORY_LEGACY.toFile();
+        final File[] oldAnalysisFiles = oldFolder.listFiles();
+        if (oldAnalysisFiles != null) {
+            for (File fromFile : oldAnalysisFiles) {
                 File toFile = pathToFiles.append(fromFile.getName()).toFile();
                 if (!toFile.exists() && !fromFile.isDirectory()) {
                     try (FileInputStream fis = new FileInputStream(fromFile);
@@ -176,9 +176,11 @@ public class XmlAnalysisModuleSource implements IAnalysisModuleSource {
                 }
             }
         }
-
-        for (File xmlFile : fFolder.listFiles()) {
-            processFile(xmlFile);
+        final File[] analysisFiles = folder.listFiles();
+        if (analysisFiles != null) {
+            for (File xmlFile : analysisFiles) {
+                processFile(xmlFile);
+            }
         }
     }
 
This page took 0.027056 seconds and 5 git commands to generate.