You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Marco Speranza <ma...@apache.org> on 2012/02/15 19:25:57 UTC

[Graph] Possible NPE if user requests a vertex that not exists on BaseGraph class

Hi all guys,

I notice that the methods "getConnectedVertices( V v )" and "getEdge( V
source, V target )" into the class BaseGraph are not protect if a user
passes  a vertex that not exists.
Moreover in the first case the system throws a NPE and in the second case
the system accepts the argument but return a null value to the user.

Should it be a good idea put a control and throw a IllegalArgumentEx in
both cases?
WDYT?

Ciao

--
Marco Speranza <marcosperanza@ <ma...@gmail.com>apache.org>
Google Code: http://code.google.com/u/marco.speranza79/

Re: [Graph] Possible NPE if user requests a vertex that not exists on BaseGraph class

Posted by Simone Tripodi <si...@apache.org>.
Hola,

yes, I think so, every wrong behavior in the data structure should
throw GE, according to what we already agreed on on Graph contract.

best,
-Simo

http://people.apache.org/~simonetripodi/
http://simonetripodi.livejournal.com/
http://twitter.com/simonetripodi
http://www.99soft.org/



On Wed, Feb 15, 2012 at 9:50 PM, Marco Speranza
<ma...@gmail.com> wrote:
> hi,
>
> I'd recommend to throw the GraphException, as we reported in the javadoc:
>
> I was thinking to use the method graph.utils.Assertions.checkArgument, it
> throws an IllegalArgumentEx, but  also GraphExpetion sounds good!
>
> one more thing, the method getEdge() creates an instance of VertexPair for
> retrieve the edge, so if the user passes an incorrect vertex the method
> doesn't throw an Excepion but simply returns a null reference to the user.
> Is it necessary to throw the same exception also for that method?
>
> thanks ;)
>
> --
> Marco Speranza <ma...@gmail.com>
>
> Flickr: http://www.flickr.com/photos/marcosperanza79/
> Google Code: http://code.google.com/u/marco.speranza79/
>
>
>
> Il giorno 15/feb/2012, alle ore 20:57, Simone Tripodi ha scritto:
>
> Hola!
>
> I'd recommend to throw the GraphException, as we reported in the javadoc:
>
>     * <b>NOTE</b>: implementors have to take in consideration
> throwing a {@link GraphException}
>     * if an error occurs while performing that operation.
>
> How does it sound?
> all the best,
>
> -Simo
>
> http://people.apache.org/~simonetripodi/
> http://simonetripodi.livejournal.com/
> http://twitter.com/simonetripodi
> http://www.99soft.org/
>
>
>
> On Wed, Feb 15, 2012 at 7:25 PM, Marco Speranza
> <ma...@apache.org> wrote:
>
> Hi all guys,
>
>
> I notice that the methods "getConnectedVertices( V v )" and "getEdge( V
>
> source, V target )" into the class BaseGraph are not protect if a user
>
> passes  a vertex that not exists.
>
> Moreover in the first case the system throws a NPE and in the second case
>
> the system accepts the argument but return a null value to the user.
>
>
> Should it be a good idea put a control and throw a IllegalArgumentEx in
>
> both cases?
>
> WDYT?
>
>
> Ciao
>
>
> --
>
> Marco Speranza <marcosperanza@ <ma...@gmail.com>apache.org>
>
> Google Code: http://code.google.com/u/marco.speranza79/
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
>

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


Re: [Graph] Possible NPE if user requests a vertex that not exists on BaseGraph class

Posted by Marco Speranza <ma...@gmail.com>.
hi, 

> I'd recommend to throw the GraphException, as we reported in the javadoc:

I was thinking to use the method graph.utils.Assertions.checkArgument, it throws an IllegalArgumentEx, but  also GraphExpetion sounds good!

one more thing, the method getEdge() creates an instance of VertexPair for retrieve the edge, so if the user passes an incorrect vertex the method doesn't throw an Excepion but simply returns a null reference to the user.  
Is it necessary to throw the same exception also for that method? 

thanks ;)

--
Marco Speranza <ma...@gmail.com>

Flickr: http://www.flickr.com/photos/marcosperanza79/
Google Code: http://code.google.com/u/marco.speranza79/



Il giorno 15/feb/2012, alle ore 20:57, Simone Tripodi ha scritto:

> Hola!
> 
> I'd recommend to throw the GraphException, as we reported in the javadoc:
> 
>     * <b>NOTE</b>: implementors have to take in consideration
> throwing a {@link GraphException}
>     * if an error occurs while performing that operation.
> 
> How does it sound?
> all the best,
> 
> -Simo
> 
> http://people.apache.org/~simonetripodi/
> http://simonetripodi.livejournal.com/
> http://twitter.com/simonetripodi
> http://www.99soft.org/
> 
> 
> 
> On Wed, Feb 15, 2012 at 7:25 PM, Marco Speranza
> <ma...@apache.org> wrote:
>> Hi all guys,
>> 
>> I notice that the methods "getConnectedVertices( V v )" and "getEdge( V
>> source, V target )" into the class BaseGraph are not protect if a user
>> passes  a vertex that not exists.
>> Moreover in the first case the system throws a NPE and in the second case
>> the system accepts the argument but return a null value to the user.
>> 
>> Should it be a good idea put a control and throw a IllegalArgumentEx in
>> both cases?
>> WDYT?
>> 
>> Ciao
>> 
>> --
>> Marco Speranza <marcosperanza@ <ma...@gmail.com>apache.org>
>> Google Code: http://code.google.com/u/marco.speranza79/
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
> 


Re: [Graph] Possible NPE if user requests a vertex that not exists on BaseGraph class

Posted by Simone Tripodi <si...@apache.org>.
Hola!

I'd recommend to throw the GraphException, as we reported in the javadoc:

     * <b>NOTE</b>: implementors have to take in consideration
throwing a {@link GraphException}
     * if an error occurs while performing that operation.

How does it sound?
all the best,

-Simo

http://people.apache.org/~simonetripodi/
http://simonetripodi.livejournal.com/
http://twitter.com/simonetripodi
http://www.99soft.org/



On Wed, Feb 15, 2012 at 7:25 PM, Marco Speranza
<ma...@apache.org> wrote:
> Hi all guys,
>
> I notice that the methods "getConnectedVertices( V v )" and "getEdge( V
> source, V target )" into the class BaseGraph are not protect if a user
> passes  a vertex that not exists.
> Moreover in the first case the system throws a NPE and in the second case
> the system accepts the argument but return a null value to the user.
>
> Should it be a good idea put a control and throw a IllegalArgumentEx in
> both cases?
> WDYT?
>
> Ciao
>
> --
> Marco Speranza <marcosperanza@ <ma...@gmail.com>apache.org>
> Google Code: http://code.google.com/u/marco.speranza79/

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