[jdom-interest] Possible bug in Namespace.getNamespace() w.r.t. xml:

Elliotte Rusty Harold elharo at metalab.unc.edu
Tue Apr 30 08:48:27 PDT 2002


The following code appears in org.jdom.Namespace:

    public static Namespace getNamespace(String prefix, String uri) {
        // Sanity checking
        if ((prefix == null) || (prefix.trim().equals(""))) {
            prefix = "";
        }
        if ((uri == null) || (uri.trim().equals(""))) {
            uri = "";
        }

        // Handle XML namespace
        if (prefix.equals("xml")) {
            return XML_NAMESPACE;
        }

I think this is the correct behavior if someobody passes in the prefix 
"xml" and a null URI, an empty string URI, or 
"http://www.w3.org/XML/1998/namespace". However, I think that 
Namespace.getNamespace("xml", "http://www.somewhere.com/something") 
should throw an IllegalNameException. I propose modifying the last few 
lines something like this:

        // Handle XML namespace
        if (prefix.equals("xml")) {
          if (uri.equals("") || 
uri.equals("http://www.w3.org/XML/1998/namespace ")) {
            return XML_NAMESPACE;
          }
          else {
            throw new IllegalNameException("xml prefix cannot be 
remapped to " + uri);
          }
        }

I haven't tested the code yet, but you get the idea. Thoughts?

-- 
+-----------------------+------------------------+-------------------+
| Elliotte Rusty Harold | elharo at metalab.unc.edu | Writer/Programmer |
+-----------------------+------------------------+-------------------+ 
|           The XML Bible, 2nd Edition (IDG Books, 2001)             |
|             http://www.cafeconleche.org/books/bible2/              |
|   http://www.amazon.com/exec/obidos/ISBN=0764547607/cafeaulaitA/   |
+----------------------------------+---------------------------------+
|  Read Cafe au Lait for Java News:   http://www.cafeaulait.org/     | 
|  Read Cafe con Leche for XML News:  http://www.cafeconleche.org/   |
+----------------------------------+---------------------------------+





More information about the jdom-interest mailing list