On 8/3/11 16:47 , Niclas Hedhman wrote:
On Wed, Aug 3, 2011 at 4:30 PM, Rickard Öberg<[email protected]>  wrote:
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".

Well, is it effectively any better to get such an Exception served than an NPE??

Returning 'null' at least allows the client to "recover", for instance
what is happening in UnitOfWorkPropagation, which otherwise will have
an "expensive" exception thrown in many cases...

Right, but my guess is that most of the time when you are asking for something, you expect to get it back and then work with it. As it is, the client code has to do null checks before continuining to use it, and if not it might blow up quite a bit later.

For specific cases like the above, I would prefer to have a boolean check which can be checked before calling currentUnitOfWork(), i.e. UnitOfWorkFactory.isUnitOfWorkActive() or something like that.

/Rickard

_______________________________________________
qi4j-dev mailing list
[email protected]
http://lists.ops4j.org/mailman/listinfo/qi4j-dev

Reply via email to