Repository: wicket
Updated Branches:
  refs/heads/wicket-6.x 7613966c9 -> c0f187b57


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/c0f187b5
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/c0f187b5
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/c0f187b5

Branch: refs/heads/wicket-6.x
Commit: c0f187b57cb55151db775306a70c57cb3d1d3f4e
Parents: 7613966
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:53 2015 +0100

----------------------------------------------------------------------
 .../wicket/proxy/LazyInitProxyFactory.java      | 65 ++++++++++++--------
 1 file changed, 40 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/c0f187b5/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);
+               }
+       }
+
 }

Reply via email to