aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Ross2013-06-28 08:53:44 (EDT)
committerThomas Watson2013-07-01 15:19:00 (EDT)
commite4619cbfa6d2ad627511d07502b75bc62d391c8f (patch)
treea6f9d724912720381447432b7e64af700b4b0748
parent1070b693b75460f311be85953d0c7e9e0b35011a (diff)
downloadrt.equinox.framework-e4619cbfa6d2ad627511d07502b75bc62d391c8f.zip
rt.equinox.framework-e4619cbfa6d2ad627511d07502b75bc62d391c8f.tar.gz
rt.equinox.framework-e4619cbfa6d2ad627511d07502b75bc62d391c8f.tar.bz2
[Bug 411829] StorageHookFactory validates factory class of StorageHook at creation time.
Added public final method createStorageHookAndValidateFactoryClass(Generation) to StorageHookFactory. This method calls the existing public abstract createStorageHook(Generation) method then validates the factory class of the storage hook against its own class. If not equal, an IllegalStateException is thrown. Modified the framework code to call the new method instead of the original one.
-rw-r--r--bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/hookregistry/StorageHookFactory.java20
-rw-r--r--bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/Storage.java8
2 files changed, 24 insertions, 4 deletions
diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/hookregistry/StorageHookFactory.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/hookregistry/StorageHookFactory.java
index a98e12f..ab75c5b 100644
--- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/hookregistry/StorageHookFactory.java
+++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/hookregistry/StorageHookFactory.java
@@ -88,6 +88,26 @@ public abstract class StorageHookFactory<S, L, H extends StorageHookFactory.Stor
public abstract H createStorageHook(Generation generation);
/**
+ * Creates a storage hook for the specified generation and checks that the
+ * factory class of the storage hook equals the class of this storage hook
+ * factory.
+ *
+ * @param generation - The generation for which a storage hook should be
+ * created.
+ * @return A newly created storage hook.
+ * @throws IllegalStateException - If the factory class of the storage hook
+ * is not equal to the class of this storage hook factory.
+ */
+ public final H createStorageHookAndValidateFactoryClass(Generation generation) {
+ H result = createStorageHook(generation);
+ Class<?> factoryClass = getClass();
+ Class<?> factoryClassOfStorageHook = result.getFactoryClass();
+ if (!factoryClass.equals(factoryClassOfStorageHook))
+ throw new IllegalStateException(String.format("The factory class '%s' of storage hook '%s' does not match the creating factory class of '%s'", factoryClassOfStorageHook.getName(), result, factoryClass.getName())); //$NON-NLS-1$
+ return result;
+ }
+
+ /**
* A storage hook for a specific generation object. This hook
* is responsible for persisting and loading data associated
* with a specific generation.
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 f9fa54a..1f1edbe 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
@@ -502,7 +502,7 @@ public class Storage {
for (Iterator<StorageHookFactory<?, ?, ?>> iFactories = factories.iterator(); iFactories.hasNext();) {
@SuppressWarnings("unchecked")
StorageHookFactory<Object, Object, StorageHook<Object, Object>> next = (StorageHookFactory<Object, Object, StorageHook<Object, Object>>) iFactories.next();
- StorageHook<Object, Object> hook = next.createStorageHook(generation);
+ StorageHook<Object, Object> hook = next.createStorageHookAndValidateFactoryClass(generation);
hooks.add(hook);
}
generation.setStorageHooks(Collections.unmodifiableList(hooks), true);
@@ -1169,7 +1169,7 @@ public class Storage {
if (generation.getBundleInfo().getBundleId() == 0) {
continue; // ignore system bundle
}
- StorageHook<Object, Object> hook = factory.createStorageHook(generation);
+ StorageHook<Object, Object> hook = factory.createStorageHookAndValidateFactoryClass(generation);
hook.load(loadContext, temp);
getHooks(hookMap, generation).add(hook);
}
@@ -1179,7 +1179,7 @@ public class Storage {
if (generation.getBundleInfo().getBundleId() == 0) {
continue; // ignore system bundle
}
- StorageHook<Object, Object> hook = factory.createStorageHook(generation);
+ StorageHook<Object, Object> hook = factory.createStorageHookAndValidateFactoryClass(generation);
hook.initialize(generation.getHeaders());
getHooks(hookMap, generation).add(hook);
}
@@ -1200,7 +1200,7 @@ public class Storage {
if (generation.getBundleInfo().getBundleId() == 0) {
continue; // ignore system bundle
}
- StorageHook<Object, Object> hook = next.createStorageHook(generation);
+ StorageHook<Object, Object> hook = next.createStorageHookAndValidateFactoryClass(generation);
try {
hook.initialize(generation.getHeaders());
getHooks(hookMap, generation).add(hook);