Hi Ken,

somethings I get the feeling you use this mailinglist like a chat system providing much info in many many small chunks. Can't you just gather all information first and afterwards throw it to the mailinglist? And for this particular topic, I miss the stacktrace maybe I did not see it. Can you show the complete NPE stacktrace? And how is "property binding" related to your NPE?

When looking at CollectionGridDataSource.java I see:

    public CollectionGridDataSource(final Collection collection)
    {
        assert collection != null;
        list = CollectionFactory.newList(collection);
    }

so the ctor is guarded by an assert. When you pass "-ea" as VM argument (enable asserts) you will get an assertion error. So honestly I do not believe "null" is an acceptable value and the NPE occurs later on in the CTOR of ArrayList. Maybe I will be corrected but due to Tapestry magic you get some kind of a default GridDataSource when your method does not provide one, therfore the null check works in your particular case. If you do not want to rely on T5 magic I prefer generally to make hidden things obvious so why not simply writing:

return new CollectionGridDataSource(null != collection ? collection : Collections.EMPTY_LIST)


And when you "hate null checks" you can modify your collection creation code to explicitly return a empty collection in case it's null. This does not prevent you from the check in general, but this "null check code" moves deeper into the service layer of your app which is good anyway and you never have to think about this kind of NPE in your client, because you know "null collection" will never returned. That's the way I treat it, too. Either you spread null checks or you create empty collections. For the latter do it at the source and don't let the 'null' escape....



Jens




Am 29.05.13 02:36, schrieb Ken in Nashua:
alright... i hate doing null checks...

because if you get into the habit of it...

you never know if your actually writing a legit piece of code

So I did it anyway

     public GridDataSource getSource() {
         if (collection != null )
             return new CollectionGridDataSource(collection);
         else return null;
     }

and it works..
my form comes up... initialized..
table is empty.. as expected with the nice message "No objects to render

But is my code legit?

"
                                        


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

Reply via email to