myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mstar...@apache.org
Subject svn commit: r1070950 - in /myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/facelets: DatePropertyTagRule.java StringArrayPropertyTagRule.java
Date Tue, 15 Feb 2011 16:11:07 GMT
Author: mstarets
Date: Tue Feb 15 16:11:06 2011
New Revision: 1070950

URL: http://svn.apache.org/viewvc?rev=1070950&view=rev
Log:
TRINIDAD-2034 - DatePropertyTagRule and StringArrayPropertyTagRule cache mutable objects

Modified:
    myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/facelets/DatePropertyTagRule.java
    myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/facelets/StringArrayPropertyTagRule.java

Modified: myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/facelets/DatePropertyTagRule.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/facelets/DatePropertyTagRule.java?rev=1070950&r1=1070949&r2=1070950&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/facelets/DatePropertyTagRule.java
(original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/facelets/DatePropertyTagRule.java
Tue Feb 15 16:11:06 2011
@@ -59,14 +59,17 @@ class DatePropertyTagRule
     
     public void applyMetadata(FaceletContext ctx, Object instance)
     {
-      if (_params == null)
+      if (_time == null)
       {
         Date date = _coerceToDate(_attribute.getValue(), _adjustToEnd);
-        _params = new Object[]{date};
+        _time = (date == null) ? _UNKNOWN_TIME : date.getTime();
       }
       try
       {
-        _method.invoke(instance, _params);
+        // TRINIDAD-2034 - create a new instance of Date every time to avoid issues
+        // with sharing mutable objects
+        Object params[] = new Object[]{(_time.longValue() == _UNKNOWN_TIME) ? null : new
Date(_time)};
+        _method.invoke(instance, params);
       }
       catch (InvocationTargetException e)
       {
@@ -81,7 +84,8 @@ class DatePropertyTagRule
     private final Method       _method;
     private final TagAttribute _attribute;
     private final boolean      _adjustToEnd;
-    private       Object[]     _params;
+    private       Long         _time;
+    private static final long  _UNKNOWN_TIME = -1;
   }
   
   public Metadata applyRule(String name, TagAttribute attribute,

Modified: myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/facelets/StringArrayPropertyTagRule.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/facelets/StringArrayPropertyTagRule.java?rev=1070950&r1=1070949&r2=1070950&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/facelets/StringArrayPropertyTagRule.java
(original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/facelets/StringArrayPropertyTagRule.java
Tue Feb 15 16:11:06 2011
@@ -21,8 +21,10 @@ package org.apache.myfaces.trinidadinter
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 
+import java.util.List;
 import java.util.ArrayList;
 import java.util.StringTokenizer;
+import java.util.Collections;
 
 import javax.faces.view.facelets.FaceletContext;
 import javax.faces.view.facelets.Metadata;
@@ -51,15 +53,17 @@ final class StringArrayPropertyTagRule e
     @Override
     public void applyMetadata(FaceletContext ctx, Object instance)
     {
-      if (_params == null)
+      if (_itemList == null)
       {
-        String[] strArray = _coerceToStringArray(_attribute.getValue());
-        _params = new Object[]{strArray};
+        _itemList = _coerceToStringArray(_attribute.getValue());
       }
       
       try
       {
-        _method.invoke(instance, _params);
+        // TRINIDAD-2034 - create a new String array instance every time to avoid issues
+        // with sharing mutable objects
+        Object params = new Object[]{_itemList.isEmpty() ? null : _itemList.toArray(new String[_itemList.size()])};
+        _method.invoke(instance, params);
       }
       catch (InvocationTargetException e)
       {
@@ -73,7 +77,7 @@ final class StringArrayPropertyTagRule e
 
     private final Method       _method;
     private final TagAttribute _attribute;
-    private       Object[]     _params;
+    private       List<String> _itemList;
   }
    
 
@@ -98,10 +102,10 @@ final class StringArrayPropertyTagRule e
     return null;
   }
 
-  static private String[] _coerceToStringArray(String str)
+  static private List<String> _coerceToStringArray(String str)
   {
     if (str == null)
-      return null;
+      return Collections.emptyList();
 
     ArrayList<String> list = new ArrayList<String>();
     StringTokenizer tokens = new StringTokenizer(str);
@@ -110,7 +114,7 @@ final class StringArrayPropertyTagRule e
       list.add(tokens.nextToken());
     }
     
-    return list.toArray(new String[list.size()]);
+    return list;
   }
 
   static private final Class<? extends String[]> _STRING_ARRAY_TYPE = (new String[0]).getClass();



Mime
View raw message