diff options
author | René Purrio | 2018-01-17 08:03:49 +0000 |
---|---|---|
committer | René Purrio | 2018-01-17 08:03:49 +0000 |
commit | edb01a788585e35cb247f67161b4944a9d1be364 (patch) | |
tree | c05cafa5ce06eb2fb37e580594334e9005d39a99 /org.eclipse.help.base/src/org/eclipse | |
parent | a0bbfb0b2a5a40b73eaeabdf3221f079e7ef38f7 (diff) | |
download | eclipse.platform.ua-edb01a788585e35cb247f67161b4944a9d1be364.tar.gz eclipse.platform.ua-edb01a788585e35cb247f67161b4944a9d1be364.tar.xz eclipse.platform.ua-edb01a788585e35cb247f67161b4944a9d1be364.zip |
Bug 529828 - [sonar] Resolve "Possible null pointer dereference"S4_8_0_M5I20180124-2000I20180124-0800I20180123-2000I20180123-1010I20180123-0800I20180122-2000I20180122-0800I20180121-2000I20180121-0800I20180120-1500I20180120-0800I20180119-2000I20180119-0110I20180118-2000
Change-Id: Iddfb24c63e3454c3de9e539db25c379c7775f06c
Signed-off-by: René Purrio <rpurrio@itemis.de>
Diffstat (limited to 'org.eclipse.help.base/src/org/eclipse')
4 files changed, 28 insertions, 7 deletions
diff --git a/org.eclipse.help.base/src/org/eclipse/help/internal/base/IndexToolApplication.java b/org.eclipse.help.base/src/org/eclipse/help/internal/base/IndexToolApplication.java index f254fc69d..d050bf870 100644 --- a/org.eclipse.help.base/src/org/eclipse/help/internal/base/IndexToolApplication.java +++ b/org.eclipse.help.base/src/org/eclipse/help/internal/base/IndexToolApplication.java @@ -100,6 +100,9 @@ public class IndexToolApplication implements IApplication { private static void delete(File file) throws IOException { if (file.isDirectory()) { File files[] = file.listFiles(); + if(files == null) { + throw new IOException("Content from directory '" + file.getAbsolutePath() + "' can not be listed."); //$NON-NLS-1$ //$NON-NLS-2$ + } for (int i = 0; i < files.length; i++) { delete(files[i]); } diff --git a/org.eclipse.help.base/src/org/eclipse/help/internal/search/SearchIndex.java b/org.eclipse.help.base/src/org/eclipse/help/internal/search/SearchIndex.java index 0903ed4ef..c8fd3e5ca 100644 --- a/org.eclipse.help.base/src/org/eclipse/help/internal/search/SearchIndex.java +++ b/org.eclipse.help.base/src/org/eclipse/help/internal/search/SearchIndex.java @@ -210,6 +210,9 @@ public class SearchIndex implements IHelpSearchIndex { private void deleteDir(File indexDir) { File[] files = indexDir.listFiles(); + if(files == null) { + files = new File[0]; + } for (File file : files) { if (file.isDirectory()) deleteDir(file); diff --git a/org.eclipse.help.base/src/org/eclipse/help/internal/standalone/Eclipse.java b/org.eclipse.help.base/src/org/eclipse/help/internal/standalone/Eclipse.java index 53d2b8339..4416ecaf3 100644 --- a/org.eclipse.help.base/src/org/eclipse/help/internal/standalone/Eclipse.java +++ b/org.eclipse.help.base/src/org/eclipse/help/internal/standalone/Eclipse.java @@ -10,7 +10,11 @@ *******************************************************************************/ package org.eclipse.help.internal.standalone; -import java.io.*; +import java.io.BufferedReader; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; import java.util.List; /** @@ -176,6 +180,9 @@ public class Eclipse extends Thread { throw new Exception("Plugins directory " + pluginsDir.getAbsolutePath() //$NON-NLS-1$ + " does not exists. Pass a correct -eclipsehome option"); //$NON-NLS-1$ File[] plugins = pluginsDir.listFiles(); + if(plugins == null) { + throw new IOException("Content from plugins directory '" + pluginsDir.getAbsolutePath() + "' can not be listed."); //$NON-NLS-1$ //$NON-NLS-2$ + } for (int i = 0; i < plugins.length; i++) { String file = plugins[i].getName(); if (file.startsWith("org.eclipse.equinox.launcher_") && file.endsWith(".jar") && !plugins[i].isDirectory()) //$NON-NLS-1$ //$NON-NLS-2$ diff --git a/org.eclipse.help.base/src/org/eclipse/help/search/HelpIndexBuilder.java b/org.eclipse.help.base/src/org/eclipse/help/search/HelpIndexBuilder.java index 776ddb487..0ab6701a2 100644 --- a/org.eclipse.help.base/src/org/eclipse/help/search/HelpIndexBuilder.java +++ b/org.eclipse.help.base/src/org/eclipse/help/search/HelpIndexBuilder.java @@ -352,7 +352,7 @@ public class HelpIndexBuilder { * nl/language/country/ locale dirs that contain files. We will * produce an index for each one. */ - private void computeLocaleDirs(boolean fragment) { + private void computeLocaleDirs(boolean fragment) throws CoreException { if (!fragment) { LocaleDir dir = new LocaleDir(null, "/"); //$NON-NLS-1$ dir.addDirectory(destination); @@ -366,7 +366,7 @@ public class HelpIndexBuilder { File nl = new File(destination, "nl"); //$NON-NLS-1$ if (!nl.exists() || !nl.isDirectory()) return; - File [] languages = nl.listFiles(); + File [] languages = listFiles(nl); HashSet<String> locales = new HashSet<>(); for (int i=0; i<languages.length; i++) { File language = languages[i]; @@ -374,7 +374,7 @@ public class HelpIndexBuilder { continue; if (!isValidLanguage(language.getName())) continue; - File [] countries = language.listFiles(); + File [] countries = listFiles(language); for (int j=0; j<countries.length; j++) { File country = countries[j]; String locale; @@ -403,10 +403,10 @@ public class HelpIndexBuilder { } } - private void computeSystem(File systemRoot, String [] values) { + private void computeSystem(File systemRoot, String [] values) throws CoreException { if (systemRoot.exists() && systemRoot.isDirectory()) { // check - File [] files = systemRoot.listFiles(); + File [] files = listFiles(systemRoot); for (int i=0; i<files.length; i++) { File sdir = files[i]; if (!sdir.isDirectory()) @@ -643,7 +643,7 @@ public class HelpIndexBuilder { private void prepareDirectory(File indexDirectory) throws CoreException { if (indexDirectory.exists()) { - File[] files = indexDirectory.listFiles(); + File[] files = listFiles(indexDirectory); for (int i = 0; i < files.length; i++) { File file = files[i]; boolean result = file.delete(); @@ -766,4 +766,12 @@ public class HelpIndexBuilder { IStatus.OK, message, t); throw new CoreException(status); } + + private File[] listFiles(File file) throws CoreException { + File[] fileList = file.listFiles(); + if(fileList == null) { + throwCoreException("Content from directory '" + file.getAbsolutePath() + "' can not be listed.", null); //$NON-NLS-1$ //$NON-NLS-2$ + } + return fileList; + } } |