I ran into a problem with JSONArray today that I think deserves a bug report, 
but I'm not exactly sure what the correct/expected behavior should be, so I'm 
not sure how to file the bug.

This test case demonstrates the issue:

    def "test add null to array"() {
        setup:
        String n = null
        JSONArray obj = new JSONArray()
        obj.put(n)

        when:
        String result = obj.toString()

        then:
        "[]" == result
    }


I think I might expect the actual result to be [ null ], but you don't get that 
either, what you do get is a NULL pointer exception.

java.lang.NullPointerException
        at org.apache.tapestry5.json.JSONObject.printValue(JSONObject.java:887)
        at org.apache.tapestry5.json.JSONArray.print(JSONArray.java:436)
        at 
org.apache.tapestry5.json.JSONCollection.toString(JSONCollection.java:47)
        at com.starpoint.business.BusLogic1Test.test print empty 
array(BusLogic1Test.groovy:35)

Looking at the code, it would appear that you don't want null to be a valid 
value (though I would argue it's perfectly fine),

    public JSONArray put(Object value)
    {
        assert value != null;

        JSONObject.testValidity(value);

        list.add(value);

        return this;
    }


I don't run with assertions enabled (who does??), but apparently 
JSONObject.testValidity passes just fine. You don't run into a problem until 
you actually try to print the array (or return it as an ajax response).

What is the correct behavior?
Tony

Since 1982, Starpoint Solutions has been a trusted source of human capital and 
solutions. We are committed to our clients, employees, environment, community 
and social concerns.  We foster an inclusive culture based on trust, respect, 
honesty and solid performance. Learn more about Starpoint and our social 
responsibility at http://www.starpoint.com/social_responsibility

This email message from Starpoint Solutions LLC is for the sole use of  the 
intended recipient(s) and may contain confidential and privileged  information. 
 Any unauthorized review, use, disclosure or distribution is prohibited.  If 
you are not the intended recipient, please contact the sender by reply email 
and destroy all copies of the original message.  Opinions, conclusions and 
other information in this message that do not relate to the official business 
of Starpoint Solutions shall be understood as neither given nor endorsed by it.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org

Reply via email to