[jdom-interest] Re: small bug with big impact

Jason Hunter jhunter at collab.net
Sun Dec 3 21:53:44 PST 2000


Joseph Bowbeer wrote:
> 
> The bug that is repeated several times in the source is to use
> list.remove(object) instead of list.remove(index).

OK, I've integrated the fix.  Good eye, Joe.

> Xerces reports the intervening newline and indentation in a single
> 'characters' event.  This bypasses the code in JDOM that tries to
> concatenate contiguous characters.

Ah, this answers your initial question of "how it ever worked".  The bug
only occurred when an element had mixed content and the parser gave a
characters() callback to append to a String that was equivalent to a
String already in the content.  In Xerces seems this would never happen.

> List.remove(Object) is also called in several places in PartialList.
> This can lead to bugs if several objects in the backing list are equal
> to the Object in question.  When an object is removed from a
> PartialList, the object in the corresponding position in the backing
> list should be removed -- not the first object that satisfies
> equals().

Actually, we're OK because JDOM semantics are that JDOM objects are
equivalent only if they're identical.  (In other words, an element is
.equals() to another element only if they're the same element, not if
they have the same children and content.)  You'll notice the .equals()
methods are final and implemented as ==.  Oh, the ability to enforce
these equivalency checking semantics are one thing you miss out on if
you use interfaces.

PartialList does need to implement special handling for String types
though, where .equals() has different behavior.

-jh-




More information about the jdom-interest mailing list