JDK-6472982 : javax.xml.namespace.NamespaceContext.getPrefix("") should not throw IllegalArgumentException
  • Type: Bug
  • Component: xml
  • Sub-Component: javax.xml.stream
  • Affected Version: 6
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2006-09-20
  • Updated: 2012-04-25
  • Resolved: 2010-01-15
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
1.4.0 h1192Fixed
Description
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.

Comments
EVALUATION ChangeSet=http://hg.openjdk.java.net/jdk6/jdk6/jaxp/rev/5c070921580c,ChangeRequest=6923146,ChangeRequest=6917454,ChangeRequest=6472982,ChangeRequest=6909759,ChangeRequest=6333993,ChangeRequest=6900779,ChangeRequest=6900773,ChangeRequest=6900249,ChangeRequest=6675332,ChangeRequest=6889654,ChangeRequest=6889649,ChangeRequest=6863312
18-02-2010

EVALUATION Fixed in JAXP sources. Note that this is a reverse of the change in 5055532, a test from 5055532 has been deprecated.
15-01-2010