diff options
author | Brian S. O'Neill <bronee@gmail.com> | 2011-01-08 18:50:19 +0000 |
---|---|---|
committer | Brian S. O'Neill <bronee@gmail.com> | 2011-01-08 18:50:19 +0000 |
commit | d8b0a17836099a976b415dbb45a6f7e0645e3ce6 (patch) | |
tree | 4814d7ffbfc6a8225ec0217b747eb9fb6f89710f /src | |
parent | 28d0b3c1737ba38759f84ee9fdbb769f903dbf0e (diff) |
Fix class loader issues.
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/com/amazon/carbonado/gen/StorableCopier.java | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/src/main/java/com/amazon/carbonado/gen/StorableCopier.java b/src/main/java/com/amazon/carbonado/gen/StorableCopier.java index 7152113..f03790d 100644 --- a/src/main/java/com/amazon/carbonado/gen/StorableCopier.java +++ b/src/main/java/com/amazon/carbonado/gen/StorableCopier.java @@ -184,7 +184,23 @@ public abstract class StorableCopier<S extends Storable, T extends Storable> { mWrapperInfo = StorableIntrospector.examine(wrapper);
mDelegateInfo = StorableIntrospector.examine(delegate);
- mClassInjector = ClassInjector.create(wrapper.getName(), wrapper.getClassLoader());
+ ClassLoader loader = wrapper.getClassLoader();
+ try {
+ loader.loadClass(delegate.getName());
+ } catch (ClassNotFoundException e) {
+ loader = delegate.getClassLoader();
+ try {
+ loader.loadClass(wrapper.getName());
+ } catch (ClassNotFoundException e2) {
+ // This could be fixed by creating an intermediate class loader, but
+ // other issues might crop up.
+ throw new IllegalStateException
+ ("Unable for find common class loader for source and target types: " +
+ wrapper.getClass() + ", " + delegate.getClass());
+ }
+ }
+
+ mClassInjector = ClassInjector.create(wrapper.getName(), loader);
mClassFile = CodeBuilderUtil.createStorableClassFile
(mClassInjector, mWrapperInfo.getStorableType(),
@@ -192,9 +208,7 @@ public abstract class StorableCopier<S extends Storable, T extends Storable> { }
Constructor<? extends W> generate() {
- TypeDesc wrapperType = TypeDesc.forClass(mWrapperInfo.getStorableType());
TypeDesc delegateType = TypeDesc.forClass(mDelegateInfo.getStorableType());
- TypeDesc classType = TypeDesc.forClass(Class.class);
mClassFile.addField(Modifiers.PRIVATE.toFinal(true), "delegate", delegateType);
|