Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6767322

XMLStreamReader.getVersion implementation contradicts JavaDoc

XMLWordPrintable

    • 1.4
    • sparc
    • solaris_2.5.1
    • Verified

      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();
          }
        }
      }

            joehw Joe Wang
            dkorbel David Korbel (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: