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

Ken Rune Helland kenh at csc.no
Thu Mar 22 03:13:33 PST 2001


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
  




More information about the jdom-interest mailing list