myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From m..@apache.org
Subject svn commit: r511672 - in /myfaces/core/branches/jsf12/impl/src: main/java/org/apache/myfaces/el/convert/VariableResolverToELResolver.java test/java/org/apache/myfaces/el/unified/ResolverBuilderBaseTest.java
Date Mon, 26 Feb 2007 00:34:59 GMT
Author: mbr
Date: Sun Feb 25 16:34:59 2007
New Revision: 511672

URL: http://svn.apache.org/viewvc?view=rev&rev=511672
Log:
StackOverflowException fixed

Modified:
    myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/el/convert/VariableResolverToELResolver.java
    myfaces/core/branches/jsf12/impl/src/test/java/org/apache/myfaces/el/unified/ResolverBuilderBaseTest.java

Modified: myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/el/convert/VariableResolverToELResolver.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/el/convert/VariableResolverToELResolver.java?view=diff&rev=511672&r1=511671&r2=511672
==============================================================================
--- myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/el/convert/VariableResolverToELResolver.java
(original)
+++ myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/el/convert/VariableResolverToELResolver.java
Sun Feb 25 16:34:59 2007
@@ -26,6 +26,8 @@
 import javax.faces.el.VariableResolver;
 
 import java.beans.FeatureDescriptor;
+import java.util.Collection;
+import java.util.HashSet;
 import java.util.Iterator;
 
 /**
@@ -39,6 +41,15 @@
 public class VariableResolverToELResolver extends ELResolver
 {
 
+    // holds a flag to check if this instance is already called in current thread 
+    private static final ThreadLocal<Collection<String>> propertyGuard = new
ThreadLocal<Collection<String>>() {
+        @Override
+        protected Collection<String> initialValue()
+        {
+            return new HashSet<String>();
+        }
+    };
+    
     private VariableResolver variableResolver;
 
     /**
@@ -57,7 +68,7 @@
             return null;
         if (property == null)
             throw new PropertyNotFoundException();
-        
+
         context.setPropertyResolved(true);
 
         if (!(property instanceof String))
@@ -65,15 +76,13 @@
 
         String strProperty = (String) property;
 
-        // This differs from the spec slightly. I'm wondering if the spec is
-        // wrong because it is legal for the resolveVariable method to return
-        // null. In that case you would not want to setPropertyResolved(true).
+        Object result = null;
         try
         {
-            Object value = variableResolver.resolveVariable(facesContext(context), strProperty);
-            if (value != null)
-            {
-                return value;
+            // only call the resolver if we haven't done it in current stack
+            if(!propertyGuard.get().contains(strProperty)) {
+                propertyGuard.get().add(strProperty);
+                result = variableResolver.resolveVariable(facesContext(context), strProperty);
             }
         }
         catch (javax.faces.el.PropertyNotFoundException e)
@@ -91,8 +100,14 @@
             context.setPropertyResolved(false);
             throw e;
         }
+        finally
+        {
+            propertyGuard.get().remove(strProperty);
+            // set property resolved to false in any case if result is null
+            context.setPropertyResolved(result != null);
+        }
 
-        return null;
+        return result;
     }
 
     // get the FacesContext from the ELContext

Modified: myfaces/core/branches/jsf12/impl/src/test/java/org/apache/myfaces/el/unified/ResolverBuilderBaseTest.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/jsf12/impl/src/test/java/org/apache/myfaces/el/unified/ResolverBuilderBaseTest.java?view=diff&rev=511672&r1=511671&r2=511672
==============================================================================
--- myfaces/core/branches/jsf12/impl/src/test/java/org/apache/myfaces/el/unified/ResolverBuilderBaseTest.java
(original)
+++ myfaces/core/branches/jsf12/impl/src/test/java/org/apache/myfaces/el/unified/ResolverBuilderBaseTest.java
Sun Feb 25 16:34:59 2007
@@ -182,10 +182,11 @@
 
         Object value = resolver.getValue(expectedContext, expectedBase, expectedProperty);
         assertNull(value);
-        assertTrue(expectedContext.isPropertyResolved());
-        assertEquals(2, calledResolvers.size());
+        assertFalse(expectedContext.isPropertyResolved());
+        assertEquals(3, calledResolvers.size());
         assertEquals("config", calledResolvers.get(0));
         assertEquals("variable", calledResolvers.get(1));
+        assertEquals("app", calledResolvers.get(2));
 
         runtimeConfig.setVariableResolver(null);
         resolver = new CompositeELResolver();



Mime
View raw message