[jdom-interest] Inconsistancy in Namespace.hashCode().

GB/DEV - Philip Nelson philip.nelson at omniresources.com
Wed Feb 28 13:27:34 PST 2001


> I have been looking at the code a little and came across
> a discrepency between the function's documentation and its
> behaviour.  Here's the code:
> 
>     /**
>      * <p>
>      *  This returns a probably unique hash code for the
> <code>Namespace</code>.
>      *  If two namespaces have the same URI, they are equal 
> and have the
> same
>      *  hash code, even if they have different prefixes.
>      * </p>
>      *
>      * @return <code>int</code> - hash code for this 
> <code>Namespace</code>.
>      */
>     public int hashCode() {
>         // Since neither URI nor prefix are guaranteed to be unique,
>         // use the combination
>         return (prefix+uri).hashCode();
>     }

Yeah the comment looks wrong to me.  It probably relates back to Elliote's
implementation where a namespace may not return the prefix you think you
added because a previous prefix was added with the same namespace.  In that
case, it's anybodies guess which one you would get back. Perhaps this
behaviour has changed.  I'll run my tests to see soon.  It seems that the
was the code is written is what a user would actually expect.



More information about the jdom-interest mailing list