Skip to Content.
Sympa Menu

xom-interest - Re: [XOM-interest] getChild sometimes returns null and sometimes throws IndexOutOfBoundsException

xom-interest AT lists.ibiblio.org

Subject: XOM API for Processing XML with Java

List archive

Chronological Thread  
  • From: Elliotte Rusty Harold <elharo AT ibiblio.org>
  • To: XOM API for Processing XML with Java <xom-interest AT lists.ibiblio.org>
  • Subject: Re: [XOM-interest] getChild sometimes returns null and sometimes throws IndexOutOfBoundsException
  • Date: Tue, 14 Mar 2017 10:50:07 -0400

I agree that's strange. I'll take a look.

On Tue, Mar 14, 2017 at 9:59 AM, Michael Whapples <software AT mdw.onl> wrote:
> Hello,
>
> I have found if my code tries to call getChild with an index greater than
> the number of child nodes, sometimes it will return null and other times it
> will throw an IndexOutOfBoundsException. This does not seem to be entirely
> random and seems to be reproduceable. When I tested it, getChild(1) called
> when the element only has one child throws the exception. Similar for
> getChild(2) called on an element with 2 child nodes. However for getChild(3)
> called on an element with 3 child nodes will return null.
>
>
> Is there any reason why XOM does different things for what seems to be the
> same problem?
>
>
> Below is a Java class demonstrating the issue.
>
>
> import nu.xom.Element;
>
> public class App {
> public static void main(String[] args) {
> Element e1 = new Element("p");
> Element c1 = new Element("s");
> e1.appendChild(c1);
> Element c2 = new Element("b");
> e1.appendChild(c2);
> Element c3 = new Element("s");
> e1.appendChild(c3);
> System.out.println(e1.getChild(3));
> Element e2 = new Element("p");
> Element cn1 = new Element("s");
> e2.appendChild(cn1);
> System.out.println(e2.getChild(1));
> }
> }
>
> Regards
>
>
> Michael Whapples
>
> _______________________________________________
> XOM-interest mailing list
> XOM-interest AT lists.ibiblio.org
> http://lists.ibiblio.org/mailman/listinfo/xom-interest



--
Elliotte Rusty Harold
elharo AT ibiblio.org




Archive powered by MHonArc 2.6.24.

Top of Page