Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Ross2016-03-03 20:15:05 +0000
committerJohn Ross2016-03-03 20:44:45 +0000
commitd2e12471494d0dd3721261510cff0b5b4d391754 (patch)
tree9283bbc2c69c98ab344e5f80f7b5358f440deaab /bundles
parent121b7c5b2cb5f7a130720d382a3eac8c0e290a05 (diff)
downloadrt.equinox.framework-d2e12471494d0dd3721261510cff0b5b4d391754.tar.gz
rt.equinox.framework-d2e12471494d0dd3721261510cff0b5b4d391754.tar.xz
rt.equinox.framework-d2e12471494d0dd3721261510cff0b5b4d391754.zip
[Bug 477787] Embedded Equinox in an entreprise application ear - NullPointerException at start upI20160308-0800
In BundleInfo.Generation, check for null content and, if so, set lastModified to zero. In ModuleClassLoader, check for a null base file from BundleFile and, if so, create the ProtectionDomain with a null CodeSource. In both cases, the referenced variable will be null when the osgi.framework property was specified with an invalid value. Plus test. Signed-off-by: John Ross <jwross@us.ibm.com>
Diffstat (limited to 'bundles')
-rw-r--r--bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/SystemBundleTests.java62
-rw-r--r--bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/loader/ModuleClassLoader.java5
-rw-r--r--bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/BundleInfo.java5
3 files changed, 71 insertions, 1 deletions
diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/SystemBundleTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/SystemBundleTests.java
index 93577eb2b..5c64f8fbe 100644
--- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/SystemBundleTests.java
+++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/SystemBundleTests.java
@@ -34,7 +34,10 @@ import org.osgi.framework.hooks.resolver.ResolverHook;
import org.osgi.framework.hooks.resolver.ResolverHookFactory;
import org.osgi.framework.hooks.weaving.WeavingHook;
import org.osgi.framework.hooks.weaving.WovenClass;
+import org.osgi.framework.namespace.NativeNamespace;
import org.osgi.framework.wiring.*;
+import org.osgi.resource.Capability;
+import org.osgi.resource.Requirement;
import org.osgi.service.packageadmin.ExportedPackage;
import org.osgi.service.packageadmin.PackageAdmin;
import org.osgi.service.startlevel.StartLevel;
@@ -2683,4 +2686,63 @@ public class SystemBundleTests extends AbstractBundleTests {
jos.close();
return file;
}
+
+ public void testBug405919() throws Exception {
+ File config = OSGiTestsActivator.getContext().getDataFile(getName());
+ config.mkdirs();
+ Map<String, Object> configuration = new HashMap<String, Object>();
+ configuration.put(Constants.FRAMEWORK_STORAGE, config.getAbsolutePath());
+ configuration.put("osgi.framework", "boo");
+ // Initialize and start a framework specifying an invalid osgi.framework configuration value.
+ Equinox equinox = null;
+ try {
+ equinox = new Equinox(configuration);
+ equinox.start();
+ } catch (NullPointerException e) {
+ fail("failed to accept an invalid value for osgi.framework", e);
+ }
+ try {
+ // Make sure the framework can install and start a bundle.
+ BundleContext systemContext = equinox.getBundleContext();
+ try {
+ Bundle tb1 = systemContext.installBundle(installer.getBundleLocation("test.bug375784"));
+ tb1.start();
+ } catch (BundleException e) {
+ fail("failed to install and start test bundle", e);
+ }
+ // Check the capabilities and requirements of the system bundle.
+ BundleRevision inner = systemContext.getBundle().adapt(BundleRevision.class);
+ BundleRevision outer = getContext().getBundle(0).adapt(BundleRevision.class);
+ // Capabilities.
+ List<Capability> innerCaps = inner.getCapabilities(null);
+ List<Capability> outerCaps = outer.getCapabilities(null);
+ assertEquals("Number of capabilities differ", outerCaps.size(), innerCaps.size());
+ for (int i = 0; i < innerCaps.size(); i++) {
+ Capability innerCap = innerCaps.get(i);
+ Capability outerCap = innerCaps.get(i);
+ assertEquals("Capability namespaces differ: " + outerCap.getNamespace(), outerCap.getNamespace(), innerCap.getNamespace());
+ String namespace = outerCap.getNamespace();
+ if (NativeNamespace.NATIVE_NAMESPACE.equals(namespace) || "eclipse.platform".equals(namespace)) {
+ // Ignore these because they are known to differ.
+ continue;
+ }
+ assertEquals("Capability attributes differ: " + outerCap.getNamespace(), outerCap.getAttributes(), innerCap.getAttributes());
+ assertEquals("Capability directives differ: " + outerCap.getNamespace(), outerCap.getDirectives(), innerCap.getDirectives());
+ }
+ // Requirements.
+ List<Requirement> innerReqs = inner.getRequirements(null);
+ List<Requirement> outerReqs = outer.getRequirements(null);
+ assertEquals("Number of requirements differ", outerReqs.size(), innerReqs.size());
+ for (int i = 0; i < innerReqs.size(); i++) {
+ Requirement innerReq = innerReqs.get(i);
+ Requirement outerReq = innerReqs.get(i);
+ assertEquals("Requirement namespaces differ: " + outerReq.getNamespace(), outerReq.getNamespace(), innerReq.getNamespace());
+ assertEquals("Requirement attributes differ: " + outerReq.getNamespace(), outerReq.getAttributes(), innerReq.getAttributes());
+ assertEquals("Requirement directives differ: " + outerReq.getNamespace(), outerReq.getDirectives(), innerReq.getDirectives());
+ }
+ } finally {
+ equinox.stop();
+ equinox.waitForStop(5000);
+ }
+ }
}
diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/loader/ModuleClassLoader.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/loader/ModuleClassLoader.java
index 7593c3006..199599389 100644
--- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/loader/ModuleClassLoader.java
+++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/loader/ModuleClassLoader.java
@@ -11,6 +11,7 @@
package org.eclipse.osgi.internal.loader;
+import java.io.File;
import java.io.IOException;
import java.lang.reflect.Method;
import java.net.MalformedURLException;
@@ -357,7 +358,9 @@ public abstract class ModuleClassLoader extends ClassLoader implements BundleRef
if (signers.length > 0)
certs = signers[0].getCertificateChain();
}
- return new GenerationProtectionDomain(new CodeSource(bundlefile.getBaseFile().toURL(), certs), permissions, getGeneration());
+ File file = bundlefile.getBaseFile();
+ // Bug 477787: file will be null when the osgi.framework configuration property contains an invalid value.
+ return new GenerationProtectionDomain(file == null ? null : new CodeSource(file.toURL(), certs), permissions, getGeneration());
//return new ProtectionDomain(new CodeSource(bundlefile.getBaseFile().toURL(), certs), permissions);
} catch (MalformedURLException e) {
// Failed to create our own domain; just return the baseDomain
diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/BundleInfo.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/BundleInfo.java
index e04e6d29f..4ab00f0aa 100644
--- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/BundleInfo.java
+++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/BundleInfo.java
@@ -192,6 +192,11 @@ public final class BundleInfo {
}
private void setLastModified(File content) {
+ if (content == null) {
+ // Bug 477787: content will be null when the osgi.framework configuration property contains an invalid value.
+ lastModified = 0;
+ return;
+ }
if (isDirectory)
content = new File(content, "META-INF/MANIFEST.MF"); //$NON-NLS-1$
lastModified = Storage.secureAction.lastModified(content);

Back to the top