You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by al...@apache.org on 2007/06/19 16:35:56 UTC

svn commit: r548739 - /incubator/wicket/trunk/jdk-1.4/wicket-spring/src/main/java/org/apache/wicket/spring/SpringBeanLocator.java

Author: almaw
Date: Tue Jun 19 07:35:55 2007
New Revision: 548739

URL: http://svn.apache.org/viewvc?view=rev&rev=548739
Log:
WICKET-625 - Wicket doesn't clean up properly when hot-deploying; hangs onto Class references. (partial fix, work in progress)

Modified:
    incubator/wicket/trunk/jdk-1.4/wicket-spring/src/main/java/org/apache/wicket/spring/SpringBeanLocator.java

Modified: incubator/wicket/trunk/jdk-1.4/wicket-spring/src/main/java/org/apache/wicket/spring/SpringBeanLocator.java
URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/jdk-1.4/wicket-spring/src/main/java/org/apache/wicket/spring/SpringBeanLocator.java?view=diff&rev=548739&r1=548738&r2=548739
==============================================================================
--- incubator/wicket/trunk/jdk-1.4/wicket-spring/src/main/java/org/apache/wicket/spring/SpringBeanLocator.java (original)
+++ incubator/wicket/trunk/jdk-1.4/wicket-spring/src/main/java/org/apache/wicket/spring/SpringBeanLocator.java Tue Jun 19 07:35:55 2007
@@ -16,6 +16,8 @@
  */
 package org.apache.wicket.spring;
 
+import java.lang.ref.WeakReference;
+
 import org.apache.wicket.proxy.IProxyTargetLocator;
 import org.apache.wicket.util.lang.Objects;
 import org.springframework.beans.factory.BeanFactoryUtils;
@@ -33,7 +35,8 @@
  */
 public class SpringBeanLocator implements IProxyTargetLocator
 {
-	private transient Class beanTypeCache;
+	// Weak reference so we don't hold up WebApp classloader garbage collection.
+	private transient WeakReference/*<Class>*/ beanTypeCache;
 
 	private String beanTypeName;
 
@@ -78,7 +81,7 @@
 			throw new IllegalArgumentException("[beanType] argument cannot be null");
 		}
 
-		this.beanTypeCache = beanType;
+		this.beanTypeCache = new WeakReference(beanType);
 		this.beanTypeName = beanType.getName();
 		this.springContextLocator = locator;
 		this.beanName = beanName;
@@ -133,12 +136,18 @@
 	 */
 	public Class getBeanType()
 	{
-		if (beanTypeCache == null)
+		Class clazz = beanTypeCache == null ? null : (Class)beanTypeCache.get();
+		if (clazz == null)
 		{
 			try
 			{
-				beanTypeCache = Class.forName(beanTypeName, true, Thread.currentThread()
+				/* 
+				 * Need to make this scoped, rather than sticking it straight into the WeakReference,
+				 * otherwise it might get garbage collected before we've even returned it!
+				 */
+				clazz = Class.forName(beanTypeName, true, Thread.currentThread()
 						.getContextClassLoader());
+				beanTypeCache = new WeakReference(clazz);
 			}
 			catch (ClassNotFoundException e)
 			{
@@ -148,7 +157,7 @@
 						+ "] bean", e);
 			}
 		}
-		return beanTypeCache;
+		return clazz;
 	}
 
 	/**