+1 for update javadoc and throw an IllegalArgumentException

I'm not familiar with this method, but I suppose a null object should not be
accepted as argument at all. Otherwise, the method should not be throwing a
NullPointerException and it should be fixed.

So, assuming this method should not accept a null argument, the best
practice, for sure, should be to throw an IllegalArgumentException and
explicit it on javadoc

Regards,
Adriano Crestani

On Sat, Apr 5, 2008 at 4:21 PM, Mark Combellack <[EMAIL PROTECTED]>
wrote:

> Hi,
>
>
>
> I was using the core-spi project and ran into a NullPointerException
> because
> I passed a null into a method. Reading the JavaDoc for the method, it did
> not say that I was not allowed to pass a null into the method.
>
>
>
>
>
> The case that I ran into of the
> ContextFactoryExtensionPoint.addFactory(Object factory) method. The
> JavaDoc
> says:
>
>
>
>  /**
>
>   * Add a context factory extension.
>
>   *
>
>   * @param factory The factory to add
>
>   */
>
>
>
> The problem is that it does not provide any details of what happens if a
> null value is passed in for the factory parameter. What actually happens
> in
> the code is that it throws a NullPointerException.
>
>
>
>
>
> As the core-spi is a public API, we should be very clear to the developers
> that use it what will happen.
>
>
>
>
>
>
>
> My question is how should we handle this? The JavaDoc should be updated to
> include information about what will happen if a null is passed in. The
> question is - what should the Tuscany code do? Options include:
>
>
>
>
>
> 1) Do an if check and throw an IllegalArgumentException.
>
>
>
> 2) Don't do anything else - just document it in the JavaDoc. If the user
> is
> "stupid" enough to pass null into a method that should not be passed a
> null
> then they deserve what they get.
>
>
>
> 3) Use Java Asserts. When things start going wrong, enable Asserts and the
> error will be spotted. Since it is an Assert, it has no cost a runtime if
> Asserts are off.
>
>
>
>
>
> Personally, I would update the JavaDoc and do option 1 - throw
> IllegalArgumentException.
>
>
>
>
>
> I'm interested in what other people think and if there is a current policy
> for handling this kind of error in Tuscany?
>
>
>
> Assuming that people are in general agreement with doing option 1, I will
> update the core-spi accordingly.
>
>
>
> Thanks,
>
>
>
> Mark
>
>
>
>

Reply via email to