You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by th...@apache.org on 2014/05/31 05:09:15 UTC

git commit: TAP5-2330 : NullPointerException when updating a Zone with no clientId TAP5-2342 : NPE on org.apache.tapestry5.json.JSONObject.printValue(JSONObject.java:950)

Repository: tapestry-5
Updated Branches:
  refs/heads/master d96b5534f -> 01a1439c4


TAP5-2330 : NullPointerException when updating a Zone with no clientId
TAP5-2342 : NPE on org.apache.tapestry5.json.JSONObject.printValue(JSONObject.java:950)


Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo
Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/01a1439c
Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/01a1439c
Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/01a1439c

Branch: refs/heads/master
Commit: 01a1439c4a520cf5425415e0ed6a9fa51d386df1
Parents: d96b553
Author: Thiago H. de Paula Figueiredo <th...@apache.org>
Authored: Sat May 31 00:07:47 2014 -0300
Committer: Thiago H. de Paula Figueiredo <th...@apache.org>
Committed: Sat May 31 00:07:47 2014 -0300

----------------------------------------------------------------------
 .../tapestry5/corelib/components/Zone.java      |  6 ++++++
 tapestry-core/src/test/app1/nested/ZoneDemo.tml |  1 +
 .../tapestry5/integration/app1/ZoneTests.java   | 20 ++++++++++++++++++++
 .../integration/app1/pages/nested/ZoneDemo.java |  6 ++++++
 .../org/apache/tapestry5/json/JSONObject.java   |  6 ++++++
 5 files changed, 39 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/01a1439c/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Zone.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Zone.java b/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Zone.java
index f79b286..a04524a 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Zone.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Zone.java
@@ -250,6 +250,12 @@ public class Zone implements ClientBodyElement
     {
         if (resources.isBound("id"))
             return idParameter;
+        
+        // TAP4-2342. I know this won't work with a Zone with no given clientId and that was already 
+        // via AJAX inside an outer Zone, but it's still better than nothing.
+        if (clientId == null) {
+            clientId = resources.getId();
+        }
 
         return clientId;
     }

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/01a1439c/tapestry-core/src/test/app1/nested/ZoneDemo.tml
----------------------------------------------------------------------
diff --git a/tapestry-core/src/test/app1/nested/ZoneDemo.tml b/tapestry-core/src/test/app1/nested/ZoneDemo.tml
index 049cb69..cd4beaf 100644
--- a/tapestry-core/src/test/app1/nested/ZoneDemo.tml
+++ b/tapestry-core/src/test/app1/nested/ZoneDemo.tml
@@ -87,6 +87,7 @@
         MultiZone update with id of non-Zone
         element
     </t:actionlink>
+    <t:actionlink class="btn btn-default" t:id="updateViaAjaxResponseRenderer" zone="output">Update via AjaxResponseRenderer</t:actionlink>
 </div>
 
 <div id="notAZone"/>

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/01a1439c/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/ZoneTests.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/ZoneTests.java b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/ZoneTests.java
index 1ec0c75..77acefe 100644
--- a/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/ZoneTests.java
+++ b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/ZoneTests.java
@@ -323,4 +323,24 @@ public class ZoneTests extends App1TestCase
         assertText("zone-update-message", "Zone updated.");
     }
 
+    /**
+     * TAP5-2330
+     */
+    @Test
+    public void update_zone_with_no_clientid()
+    {
+        openLinks("Zone Demo");
+
+        assertText("zone-update-message", "");
+
+        click("link=Update via AjaxResponseRenderer");
+
+        waitForAjaxRequestsToComplete();
+
+        assertText("zone-update-message", "Zone updated.");
+        
+        assertEquals("Selected: AjaxResponseRenderer", getText("output"));
+        
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/01a1439c/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/nested/ZoneDemo.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/nested/ZoneDemo.java b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/nested/ZoneDemo.java
index 4e2ad9e..e13ed76 100644
--- a/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/nested/ZoneDemo.java
+++ b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/nested/ZoneDemo.java
@@ -222,4 +222,10 @@ public class ZoneDemo
     {
         return new MultiZoneUpdate("notAZone", forNotAZone);
     }
+    
+    void onActionFromUpdateViaAjaxResponseRenderer()
+    {
+        name = "AjaxResponseRenderer";
+        ajaxResponseRenderer.addRender(output);
+    }
 }

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/01a1439c/tapestry-json/src/main/java/org/apache/tapestry5/json/JSONObject.java
----------------------------------------------------------------------
diff --git a/tapestry-json/src/main/java/org/apache/tapestry5/json/JSONObject.java b/tapestry-json/src/main/java/org/apache/tapestry5/json/JSONObject.java
index 8c42bc4..651260b 100644
--- a/tapestry-json/src/main/java/org/apache/tapestry5/json/JSONObject.java
+++ b/tapestry-json/src/main/java/org/apache/tapestry5/json/JSONObject.java
@@ -913,6 +913,12 @@ public final class JSONObject extends JSONCollection
      */
     static void printValue(JSONPrintSession session, Object value)
     {
+    	
+    	// TAP5-2342: a little more robustness by treating null as JSONObject.NULL and avoinding an NPE.
+    	if (value == null) {
+    		value = NULL;
+    	}
+    	
         if (value instanceof JSONObject)
         {
             ((JSONObject) value).print(session);