You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lu...@apache.org on 2012/05/22 16:40:29 UTC

svn commit: r1341497 - in /myfaces/core/branches/2.0.x: api/src/main/java/javax/faces/component/ impl/src/main/java/org/apache/myfaces/webapp/

Author: lu4242
Date: Tue May 22 14:40:29 2012
New Revision: 1341497

URL: http://svn.apache.org/viewvc?rev=1341497&view=rev
Log:
MYFACES-3549 Alternative solution to bugs MYFACES-3262 and MYFACES-3510 (Thanks to Jesús Pérez Alcaide (ISBAN) for provide this patch)

Modified:
    myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/component/_ComponentAttributesMap.java
    myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/component/_PropertyDescriptorHolder.java
    myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/webapp/AbstractFacesInitializer.java

Modified: myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/component/_ComponentAttributesMap.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/component/_ComponentAttributesMap.java?rev=1341497&r1=1341496&r2=1341497&view=diff
==============================================================================
--- myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/component/_ComponentAttributesMap.java (original)
+++ myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/component/_ComponentAttributesMap.java Tue May 22 14:40:29 2012
@@ -23,7 +23,6 @@ import java.beans.IntrospectionException
 import java.beans.Introspector;
 import java.beans.PropertyDescriptor;
 import java.io.Serializable;
-import java.lang.ref.SoftReference;
 import java.lang.reflect.Method;
 import java.util.Collection;
 import java.util.Collections;
@@ -81,9 +80,8 @@ class _ComponentAttributesMap implements
     private transient Map<String, _PropertyDescriptorHolder> _propertyDescriptorMap = null;
 
     // Cache for component property descriptors
-    private static Map<ClassLoader, SoftReference<Map<Class<?>, Map<String, _PropertyDescriptorHolder>>>>
-            propertyDescriptorCacheMap = new WeakHashMap<ClassLoader, SoftReference<Map<Class<?>, 
-                Map<String, _PropertyDescriptorHolder>>>>();
+    private static Map<Class<?>, Map<String, _PropertyDescriptorHolder>> propertyDescriptorCache =
+        new WeakHashMap<Class<?>, Map<String, _PropertyDescriptorHolder>>();
     
     private boolean _isCompositeComponent;
     private boolean _isCompositeComponentSet;
@@ -98,11 +96,6 @@ class _ComponentAttributesMap implements
         _component = component;
     }
     
-    public static void clearPropertyDescriptorCache()
-    {
-        propertyDescriptorCacheMap.remove(_ClassUtils.getContextClassLoader());
-    }
-
     /**
      * Create a map backed by the specified component. Attributes already
      * associated with the component are provided in the specified Map
@@ -491,24 +484,6 @@ class _ComponentAttributesMap implements
     {
         if (_propertyDescriptorMap == null)
         {
-            ClassLoader cl = _ClassUtils.getContextClassLoader();
-            SoftReference<Map<Class<?>, Map<String, _PropertyDescriptorHolder>>> 
-                    propertyDescriptorCacheRef =
-                        propertyDescriptorCacheMap.get(cl);
-            Map<Class<?>, Map<String, _PropertyDescriptorHolder>> 
-                    propertyDescriptorCache = (propertyDescriptorCacheRef != null) ?
-                        propertyDescriptorCacheRef.get() : null;
-            if (propertyDescriptorCache == null)
-            {
-                 propertyDescriptorCache = new WeakHashMap<Class<?>, 
-                                 Map<String, _PropertyDescriptorHolder>>();
-                 synchronized(propertyDescriptorCacheMap)
-                 {
-                     propertyDescriptorCacheMap.put(cl, new SoftReference
-                         <Map<Class<?>, Map<String, _PropertyDescriptorHolder>>>
-                             (propertyDescriptorCache));
-                 }
-            }
             // Try to get descriptor map from cache
             _propertyDescriptorMap = propertyDescriptorCache.get(_component.getClass());
             // Cache miss: create descriptor map and put it in cache
@@ -633,7 +608,7 @@ class _ComponentAttributesMap implements
     Map<String, Object> getUnderlyingMap()
     {
         StateHelper stateHelper = _component.getStateHelper(false);
-        Map attributes = null;
+        Map<String, Object> attributes = null;
         if (stateHelper != null)
         {
             attributes = (Map<String, Object>) stateHelper.get(UIComponentBase.PropertyKeys.attributesMap);

Modified: myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/component/_PropertyDescriptorHolder.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/component/_PropertyDescriptorHolder.java?rev=1341497&r1=1341496&r2=1341497&view=diff
==============================================================================
--- myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/component/_PropertyDescriptorHolder.java (original)
+++ myfaces/core/branches/2.0.x/api/src/main/java/javax/faces/component/_PropertyDescriptorHolder.java Tue May 22 14:40:29 2012
@@ -19,24 +19,26 @@
 package javax.faces.component;
 
 import java.beans.PropertyDescriptor;
+import java.lang.ref.Reference;
+import java.lang.ref.SoftReference;
 import java.lang.reflect.Method;
 
 class _PropertyDescriptorHolder
 {
     private final PropertyDescriptor _descriptor;
-    private final Method _readMethod;
-    private Method _writeMethod;
+    private Reference<Method> _readMethodRef;
+    private Reference<Method> _writeMethodRef;
 
     public _PropertyDescriptorHolder(PropertyDescriptor descriptor)
     {
         _descriptor = descriptor;
-        _readMethod = _descriptor.getReadMethod();
+        _readMethodRef = new SoftReference<Method>(_descriptor.getReadMethod());
     }
 
     public _PropertyDescriptorHolder(PropertyDescriptor descriptor, Method readMethod)
     {
         _descriptor = descriptor;
-        _readMethod = readMethod;
+        _readMethodRef = new SoftReference<Method>(readMethod);
     }
     
     public String getName()
@@ -46,21 +48,28 @@ class _PropertyDescriptorHolder
     
     public Method getReadMethod()
     {
-        return _readMethod;
+        Method readMethod = _readMethodRef.get();
+        if (readMethod == null)
+        {
+            readMethod = _descriptor.getReadMethod();
+            _readMethodRef = new SoftReference<Method>(readMethod);
+        }
+        return readMethod;
     }
     
     public Method getWriteMethod()
     {
-        // In facelets, the Method instance used to write the variable is stored
-        // in a variable (see org.apache.myfaces.view.facelets.tag.BeanPropertyTagRule),
-        // so the impact of this synchronized call at the end is minimal compared with 
-        // getReadMethod. That's the reason why cache it here in a lazy way is enough
-        // instead retrieve it as soon as this holder is created.
-        if (_writeMethod == null)
+        if (_writeMethodRef == null || _writeMethodRef.get() == null)
         {
-            _writeMethod = _descriptor.getWriteMethod(); 
+            // In facelets, the Method instance used to write the variable is stored
+            // in a variable (see org.apache.myfaces.view.facelets.tag.BeanPropertyTagRule),
+            // so the impact of this synchronized call at the end is minimal compared with 
+            // getReadMethod. That's the reason why cache it here in a lazy way is enough
+            // instead retrieve it as soon as this holder is created.
+            Method writeMethod = _descriptor.getWriteMethod();
+            _writeMethodRef = new SoftReference<Method>(writeMethod);
         }
-        return _writeMethod;
+        return _writeMethodRef.get();
     }
     
     public PropertyDescriptor getPropertyDescriptor()

Modified: myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/webapp/AbstractFacesInitializer.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/webapp/AbstractFacesInitializer.java?rev=1341497&r1=1341496&r2=1341497&view=diff
==============================================================================
--- myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/webapp/AbstractFacesInitializer.java (original)
+++ myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/webapp/AbstractFacesInitializer.java Tue May 22 14:40:29 2012
@@ -18,7 +18,6 @@
  */
 package org.apache.myfaces.webapp;
 
-import java.lang.reflect.Method;
 import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFWebConfigParam;
 import org.apache.myfaces.config.FacesConfigValidator;
 import org.apache.myfaces.config.FacesConfigurator;
@@ -52,7 +51,6 @@ import java.util.Locale;
 import java.util.Map;
 import java.util.logging.Level;
 import java.util.logging.Logger;
-import org.apache.myfaces.shared.util.ClassUtils;
 
 /**
  * Performs common initialization tasks.
@@ -317,21 +315,6 @@ public abstract class AbstractFacesIniti
         // clear the cache of MetaRulesetImpl in order to prevent a memory leak
         MetaRulesetImpl.clearMetadataTargetCache();
 
-        try
-        {
-            Class clazz = ClassUtils.simpleClassForName(
-                    "javax.faces.component._ComponentAttributesMap");
-            if (clazz != null)
-            {
-                Method clearMethod = clazz.getMethod("clearPropertyDescriptorCache", new Class[]{});
-                clearMethod.setAccessible(true);
-                clearMethod.invoke(null, new Object[]{});
-            }
-        }
-        catch(Throwable t)
-        {
-            // cannot clear cache, just swallow it, the gc will do the job for us
-        }
         // TODO is it possible to make a real cleanup?
     }