[jdom-interest] JDOM 1.0b6 bug in Element.hasChildren()?

Thomas Koch Thomas.Koch at atlantec-es.com
Thu Mar 22 06:23:41 PST 2001


Good question. Actually, after looking at Element.java again,
getChildren() uses similar code already. I missed to check 
whether objclass was used anywhere else - too much
of a hurry.

Thomas

On Thursday 22 March 2001 12:13, Ken Rune Helland wrote:
> At 11:21 AM 3/22/2001 +0100, Thomas Koch wrote:
> >I believe to have identified a problem with Element.hasChildren()
> >that occurs when Element is subtyped. There is a test for class
> >equality that fails in that case even though it should succeed.
> >
> >See diff below.
> >
> >Thomas
> >
> >
> >*** b6/Element.java        Wed Feb 14 20:48:26 2001
> >--- b6-p1/Element.java        Thu Mar 22 10:46:43 2001
> >***************
> >*** 742,748 ****
> >           while (i.hasNext()){
> >               Object obj = i.next();
> >               Class objclass = obj.getClass();
> >!             if (objclass == Element.class) {
> >                   return true;
> >               }
> >           }
> >--- 742,748 ----
> >           while (i.hasNext()){
> >               Object obj = i.next();
> >               Class objclass = obj.getClass();
> >!             if (Element.class.isAssignableFrom(objclass)) {
> >                   return true;
> >               }
> >           }
>
> Why isnt this just using the instanceof operator?
>
> like:
>
>            while (i.hasNext()){
>              if (i.next() instanceof Element) {
>                return true;
>              }
>            }
>
> This will return true for Element and all subclasses of element.
> If the second operator to instanceof is a interface it will
> return true for all objects that implements this interface.
>
> Best regards
> KenR
>
>
> _______________________________________________
> To control your jdom-interest membership:
> http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourho
>st.com



More information about the jdom-interest mailing list