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

XMLStreamWriterImpl does not write 'standalone' property

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 8, 9
    • Fix Version/s: 9
    • Component/s: xml
    • Subcomponent:
    • Resolved In Build:
      b140
    • CPU:
      x86_64
    • OS:
      generic

      Description

      FULL PRODUCT VERSION :
      java version "1.8.0_45"
      Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
      Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Linux AMDC1917 3.13.0-52-generic #86-Ubuntu SMP Mon May 4 04:32:59 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

      EXTRA RELEVANT SYSTEM CONFIGURATION :
      Just Jdk version

      A DESCRIPTION OF THE PROBLEM :
      If this is indeed an issue, a first description exists on stackoverflow:
      http://stackoverflow.com/questions/27437603/setting-standalone-yes-using-xmleventwriter

      When using StAX to create an XML document, the XMLEventFactory.createStartDocument does create a XMLEvent event. When adding the XMLEvent into a XMLEventWriter, it does not produce the standalone property, even if explicitly given as parameter.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1 - create a XMLOutputFactory
      2 - create a XMLEventFactory
      3 - create an output file (XML)
      4 - create a XMLEventWriter on this file with the XMLOutputFactory
      5 - create a XMLEvent as {XMLEventFactory}.createStartDocument("iso-8859-15", "1.0", true);
      6 - add this event to the XMLEventWriter
      7 - flush cached events if necessary

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      creation of an (empty) document with XML header as:

      <?xml version="1.0" encoding="iso-8859-15" standalone="yes"?>
      ACTUAL -
      creation of an (empty) document with XML header as:

      <?xml version="1.0" encoding="iso-8859-15"?>

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.io.FileOutputStream;
      import java.io.IOException;
      import java.io.OutputStreamWriter;

      import javax.xml.stream.XMLEventFactory;
      import javax.xml.stream.XMLEventWriter;
      import javax.xml.stream.XMLOutputFactory;
      import javax.xml.stream.XMLStreamConstants;
      import javax.xml.stream.XMLStreamException;
      import javax.xml.stream.events.StartDocument;
      import javax.xml.stream.events.XMLEvent;



          /**
           * test for:
           * http://stackoverflow.com/questions/28629709/java-stax-standalone-property-of-startdocument
           * using XMLEventReader | XMLEventWriter
           * @param args
           */
          public testStandalone() {
              XMLOutputFactory factory_out = null;
              XMLEventFactory eventFactory = null;
              XMLEventWriter eventWriter = null;
              XMLEvent event_out = null;

              try {
                  factory_out = XMLOutputFactory.newInstance();
                  eventFactory = XMLEventFactory.newInstance();
                  FileOutputStream out = new FileOutputStream("write_out.xml");
                  OutputStreamWriter w = new OutputStreamWriter(out, "iso-8859-15");
                  eventWriter = factory_out.createXMLEventWriter(w);

                  event_out = eventFactory.createStartDocument("iso-8859-15", "1.0", true);
                  eventWriter.add(event_out);
                  eventWriter.flush();
              } catch (XMLStreamException e) {
                  e.printStackTrace();
              } catch (IOException e) {
                  e.printStackTrace();
              } catch (Exception e) {
                  //UnsupportedEncodingException or FileNotFoundException
                  e.printStackTrace();
                  return;
              }

          }


      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      no workaround found, maybe a missing implementation on com.sun.xml.internal.stream.writers.XMLStreamWriterImpl :

      public void writeStartDocument(String encoding, String version)
          throws XMLStreamException {
          //Revisit : What about standalone ?


        Attachments

          Activity

            People

            Assignee:
            joehw Joe Wang
            Reporter:
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: