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

XMLStreamException: Namespace URI is not bound to any prefix even though IS_REPAIRING_NAMESPACES

    Details

    • Type: Enhancement
    • Status: Open
    • Priority: P4
    • Resolution: Unresolved
    • Affects Version/s: 8, 9, 10
    • Fix Version/s: tbd
    • Component/s: xml

      Description

      FULL PRODUCT VERSION :
      java version "1.8.0_112"
      Java(TM) SE Runtime Environment (build 1.8.0_112-b16)
      Java HotSpot(TM) 64-Bit Server VM (build 25.112-b16, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Darwin retina 16.7.0 Darwin Kernel Version 16.7.0: Wed Oct 4 00:17:00 PDT 2017; root:xnu-3789.71.6~1/RELEASE_X86_64 x86_64 i386 MacBookPro10,1 Darwin


      A DESCRIPTION OF THE PROBLEM :
      The XMLStreamWriter API is throwing XMLStreamException in a situation where AFAICT it should not.

      In this case, we've invoked

      XMLOutputFactory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, true);

      According to the Javadoc, this means that namespaces should be "repaired", i.e., XML namespace prefixes automatically generated.

      Moreover, in this case:
      (a) the output is going to a DOM, so namespace prefixes are entirely irrelevant
      (b) the namespace being used is empty string


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Compile and execute the attached test case.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      No exception; program exits normally.

      ACTUAL -
      Exception in thread "main" javax.xml.stream.XMLStreamException: Namespace URI is not bound to any prefix
      at com.sun.xml.internal.stream.writers.XMLDOMWriterImpl.writeStartElement(XMLDOMWriterImpl.java:652)
      at xx.main(xx.java:21)


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import javax.xml.namespace.*;
      import javax.xml.stream.*;
      import javax.xml.parsers.*;
      import javax.xml.transform.dom.*;
      import org.w3c.dom.*;

      public class xx {

          public static void main(String[] args) throws Exception {

              // Create new XML DOM document
              final Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();

              // Create XMLStreamWriter
              final XMLOutputFactory factory = XMLOutputFactory.newInstance();
              factory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, true);
              final XMLStreamWriter writer = factory.createXMLStreamWriter(new DOMResult(doc));

              // Write <foo> element
              final QName foo = new QName("foo");
              writer.writeStartElement(foo.getNamespaceURI(), foo.getLocalPart());
          }
      }

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

      CUSTOMER SUBMITTED WORKAROUND :
      Add this line after creating 'writer':

         writer.setPrefix("xxx", "");


        Attachments

          Activity

            People

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

              Dates

              • Created:
                Updated: