Bug 529662 - [sonar] Resolve "Possible null pointer dereference"
Change-Id: I79540c4282a5d70b99e8eafe5c74f49f395ea62d
Signed-off-by: René Purrio <rpurrio@itemis.de>
diff --git a/tests/org.eclipse.core.tests.runtime/src/org/eclipse/core/tests/internal/registry/ContributorsTest.java b/tests/org.eclipse.core.tests.runtime/src/org/eclipse/core/tests/internal/registry/ContributorsTest.java
index f566592..1d1b664 100644
--- a/tests/org.eclipse.core.tests.runtime/src/org/eclipse/core/tests/internal/registry/ContributorsTest.java
+++ b/tests/org.eclipse.core.tests.runtime/src/org/eclipse/core/tests/internal/registry/ContributorsTest.java
@@ -13,14 +13,24 @@
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
-import junit.framework.*;
-import org.eclipse.core.runtime.*;
+
+import org.eclipse.core.runtime.ContributorFactoryOSGi;
+import org.eclipse.core.runtime.ContributorFactorySimple;
+import org.eclipse.core.runtime.IContributor;
+import org.eclipse.core.runtime.IExtension;
+import org.eclipse.core.runtime.IExtensionPoint;
+import org.eclipse.core.runtime.IExtensionRegistry;
+import org.eclipse.core.runtime.RegistryFactory;
import org.eclipse.core.runtime.spi.IDynamicExtensionRegistry;
import org.eclipse.core.tests.harness.BundleTestingHelper;
import org.eclipse.core.tests.runtime.RuntimeTestsPlugin;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleException;
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
/**
* Tests contributor resolution for Bundle-based contributors.
*
@@ -157,6 +167,9 @@
private boolean addContribution(IExtensionRegistry registry, String fileName) throws IOException {
String fullPath = RuntimeTestsPlugin.TEST_FILES_ROOT + "registry/elementsByContributor/" + fileName + "/plugin.xml";
URL urlA = RuntimeTestsPlugin.getContext().getBundle().getEntry(fullPath);
+ if (urlA == null) {
+ throw new IOException("No entry to '"+fullPath+"' could be found or caller does not have the appropriate permissions.");//$NON-NLS-1$ //$NON-NLS-2$
+ }
InputStream is = urlA.openStream();
IContributor nonBundleContributor = ContributorFactorySimple.createContributor(fileName);
return registry.addContribution(is, nonBundleContributor, false, urlA.getFile(), null, null);
diff --git a/tests/org.eclipse.core.tests.runtime/src/org/eclipse/core/tests/runtime/RuntimeTestsPlugin.java b/tests/org.eclipse.core.tests.runtime/src/org/eclipse/core/tests/runtime/RuntimeTestsPlugin.java
index 33ee8e5..5e9d40c 100644
--- a/tests/org.eclipse.core.tests.runtime/src/org/eclipse/core/tests/runtime/RuntimeTestsPlugin.java
+++ b/tests/org.eclipse.core.tests.runtime/src/org/eclipse/core/tests/runtime/RuntimeTestsPlugin.java
@@ -10,9 +10,20 @@
*******************************************************************************/
package org.eclipse.core.tests.runtime;
-import java.io.*;
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileFilter;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
import java.net.URL;
-import org.eclipse.core.runtime.*;
+
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Plugin;
import org.osgi.framework.BundleContext;
public class RuntimeTestsPlugin extends Plugin {
@@ -50,6 +61,9 @@
return true;
if (file.isDirectory()) {
File[] children = file.listFiles();
+ if(children == null) {
+ children = new File[0];
+ }
for (File element : children)
delete(element);
}
@@ -116,6 +130,9 @@
if (!target.exists())
target.mkdirs();
File[] children = source.listFiles(filter);
+ if(children == null) {
+ throw new IOException("Content from directory '" + source.getAbsolutePath() + "' can not be listed."); //$NON-NLS-1$ //$NON-NLS-2$
+ }
for (File element : children)
copy(element, new File(target, element.getName()));
return;