XMLStreamReader getAttributeValue Bug Returns Null

I’m documenting this issue (and fix) here for anyone else Googling for an answer. I just did for about an hour and found no answer, but instead stumbled across the solution.

If you are using anything from the javax.xml.stream packages in Java 6 or later, you are using the Sun Java Streaming XML Parser (SJSXP) implementation of JSR-173 (StAX XML parsing API). There are many other implementations of StAX parsers out there (Javolution provides one, Woodstox and Aalto are a few of the most popular).

Unfortunately for me (or you if you found this story via Google) in JDK 1.6.0_17 and below, the version of SJSXP that ships with the JDK’s before version 1.6.0_18 had a bug (Bug #6840792) in the XMLStreamReader.getAttributeValue(String namespaceURI, String localName) method implementation that caused the method to return null values when no namespaceURI is given (which is a valid use-case).

The purpose of that method is to retrieve the value of a given attribute, identifying it by at least it’s localName and at most it’s localName and a namespaceURI if you have one or want to use one. If you choose not to provide a namespaceURI, then the name comparison to identify which attribute value you are asking for is suppose to only consider the localName, unfortunately the bug in SJSXP caused this rule to be ignored so no value for the attribute could be retrieved unless BOTH the namespaceURI and localName was provided.

Fortunately I headed over to the SJSXP website and saw that the most recent 1.0.2 patch release (changelog) was made and rolled into the JDK 1.6.0_18 release.

I also confirmed the fix in some code that was breaking on me and returning null values for the attributes just now.

Thanks to the SJSXP team for fixing this!

Tags: , , , , , , , , ,

This post was written by:

Riyad Kalla - who has written 2275 posts on The Buzz Media.

Software development, video games, writing, reading and anything shiny. I ultimately just want to provide a resource that helps people and if I can't do that, then at least make them laugh.

Contact the author

No comments yet.

Leave a Reply