United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: 6767322 XMLStreamReader.getVersion implementation contradicts JavaDoc
6767322 : XMLStreamReader.getVersion implementation contradicts JavaDoc

Details
Type:
Bug
Submit Date:
2008-11-04
Status:
Closed
Updated Date:
2012-04-25
Project Name:
JDK
Resolved Date:
2011-08-26
Component:
xml
OS:
solaris_2.5.1
Sub-Component:
javax.xml.stream
CPU:
sparc
Priority:
P3
Resolution:
Fixed
Affected Versions:
6u7
Fixed Versions:
1.4.0

Related Reports

Sub Tasks

Description
The method getVersion() of javax.xml.stream.XMLStreamReader is defined to return null if a version wasn't declared. See JavaDoc: http://java.sun.com/javase/6/docs/api/javax/xml/stream/XMLStreamReader.html#getVersion() . The current implementation in JDK 6u7 returns "1.0" by default and never null, even for invalid XML documents.

Example program:
import java.io.ByteArrayInputStream;

import javax.xml.stream.FactoryConfigurationError;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;


public class XMLStreamReaderProblem {
  public static void main(String[] args) {
    try {
      String xmlText = args.length > 0 ? args[0] : "foo bar";
      XMLStreamReader r = XMLInputFactory.newInstance()
        .createXMLStreamReader(newByteArrayInputStream(xmlText.getBytes()));
      String version = r.getVersion();
      System.out.println("Version for text \"" + xmlText + "\": " + version);
    } catch (XMLStreamException e) {
      e.printStackTrace();
    } catch (FactoryConfigurationError e) {
      e.printStackTrace();
    }
  }
}

                                    

Comments
EVALUATION

Applied SAP's patch.
                                     
2011-08-26
EVALUATION

SJSXP (StAX implementation) abode by the StAX spec and returned null when there is no version information.  The issue is with the jaxp in jdk. When the StAX implementation was integrated into jaxp and then jdk, the common Apache parser for DOM and SAX was also used for StAX. The common parser does set default version to 1.0. The getXmlVersion for dom Document was defined like this:
"... If there is no declaration and if this document supports the "XML" feature, the value is 1.0 ..." [1]

[1] http://java.sun.com/javase/6/docs/api/org/w3c/dom/Document.html#getXmlVersion()
                                     
2009-02-24
WORK AROUND

None available.
                                     
2008-11-04



Hardware and Software, Engineered to Work Together