NamePool

2008-10-21
2012-10-08
  • Ivan Latysh

    Ivan Latysh - 2008-10-21

    I just stepped on IndexOutOfBoundsException in NamePool.java, and when I had a look at the code I saw that namespace code is treated differently in the following methods.

    So code 1050303 throws an exception in getURIFromNamespaceCode but not in getPrefixFromNamespaceCode.
    1050303 >> 16 = 16
    but
    1050303 & 0xffff = 1727

    [code]
    public String getURIFromNamespaceCode(int code) {
    return uris[code & 0xffff];
    }

    public String getPrefixFromNamespaceCode(int code) {
        return prefixes[code >> 16];
    }
    

    [/code]

    My question is: Should both methods behave the same ?

     
    • Michael Kay

      Michael Kay - 2008-10-21

      For both methods the effect is undefined if you supply a value that is not a correct namespace code. That may include throwing an exception, returning an arbitrary result, or anything else.

       

Log in to post a comment.