On 8/30/07, Maarten Coene <[EMAIL PROTECTED]> wrote:
>
> Hi,
>
> jira issue IVY-590 reports a NullPointerException which is caused by the
> following code (selected can be null):
>
>         public EvictionData(String rootModuleConf, IvyNode parent,
> ConflictManager conflictManager,
>                 Collection selected) {
>             this.rootModuleConf = rootModuleConf;
>             this.parent = parent;
>             this.conflictManager = conflictManager;
>             this.selected = selected;
>             for (Iterator iter = selected.iterator(); iter.hasNext();) {
>                 Object o = (Object) iter.next();
>                 if (!(o instanceof IvyNode)) {
>                     throw new IllegalArgumentException(
>                             "selected nodes must be instance of IvyNode.
> Found: "
>                                     + o.getClass().getName());
>                 }
>             }
>         }
>
>
> Several patches have been contributed to fix this NPE by checking the
> selected parameter for null before entering the for-loop. However, I would
> like to remove this for loop from the code, since the collection always
> contains IvyNodes.
>
> Does someone has an idea why this instanceof-check has been added there?


I think I introduced this check because it happened once that we had a non
IvyNode instance in the collection, causing a CCE later which was difficult
to diagnose. Since this constructor is public, making a check seems like a
not too bad idea (if it was done correctly, ie by checking null before :-)).
But if you experience a performance issue with this check, we can remove the
check, and add a comment in the constructor saying that the collection must
contain only IvyNode, otherwise a CCE may be cast later in other sections of
the code.

To fix the bug, I thought it would be better to first find the case when the
collection is null and add a junit test for it. But it may take more time
than what we have.

WDYT?

Xavier

regards,
> Maarten
>
>
>
>
>
>
> ____________________________________________________________________________________
> Be a better Globetrotter. Get better travel answers from someone who
> knows. Yahoo! Answers - Check it out.
> http://answers.yahoo.com/dir/?link=list&sid=396545469
>



-- 
Xavier Hanin - Independent Java Consultant
http://xhab.blogspot.com/
http://incubator.apache.org/ivy/
http://www.xoocode.org/

Reply via email to