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

XMLStreamWriter setDefaultNamespace(null) throws NullPointerException

XMLWordPrintable

    • b06
    • x86_64
    • windows_7

        A DESCRIPTION OF THE PROBLEM :
        According to the JavaDoc 11 it is allowed to use null as argument to XMLStreamWriter.setDefaultNamespace():
        "Parameters:
            uri - the uri to bind to the default namespace, may be null"

        Since Java 8 the implementation within the subsequently called method 'isDefaultNamespace()' changed from:

            if (uri == defaultNamespace) {
                return true;
            }

        to:

            if (uri.equals(defaultNamespace)) {
                return true;
            }

        In cases where 'uri' is null the call of 'equals()' leads to a NullPointerException.

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        XMLOutputFactory outFactory = XMLOutputFactory.newFactory();
        outFactory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, new Boolean(true));
        BufferedOutputStream bufferedStream = new BufferedOutputStream(outStream);
        XMLStreamWriter xsw = outFactory.createXMLStreamWriter(bufferedStream, "UTF-8");
        xsw.setDefaultNamespace(null);


        ACTUAL -
        Caused by: java.lang.NullPointerException
                at java.xml/com.sun.xml.internal.stream.writers.XMLStreamWriterImpl.isDefaultNamespace(XMLStreamWriterImpl.java:1733)
                at java.xml/com.sun.xml.internal.stream.writers.XMLStreamWriterImpl.setDefaultNamespace(XMLStreamWriterImpl.java:458)

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

                Created:
                Updated:
                Resolved: