Repository: wicket Updated Branches: refs/heads/master 12d98aab3 -> 73b8ebf87
WICKET-5850 Fix class loading issue in LazyInitProxyFactory in case of multimodule deployment Project: http://git-wip-us.apache.org/repos/asf/wicket/repo Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/73b8ebf8 Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/73b8ebf8 Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/73b8ebf8 Branch: refs/heads/master Commit: 73b8ebf87d6d21a72bfd9cd21a961e2b260f6591 Parents: 12d98aa Author: Alexander Morozov <[email protected]> Authored: Fri Mar 6 00:16:59 2015 +0600 Committer: Sven Meier <[email protected]> Committed: Thu Mar 5 22:20:20 2015 +0100 ---------------------------------------------------------------------- .../wicket/proxy/LazyInitProxyFactory.java | 65 ++++++++++++-------- 1 file changed, 40 insertions(+), 25 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/wicket/blob/73b8ebf8/wicket-ioc/src/main/java/org/apache/wicket/proxy/LazyInitProxyFactory.java ---------------------------------------------------------------------- diff --git a/wicket-ioc/src/main/java/org/apache/wicket/proxy/LazyInitProxyFactory.java b/wicket-ioc/src/main/java/org/apache/wicket/proxy/LazyInitProxyFactory.java index b4e821b..3df433b 100644 --- a/wicket-ioc/src/main/java/org/apache/wicket/proxy/LazyInitProxyFactory.java +++ b/wicket-ioc/src/main/java/org/apache/wicket/proxy/LazyInitProxyFactory.java @@ -30,9 +30,9 @@ import net.sf.cglib.core.Predicate; import net.sf.cglib.proxy.Enhancer; import net.sf.cglib.proxy.MethodInterceptor; import net.sf.cglib.proxy.MethodProxy; + import org.apache.wicket.Application; import org.apache.wicket.WicketRuntimeException; -import org.apache.wicket.application.IClassResolver; import org.apache.wicket.core.util.lang.WicketObjects; import org.apache.wicket.model.IModel; import org.apache.wicket.util.io.IClusterable; @@ -137,20 +137,7 @@ public class LazyInitProxyFactory try { - ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); - if (Application.exists()) - { - IClassResolver classResolver = Application.get() - .getApplicationSettings() - .getClassResolver(); - - if (classResolver != null) - { - classLoader = classResolver.getClassLoader(); - } - } - - return Proxy.newProxyInstance(classLoader, + return Proxy.newProxyInstance(resolveClassLoader(), new Class[] { type, Serializable.class, ILazyInitProxy.class, IWriteReplace.class }, handler); } @@ -173,25 +160,34 @@ public class LazyInitProxyFactory CGLibInterceptor handler = new CGLibInterceptor(type, locator); Enhancer e = new Enhancer(); + e.setClassLoader(resolveClassLoader()); e.setInterfaces(new Class[] { Serializable.class, ILazyInitProxy.class, IWriteReplace.class }); e.setSuperclass(type); e.setCallback(handler); - e.setNamingPolicy(new DefaultNamingPolicy() - { - @Override - public String getClassName(final String prefix, final String source, - final Object key, final Predicate names) - { - return super.getClassName("WICKET_" + prefix, source, key, names); - } - }); + e.setNamingPolicy(WicketNamingPolicy.INSTANCE); return e.create(); } } - /** + private static ClassLoader resolveClassLoader() + { + ClassLoader classLoader = null; + if (Application.exists()) + { + classLoader = Application.get().getApplicationSettings() + .getClassResolver().getClassLoader(); + } + + if (classLoader == null) { + classLoader = Thread.currentThread().getContextClassLoader(); + } + + return classLoader; + } + + /** * This interface is used to make the proxy forward writeReplace() call to the handler instead * of invoking it on itself. This allows us to serialize the replacement object instead of the * proxy itself in case the proxy subclass is deserialized on a VM that does not have it @@ -524,4 +520,23 @@ public class LazyInitProxyFactory return (method.getReturnType() == Object.class) && (method.getParameterTypes().length == 0) && method.getName().equals("writeReplace"); } + + private static final class WicketNamingPolicy extends DefaultNamingPolicy + { + + private static final WicketNamingPolicy INSTANCE = new WicketNamingPolicy(); + + private WicketNamingPolicy() + { + super(); + } + + @Override + public String getClassName(final String prefix, final String source, final Object key, + final Predicate names) + { + return super.getClassName("WICKET_" + prefix, source, key, names); + } + } + }
