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

Elliotte Rusty Harold elharo at metalab.unc.edu
Sat Mar 3 07:34:08 PST 2001


At 2:45 PM -0800 2/28/01, Jason Hunter wrote:

>Good eye.  I've changed the documentation on my local copy to be:
>
>      *  This returns a probably unique hash code for the
><code>Namespace</code>.
>      *  If two namespaces have the same URI but different prefixes, they
>may
>      *  have a different hash code.
>
>This correctly defines the behavior, and I think the existing behavior
>is correct.  Anyone (Elliotte esp) have concerns?
>

Yes, I disagree. I'm not sure when the mistake got in, but the 
comment is correct (i.e. it describes the right behavior) and the 
current code is wrong. Two namespaces are equal if their URIs are 
equal. The prefix should not be considered when testing for equality.

I suppose you can argue that two Namespace objects are not equal if 
they describe different prefixes. Maybe that makes sense, but it 
makes me deeply uncomfortable.

I guess the question comes down to what the use case for comparing 
namespaces is. I would expect that the equals method would let us 
take two set elements with possibly different prefixes, possibly one 
in a default namespace, and determine whether or not they have the 
same type; e.g. are both MathML set elements or is one a MathML set 
element and one an SVG set element? This only works if we compare 
based on URI and not prefix.
-- 

+-----------------------+------------------------+-------------------+
| Elliotte Rusty Harold | elharo at metalab.unc.edu | Writer/Programmer |
+-----------------------+------------------------+-------------------+
|                  The XML Bible (IDG Books, 1999)                   |
|              http://metalab.unc.edu/xml/books/bible/               |
|   http://www.amazon.com/exec/obidos/ISBN=0764532367/cafeaulaitA/   |
+----------------------------------+---------------------------------+
|  Read Cafe au Lait for Java News:  http://metalab.unc.edu/javafaq/ |
|  Read Cafe con Leche for XML News: http://metalab.unc.edu/xml/     |
+----------------------------------+---------------------------------+



More information about the jdom-interest mailing list