You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by ma...@apache.org on 2007/07/19 13:29:59 UTC

svn commit: r557580 - in /myfaces/core/branches/1_2_1/api/src: main/java/javax/faces/component/_ComponentAttributesMap.java test/java/javax/faces/component/UIComponentAttributesTest.java

Author: matzew
Date: Thu Jul 19 04:29:58 2007
New Revision: 557580

URL: http://svn.apache.org/viewvc?view=rev&rev=557580
Log:
MYFACES-1681

thanks to Sun's Ryan Lubke, for pointing out, that MyFaces is too restrictive with respect
to null values (on UIComponent.getAttributes().put(...)).
The RI will only throw the NPE against a null value *if* there isn't an associated property. 
Myfaces does this as well, now.

JavaDoc is misleading, so Ryan will file a "Spec Bug" as well.

added fix for the problem
added test-case for this scenario.

Added:
    myfaces/core/branches/1_2_1/api/src/test/java/javax/faces/component/UIComponentAttributesTest.java
Modified:
    myfaces/core/branches/1_2_1/api/src/main/java/javax/faces/component/_ComponentAttributesMap.java

Modified: myfaces/core/branches/1_2_1/api/src/main/java/javax/faces/component/_ComponentAttributesMap.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/1_2_1/api/src/main/java/javax/faces/component/_ComponentAttributesMap.java?view=diff&rev=557580&r1=557579&r2=557580
==============================================================================
--- myfaces/core/branches/1_2_1/api/src/main/java/javax/faces/component/_ComponentAttributesMap.java (original)
+++ myfaces/core/branches/1_2_1/api/src/main/java/javax/faces/component/_ComponentAttributesMap.java Thu Jul 19 04:29:58 2007
@@ -292,10 +292,15 @@
      */
     public Object put(Object key, Object value)
     {
-        checkKeyAndValue(key, value);
+        checkKey(key);
 
         PropertyDescriptor propertyDescriptor = getPropertyDescriptor((String)key);
-        if (propertyDescriptor != null)
+        if(propertyDescriptor == null)
+        {
+          if(value==null)
+              throw new NullPointerException("value is null for a not available property: " + key);
+        }
+        else
         {
             if (propertyDescriptor.getReadMethod() != null)
             {
@@ -405,16 +410,6 @@
                     " of component " + _component.getClientId(facesContext) +" to value : "+value+" with type : "+
                     (value==null?"null":value.getClass().getName()), e);
         }
-    }
-
-
-    private void checkKeyAndValue(Object key, Object value)
-    {
-        //http://issues.apache.org/jira/browse/MYFACES-458: obviously, the spec is a little unclear here,
-        // but value == null should be allowed - if there is a TCK-test failing due to this, we should
-        // apply for getting the TCK-test dropped
-        if (value == null) throw new NullPointerException("value");
-        checkKey(key);
     }
 
     private void checkKey(Object key)

Added: myfaces/core/branches/1_2_1/api/src/test/java/javax/faces/component/UIComponentAttributesTest.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/1_2_1/api/src/test/java/javax/faces/component/UIComponentAttributesTest.java?view=auto&rev=557580
==============================================================================
--- myfaces/core/branches/1_2_1/api/src/test/java/javax/faces/component/UIComponentAttributesTest.java (added)
+++ myfaces/core/branches/1_2_1/api/src/test/java/javax/faces/component/UIComponentAttributesTest.java Thu Jul 19 04:29:58 2007
@@ -0,0 +1,40 @@
+package javax.faces.component;
+
+import javax.faces.component.html.HtmlInputText;
+
+import org.apache.shale.test.base.AbstractJsfTestCase;
+
+public class UIComponentAttributesTest extends AbstractJsfTestCase{
+  
+    public UIComponentAttributesTest(String arg0)
+    {
+        super(arg0);
+    }
+
+    private HtmlInputText input;
+    
+    
+    protected void setUp() throws Exception {
+        super.setUp();
+        input = new HtmlInputText();
+        input.setId("testId");
+    }
+
+    protected void tearDown() throws Exception {
+        super.tearDown();
+        input = null;
+    }
+
+    public void testSetNullAttributeOnValidProperty(){
+        input.getAttributes().put("style", null);
+  }
+    public void testSetNullAttributeOnInvalidProperty(){
+        try{
+            input.getAttributes().put("someBogus", null);
+            fail("Should have thrown NullPointerException");
+        }
+        catch(NullPointerException npe){
+            //expected
+        }
+    }
+}
\ No newline at end of file