You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tuscany.apache.org by Mark Combellack <mc...@apache.org> on 2008/04/05 21:21:37 UTC

How should parameters be validate for methods on the core-SPI? - Document in JavaDoc and: Throw IllegalArgumentException? Do nothing? Use Asserts?

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

 


Re: How should parameters be validate for methods on the core-SPI? - Document in JavaDoc and: Throw IllegalArgumentException? Do nothing? Use Asserts?

Posted by Mike Edwards <mi...@gmail.com>.
Mark Combellack 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
> 
Mark,

I prefer the defensive programming style and I recommend checking for 
null and throwing the IllegalArgumentException.   The Javadoc should be 
updated to say this...


Yours,   Mike.

---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-dev-help@ws.apache.org


Re: How should parameters be validate for methods on the core-SPI? - Document in JavaDoc and: Throw IllegalArgumentException? Do nothing? Use Asserts?

Posted by Vamsavardhana Reddy <c1...@gmail.com>.
I would go with throwing an IllegalArgumentException.

++Vamsi

On Sun, Apr 6, 2008 at 12:51 AM, Mark Combellack <mc...@apache.org>
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
>
>
>
>

Re: How should parameters be validate for methods on the core-SPI? - Document in JavaDoc and: Throw IllegalArgumentException? Do nothing? Use Asserts?

Posted by Adriano Crestani <ad...@apache.org>.
+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 <mc...@apache.org>
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
>
>
>
>

Re: How should parameters be validate for methods on the core-SPI? - Document in JavaDoc and: Throw IllegalArgumentException? Do nothing? Use Asserts?

Posted by Jean-Sebastien Delfino <js...@apache.org>.
Mark Combellack wrote:
...
> 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.

+1

> The question is - what should the Tuscany code do? Options include:
...
> 1) Do an if check and throw an IllegalArgumentException.
...
> Personally, I would update the JavaDoc and do option 1 - throw
> IllegalArgumentException.
> 

+1 for option 1.

-- 
Jean-Sebastien

---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-dev-help@ws.apache.org