Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Watson2019-09-19 13:48:01 +0000
committerThomas Watson2019-09-23 15:20:02 +0000
commite7cf7a6e5f8987222cba03a5e8d2ad4d558b60c2 (patch)
tree65ace006382c7f1aa0b5f7ccaa45c2a0520a51b3
parent4b1088352687b1301b62ea8ff2f22abba5bf8f49 (diff)
downloadrt.equinox.framework-e7cf7a6e5f8987222cba03a5e8d2ad4d558b60c2.tar.gz
rt.equinox.framework-e7cf7a6e5f8987222cba03a5e8d2ad4d558b60c2.tar.xz
rt.equinox.framework-e7cf7a6e5f8987222cba03a5e8d2ad4d558b60c2.zip
Bug 551380 - StorageHookFactory.createStorageHook method returns null
The framework must handle when creeateStorageHook returns null when installing a bundle, saving persistent hook data and loading persistent hook data. A new test is added to test all three cases. Change-Id: I941491e8759b659ea97b129fbab0aa01c84edf5a Signed-off-by: Thomas Watson <tjwatson@us.ibm.com>
-rw-r--r--bundles/org.eclipse.osgi.tests/bundles_src/storage.hooks.a/org/eclipse/osgi/tests/hooks/framework/storage/a/TestHookConfigurator.java4
-rw-r--r--bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/hooks/framework/StorageHookTests.java35
-rw-r--r--bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/Storage.java8
3 files changed, 45 insertions, 2 deletions
diff --git a/bundles/org.eclipse.osgi.tests/bundles_src/storage.hooks.a/org/eclipse/osgi/tests/hooks/framework/storage/a/TestHookConfigurator.java b/bundles/org.eclipse.osgi.tests/bundles_src/storage.hooks.a/org/eclipse/osgi/tests/hooks/framework/storage/a/TestHookConfigurator.java
index da835d0b1..fc9d094cb 100644
--- a/bundles/org.eclipse.osgi.tests/bundles_src/storage.hooks.a/org/eclipse/osgi/tests/hooks/framework/storage/a/TestHookConfigurator.java
+++ b/bundles/org.eclipse.osgi.tests/bundles_src/storage.hooks.a/org/eclipse/osgi/tests/hooks/framework/storage/a/TestHookConfigurator.java
@@ -120,6 +120,9 @@ public class TestHookConfigurator implements HookConfigurator {
@Override
protected TestStorageHook createStorageHook(Generation generation) {
createStorageHookCalled = true;
+ if (returnNullStorageHook) {
+ return null;
+ }
Class<?> factoryClass = TestStorageHookFactory.class;
if (invalidFactoryClass)
factoryClass = StorageHookFactory.class;
@@ -162,6 +165,7 @@ public class TestHookConfigurator implements HookConfigurator {
public static volatile boolean adaptManifest;
public static volatile boolean replaceModuleBuilder;
public static volatile boolean handleContentConnection;
+ public static volatile boolean returnNullStorageHook;
public void addHooks(HookRegistry hookRegistry) {
hookRegistry.addStorageHookFactory(new TestStorageHookFactory());
diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/hooks/framework/StorageHookTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/hooks/framework/StorageHookTests.java
index a3a61f45c..9e8c2d63d 100644
--- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/hooks/framework/StorageHookTests.java
+++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/hooks/framework/StorageHookTests.java
@@ -46,6 +46,7 @@ public class StorageHookTests extends AbstractFrameworkHookTests {
private static final String HOOK_CONFIGURATOR_FIELD_ADAPT_MANIFEST = "adaptManifest";
private static final String HOOK_CONFIGURATOR_FIELD_REPLACE_BUILDER = "replaceModuleBuilder";
private static final String HOOK_CONFIGURATOR_FIELD_HANDLE_CONTENT = "handleContentConnection";
+ private static final String HOOK_CONFIGURATOR_FIELD_NULL_STORAGE_HOOK = "returnNullStorageHook";
private Map<String, String> configuration;
private Framework framework;
@@ -270,6 +271,32 @@ public class StorageHookTests extends AbstractFrameworkHookTests {
assertEquals("Wrong symbolicName", "testHandleContentConnection", b.getSymbolicName());
}
+ public void testNullStorageHook() throws Exception {
+
+ initAndStartFramework();
+ File bundlesBase = new File(OSGiTestsActivator.getContext().getDataFile(getName()), "bundles");
+ bundlesBase.mkdirs();
+ String initialBundleLoc = SystemBundleTests.createBundle(bundlesBase, getName(), false, false).toURI().toString();
+ Bundle initialBundle = framework.getBundleContext().installBundle(initialBundleLoc);
+ assertNotNull("Expected to have an initial bundle.", initialBundle);
+
+ // Have storage hook factory return null StorageHook
+ setFactoryNullStorageHook(true);
+ Bundle b = installBundle();
+ assertNotNull("Expected to have a bundle after install.", b);
+ framework.stop();
+ framework.waitForStop(5000);
+
+ // create new framework to make sure null storage hook works from persistence also.
+ framework = createFramework(configuration);
+ framework.init();
+
+ initialBundle = framework.getBundleContext().getBundle(initialBundleLoc);
+ assertNotNull("Expected to have initial bundle after restart.", initialBundle);
+ b = framework.getBundleContext().getBundle(location);
+ assertNotNull("Expected to have a bundle after restart.", b);
+ }
+
@Override
protected void setUp() throws Exception {
super.setUp();
@@ -339,6 +366,9 @@ public class StorageHookTests extends AbstractFrameworkHookTests {
clazz.getField(HOOK_CONFIGURATOR_FIELD_DELETING_CALLED).set(null, false);
clazz.getField(HOOK_CONFIGURATOR_FIELD_ADAPT_MANIFEST).set(null, false);
clazz.getField(HOOK_CONFIGURATOR_FIELD_FAIL_LOAD).set(null, false);
+ clazz.getField(HOOK_CONFIGURATOR_FIELD_HANDLE_CONTENT).set(null, false);
+ clazz.getField(HOOK_CONFIGURATOR_FIELD_REPLACE_BUILDER).set(null, false);
+ clazz.getField(HOOK_CONFIGURATOR_FIELD_NULL_STORAGE_HOOK).set(null, false);
}
private void restartFramework() throws Exception {
@@ -375,6 +405,11 @@ public class StorageHookTests extends AbstractFrameworkHookTests {
clazz.getField(HOOK_CONFIGURATOR_FIELD_HANDLE_CONTENT).set(null, value);
}
+ private void setFactoryNullStorageHook(boolean value) throws Exception {
+ Class<?> clazz = classLoader.loadClass(HOOK_CONFIGURATOR_CLASS);
+ clazz.getField(HOOK_CONFIGURATOR_FIELD_NULL_STORAGE_HOOK).set(null, value);
+ }
+
private void updateBundle() throws Exception {
framework.getBundleContext().getBundle(location).update();
}
diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/Storage.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/Storage.java
index 8b985cafe..b041c8abc 100644
--- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/Storage.java
+++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/Storage.java
@@ -754,7 +754,9 @@ public class Storage {
@SuppressWarnings("unchecked")
StorageHookFactory<Object, Object, StorageHook<Object, Object>> next = (StorageHookFactory<Object, Object, StorageHook<Object, Object>>) iFactories.next();
StorageHook<Object, Object> hook = next.createStorageHookAndValidateFactoryClass(generation);
- hooks.add(hook);
+ if (hook != null) {
+ hooks.add(hook);
+ }
}
generation.setStorageHooks(Collections.unmodifiableList(hooks), true);
for (StorageHook<?, ?> hook : hooks) {
@@ -1407,7 +1409,9 @@ public class Storage {
}
@SuppressWarnings({"rawtypes", "unchecked"})
StorageHook<Object, Object> hook = generation.getStorageHook((Class) factory.getClass());
- hook.save(saveContext, temp);
+ if (hook != null) {
+ hook.save(saveContext, temp);
+ }
}
} finally {
temp.close();

Back to the top