From d8b0a17836099a976b415dbb45a6f7e0645e3ce6 Mon Sep 17 00:00:00 2001 From: "Brian S. O'Neill" Date: Sat, 8 Jan 2011 18:50:19 +0000 Subject: Fix class loader issues. --- .../com/amazon/carbonado/gen/StorableCopier.java | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'src/main/java') 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 { 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 { } Constructor 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); -- cgit v1.2.3