On Wed, Aug 3, 2011 at 10:30 AM, Rickard Öberg <[email protected]> wrote: > > Hi, > > In the current API we have a number of methods that return null, and so the > client has to do null checks before continuing. One example would be > descriptor access methods in the Qi4j API class. Same with > currentUnitOfWork(). > > I suggest that all of these are changed to throw IllegalArgumentException or > IllegalStateException (according to what makes sense) instead, so that client > code can rely on objects being returned correctly in the "normal case". > > WDYT?
Having not used Qi4J, my contribution may be of rather small interest, anyway ... >From what I understand, most of what Qi4j uses are interfaces. As a consequences, the methods you mention returns proxies over those interfaces. In such a case, it would be great to use the NullObject pattern : instead of returning null, you return a proxy implementing the same interface that always return zero values or empty collections (but not null). Mor details on c2wiki : http://c2.com/cgi/wiki?NullObject When not possible, it would be better to return a Qi4J specific exception, that would be able to carry far more meaning than standard Java one and maybe provide continuation mechanisms (think about an exception that would contain the aforementionned NullObject, or an exception that would provide additionnal debug infos ina structured form, as opposed to the String+StackTrace we usually get). -- Nicolas Delsaux _______________________________________________ qi4j-dev mailing list [email protected] http://lists.ops4j.org/mailman/listinfo/qi4j-dev

