Consider the following piece of code:
XMLStreamReader reader= ...;
NamespaceContext context = reader.getNamespaceContext();
context.getPrefix(""); // <-- this throws an IllegalArgumentException
The javadocs for NamespaceContext do not agree that NamespacePrefix#getPrefix() should throw an IllegalArgumentException for "". An exception is thrown only for a null argument. The javadocs contain the following table that describes this:
*getPrefix(namespaceURI)** return value for specified Namespace URIs*
*Namespace URI parameter*
*prefix value returned*
<default Namespace URI> XMLConstants.DEFAULT_NS_PREFIX ("")
bound Namespace URI prefix bound to Namespace URI in the current scope, if multiple prefixes are bound to the Namespace URI in the current scope, a single arbitrary prefix, whose choice is implementation dependent, is returned
unbound Namespace URI null
XMLConstants.XML_NS_URI ("http://www.w3.org/XML/1998/namespace") XMLConstants.XML_NS_PREFIX ("xml")
XMLConstants.XMLNS_ATTRIBUTE_NS_URI ("http://www.w3.org/2000/xmlns/") XMLConstants.XMLNS_ATTRIBUTE ("xmlns")
null IllegalArgumentException is thrown
Based on this table, the empty string should be treated as an unbound namespace URI and the prefix returned should be null.
This bug was submitted by IBM as a part of their challenge regarding StAX test presented in JAXP TCK and JCK.
The bug exists in JDK 6 b98 and JAXP RI 1.4 b38.