8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE
authorclanger
Wed, 23 Nov 2016 08:58:15 +0100
changeset 42249 39ec1a731d99
parent 42248 6d7e82a34c09
child 42250 25a48473f3cc
8169772: [JAXP] XALAN: Transformation of DOM with null valued text node causes NPE Reviewed-by: joehw
jaxp/src/java.xml/share/classes/com/sun/org/apache/xml/internal/serializer/EmptySerializer.java
jaxp/src/java.xml/share/classes/com/sun/org/apache/xml/internal/serializer/SerializerBase.java
jaxp/src/java.xml/share/classes/com/sun/org/apache/xml/internal/serializer/ToSAXHandler.java
jaxp/src/java.xml/share/classes/com/sun/org/apache/xml/internal/serializer/ToStream.java
jaxp/src/java.xml/share/classes/com/sun/org/apache/xml/internal/serializer/ToUnknownStream.java
jaxp/src/java.xml/share/classes/com/sun/org/apache/xml/internal/serializer/XSLOutputAttributes.java
jaxp/test/javax/xml/jaxp/unittest/transform/TransformerTest.java
--- a/jaxp/src/java.xml/share/classes/com/sun/org/apache/xml/internal/serializer/EmptySerializer.java	Tue Nov 22 14:48:16 2016 +0100
+++ b/jaxp/src/java.xml/share/classes/com/sun/org/apache/xml/internal/serializer/EmptySerializer.java	Wed Nov 23 08:58:15 2016 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.
  */
 /*
  * Licensed to the Apache Software Foundation (ASF) under one or more
@@ -17,9 +17,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-/*
- * $Id: EmptySerializer.java,v 1.2.4.1 2005/09/15 08:15:16 suresh_emailid Exp $
- */
+
 package com.sun.org.apache.xml.internal.serializer;
 
 import java.io.IOException;
@@ -48,235 +46,224 @@
 public class EmptySerializer implements SerializationHandler
 {
     protected static final String ERR = "EmptySerializer method not over-ridden";
-    /**
-     * @see SerializationHandler#asContentHandler()
-     */
 
-    protected void couldThrowIOException() throws IOException
-    {
+    protected void couldThrowIOException() throws IOException {
         return; // don't do anything.
     }
 
-    protected void couldThrowSAXException() throws SAXException
+    protected void couldThrowSAXException() throws SAXException {
+        return; // don't do anything.
+    }
+
+    protected void couldThrowSAXException(char[] chars, int off, int len)
+        throws SAXException
     {
         return; // don't do anything.
     }
 
-    protected void couldThrowSAXException(char[] chars, int off, int len) throws SAXException
+    protected void couldThrowSAXException(String elemQName)
+        throws SAXException
     {
         return; // don't do anything.
     }
 
-    protected void couldThrowSAXException(String elemQName) throws SAXException
-    {
-        return; // don't do anything.
-    }
-
-    void aMethodIsCalled()
-    {
-
+    void aMethodIsCalled() {
         // throw new RuntimeException(err);
         return;
     }
 
-
     /**
      * @see SerializationHandler#asContentHandler()
      */
-    public ContentHandler asContentHandler() throws IOException
-    {
+    public ContentHandler asContentHandler() throws IOException {
         couldThrowIOException();
         return null;
     }
+
     /**
      * @see SerializationHandler#setContentHandler(org.xml.sax.ContentHandler)
      */
-    public void setContentHandler(ContentHandler ch)
-    {
+    public void setContentHandler(ContentHandler ch) {
         aMethodIsCalled();
     }
+
     /**
      * @see SerializationHandler#close()
      */
-    public void close()
-    {
+    public void close() {
         aMethodIsCalled();
     }
+
     /**
      * @see SerializationHandler#getOutputFormat()
      */
-    public Properties getOutputFormat()
-    {
+    public Properties getOutputFormat() {
         aMethodIsCalled();
         return null;
     }
+
     /**
      * @see SerializationHandler#getOutputStream()
      */
-    public OutputStream getOutputStream()
-    {
+    public OutputStream getOutputStream() {
         aMethodIsCalled();
         return null;
     }
+
     /**
      * @see SerializationHandler#getWriter()
      */
-    public Writer getWriter()
-    {
+    public Writer getWriter() {
         aMethodIsCalled();
         return null;
     }
+
     /**
      * @see SerializationHandler#reset()
      */
-    public boolean reset()
-    {
+    public boolean reset() {
         aMethodIsCalled();
         return false;
     }
+
     /**
      * @see SerializationHandler#serialize(org.w3c.dom.Node)
      */
-    public void serialize(Node node) throws IOException
-    {
+    public void serialize(Node node) throws IOException {
         couldThrowIOException();
     }
+
     /**
      * @see SerializationHandler#setCdataSectionElements(java.util.ArrayList<String>)
      */
-    public void setCdataSectionElements(ArrayList<String> URI_and_localNames)
-    {
+    public void setCdataSectionElements(ArrayList<String> URI_and_localNames) {
         aMethodIsCalled();
     }
+
     /**
      * @see SerializationHandler#setEscaping(boolean)
      */
-    public boolean setEscaping(boolean escape) throws SAXException
-    {
+    public boolean setEscaping(boolean escape) throws SAXException {
         couldThrowSAXException();
         return false;
     }
+
     /**
      * @see SerializationHandler#setIndent(boolean)
      */
-    public void setIndent(boolean indent)
-    {
+    public void setIndent(boolean indent) {
         aMethodIsCalled();
     }
+
     /**
      * @see SerializationHandler#setIndentAmount(int)
      */
-    public void setIndentAmount(int spaces)
-    {
+    public void setIndentAmount(int spaces) {
         aMethodIsCalled();
     }
+
     /**
      * @see SerializationHandler#setIsStandalone(boolean)
      */
-    public void setIsStandalone(boolean isStandalone)
-    {
+    public void setIsStandalone(boolean isStandalone) {
         aMethodIsCalled();
     }
+
     /**
      * @see SerializationHandler#setOutputFormat(java.util.Properties)
      */
-    public void setOutputFormat(Properties format)
-    {
+    public void setOutputFormat(Properties format) {
         aMethodIsCalled();
     }
+
     /**
      * @see SerializationHandler#setOutputStream(java.io.OutputStream)
      */
-    public void setOutputStream(OutputStream output)
-    {
+    public void setOutputStream(OutputStream output) {
         aMethodIsCalled();
     }
+
     /**
      * @see SerializationHandler#setVersion(java.lang.String)
      */
-    public void setVersion(String version)
-    {
+    public void setVersion(String version) {
         aMethodIsCalled();
     }
+
     /**
      * @see SerializationHandler#setWriter(java.io.Writer)
      */
-    public void setWriter(Writer writer)
-    {
+    public void setWriter(Writer writer) {
         aMethodIsCalled();
     }
+
     /**
      * @see SerializationHandler#setTransformer(javax.xml.transform.Transformer)
      */
-    public void setTransformer(Transformer transformer)
-    {
+    public void setTransformer(Transformer transformer) {
         aMethodIsCalled();
     }
+
     /**
      * @see SerializationHandler#getTransformer()
      */
-    public Transformer getTransformer()
-    {
+    public Transformer getTransformer() {
         aMethodIsCalled();
         return null;
     }
+
     /**
      * @see SerializationHandler#flushPending()
      */
-    public void flushPending() throws SAXException
-    {
+    public void flushPending() throws SAXException {
         couldThrowSAXException();
     }
+
     /**
      * @see ExtendedContentHandler#addAttribute(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String)
      */
-    public void addAttribute(
-        String uri,
-        String localName,
-        String rawName,
-        String type,
-        String value,
-        boolean XSLAttribute)
+    public void addAttribute(String uri, String localName, String rawName,
+                             String type, String value, boolean XSLAttribute)
         throws SAXException
     {
         couldThrowSAXException();
     }
+
     /**
      * @see ExtendedContentHandler#addAttributes(org.xml.sax.Attributes)
      */
-    public void addAttributes(Attributes atts) throws SAXException
-    {
+    public void addAttributes(Attributes atts) throws SAXException {
         couldThrowSAXException();
     }
+
     /**
      * @see ExtendedContentHandler#addAttribute(java.lang.String, java.lang.String)
      */
-    public void addAttribute(String name, String value)
-    {
+    public void addAttribute(String name, String value) {
         aMethodIsCalled();
     }
 
     /**
      * @see ExtendedContentHandler#characters(java.lang.String)
      */
-    public void characters(String chars) throws SAXException
-    {
+    public void characters(String chars) throws SAXException {
         couldThrowSAXException();
     }
+
     /**
      * @see ExtendedContentHandler#endElement(java.lang.String)
      */
-    public void endElement(String elemName) throws SAXException
-    {
+    public void endElement(String elemName) throws SAXException {
         couldThrowSAXException();
     }
+
     /**
      * @see ExtendedContentHandler#startDocument()
      */
-    public void startDocument() throws SAXException
-    {
+    public void startDocument() throws SAXException {
         couldThrowSAXException();
     }
+
     /**
      * @see ExtendedContentHandler#startElement(java.lang.String, java.lang.String, java.lang.String)
      */
@@ -285,13 +272,14 @@
     {
         couldThrowSAXException(qName);
     }
+
     /**
      * @see ExtendedContentHandler#startElement(java.lang.String)
      */
-    public void startElement(String qName) throws SAXException
-    {
+    public void startElement(String qName) throws SAXException {
         couldThrowSAXException(qName);
     }
+
     /**
      * @see ExtendedContentHandler#namespaceAfterStartElement(java.lang.String, java.lang.String)
      */
@@ -303,68 +291,67 @@
     /**
      * @see ExtendedContentHandler#startPrefixMapping(java.lang.String, java.lang.String, boolean)
      */
-    public boolean startPrefixMapping(
-        String prefix,
-        String uri,
-        boolean shouldFlush)
+    public boolean startPrefixMapping(String prefix, String uri,
+                                      boolean shouldFlush)
         throws SAXException
     {
         couldThrowSAXException();
         return false;
     }
+
     /**
      * @see ExtendedContentHandler#entityReference(java.lang.String)
      */
-    public void entityReference(String entityName) throws SAXException
-    {
+    public void entityReference(String entityName) throws SAXException {
         couldThrowSAXException();
     }
+
     /**
      * @see ExtendedContentHandler#getNamespaceMappings()
      */
-    public NamespaceMappings getNamespaceMappings()
-    {
+    public NamespaceMappings getNamespaceMappings() {
         aMethodIsCalled();
         return null;
     }
+
     /**
      * @see ExtendedContentHandler#getPrefix(java.lang.String)
      */
-    public String getPrefix(String uri)
-    {
+    public String getPrefix(String uri) {
         aMethodIsCalled();
         return null;
     }
+
     /**
      * @see ExtendedContentHandler#getNamespaceURI(java.lang.String, boolean)
      */
-    public String getNamespaceURI(String name, boolean isElement)
-    {
+    public String getNamespaceURI(String name, boolean isElement) {
         aMethodIsCalled();
         return null;
     }
+
     /**
      * @see ExtendedContentHandler#getNamespaceURIFromPrefix(java.lang.String)
      */
-    public String getNamespaceURIFromPrefix(String prefix)
-    {
+    public String getNamespaceURIFromPrefix(String prefix) {
         aMethodIsCalled();
         return null;
     }
+
     /**
      * @see org.xml.sax.ContentHandler#setDocumentLocator(org.xml.sax.Locator)
      */
-    public void setDocumentLocator(Locator arg0)
-    {
+    public void setDocumentLocator(Locator arg0) {
         aMethodIsCalled();
     }
+
     /**
      * @see org.xml.sax.ContentHandler#endDocument()
      */
-    public void endDocument() throws SAXException
-    {
+    public void endDocument() throws SAXException {
         couldThrowSAXException();
     }
+
     /**
      * @see org.xml.sax.ContentHandler#startPrefixMapping(java.lang.String, java.lang.String)
      */
@@ -373,25 +360,24 @@
     {
         couldThrowSAXException();
     }
+
     /**
      * @see org.xml.sax.ContentHandler#endPrefixMapping(java.lang.String)
      */
-    public void endPrefixMapping(String arg0) throws SAXException
-    {
+    public void endPrefixMapping(String arg0) throws SAXException {
         couldThrowSAXException();
     }
+
     /**
      * @see org.xml.sax.ContentHandler#startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)
      */
-    public void startElement(
-        String arg0,
-        String arg1,
-        String arg2,
-        Attributes arg3)
+    public void startElement(String arg0, String arg1, String arg2,
+                             Attributes arg3)
         throws SAXException
     {
         couldThrowSAXException();
     }
+
     /**
      * @see org.xml.sax.ContentHandler#endElement(java.lang.String, java.lang.String, java.lang.String)
      */
@@ -400,13 +386,14 @@
     {
         couldThrowSAXException();
     }
+
     /**
      * @see org.xml.sax.ContentHandler#characters(char[], int, int)
      */
-    public void characters(char[] arg0, int arg1, int arg2) throws SAXException
-    {
+    public void characters(char[] arg0, int arg1, int arg2) throws SAXException {
         couldThrowSAXException(arg0, arg1, arg2);
     }
+
     /**
      * @see org.xml.sax.ContentHandler#ignorableWhitespace(char[], int, int)
      */
@@ -415,6 +402,7 @@
     {
         couldThrowSAXException();
     }
+
     /**
      * @see org.xml.sax.ContentHandler#processingInstruction(java.lang.String, java.lang.String)
      */
@@ -423,20 +411,21 @@
     {
         couldThrowSAXException();
     }
+
     /**
      * @see org.xml.sax.ContentHandler#skippedEntity(java.lang.String)
      */
-    public void skippedEntity(String arg0) throws SAXException
-    {
+    public void skippedEntity(String arg0) throws SAXException {
         couldThrowSAXException();
     }
+
     /**
      * @see ExtendedLexicalHandler#comment(java.lang.String)
      */
-    public void comment(String comment) throws SAXException
-    {
+    public void comment(String comment) throws SAXException {
         couldThrowSAXException();
     }
+
     /**
      * @see org.xml.sax.ext.LexicalHandler#startDTD(java.lang.String, java.lang.String, java.lang.String)
      */
@@ -445,189 +434,187 @@
     {
         couldThrowSAXException();
     }
+
     /**
      * @see org.xml.sax.ext.LexicalHandler#endDTD()
      */
-    public void endDTD() throws SAXException
-    {
+    public void endDTD() throws SAXException {
         couldThrowSAXException();
     }
+
     /**
      * @see org.xml.sax.ext.LexicalHandler#startEntity(java.lang.String)
      */
-    public void startEntity(String arg0) throws SAXException
-    {
+    public void startEntity(String arg0) throws SAXException {
         couldThrowSAXException();
     }
+
     /**
      * @see org.xml.sax.ext.LexicalHandler#endEntity(java.lang.String)
      */
-    public void endEntity(String arg0) throws SAXException
-    {
+    public void endEntity(String arg0) throws SAXException {
         couldThrowSAXException();
     }
+
     /**
      * @see org.xml.sax.ext.LexicalHandler#startCDATA()
      */
-    public void startCDATA() throws SAXException
-    {
+    public void startCDATA() throws SAXException {
         couldThrowSAXException();
     }
+
     /**
      * @see org.xml.sax.ext.LexicalHandler#endCDATA()
      */
-    public void endCDATA() throws SAXException
-    {
+    public void endCDATA() throws SAXException {
         couldThrowSAXException();
     }
+
     /**
      * @see org.xml.sax.ext.LexicalHandler#comment(char[], int, int)
      */
-    public void comment(char[] arg0, int arg1, int arg2) throws SAXException
-    {
+    public void comment(char[] arg0, int arg1, int arg2) throws SAXException {
         couldThrowSAXException();
     }
+
     /**
      * @see XSLOutputAttributes#getDoctypePublic()
      */
-    public String getDoctypePublic()
-    {
+    public String getDoctypePublic() {
         aMethodIsCalled();
         return null;
     }
+
     /**
      * @see XSLOutputAttributes#getDoctypeSystem()
      */
-    public String getDoctypeSystem()
-    {
+    public String getDoctypeSystem() {
         aMethodIsCalled();
         return null;
     }
+
     /**
      * @see XSLOutputAttributes#getEncoding()
      */
-    public String getEncoding()
-    {
-        aMethodIsCalled();
-        return null;
-    }
-    /**
-     * @see XSLOutputAttributes#getIndent()
-     */
-    public boolean getIndent()
-    {
-        aMethodIsCalled();
-        return false;
-    }
-    /**
-     * @see XSLOutputAttributes#getIndentAmount()
-     */
-    public int getIndentAmount()
-    {
-        aMethodIsCalled();
-        return 0;
-    }
-    /**
-     * @see XSLOutputAttributes#getMediaType()
-     */
-    public String getMediaType()
-    {
+    public String getEncoding() {
         aMethodIsCalled();
         return null;
     }
+
     /**
-     * @see XSLOutputAttributes#getOmitXMLDeclaration()
+     * @see XSLOutputAttributes#getIndent()
      */
-    public boolean getOmitXMLDeclaration()
-    {
+    public boolean getIndent() {
         aMethodIsCalled();
         return false;
     }
+
+    /**
+     * @see XSLOutputAttributes#getIndentAmount()
+     */
+    public int getIndentAmount() {
+        aMethodIsCalled();
+        return 0;
+    }
+
+    /**
+     * @see XSLOutputAttributes#getMediaType()
+     */
+    public String getMediaType() {
+        aMethodIsCalled();
+        return null;
+    }
+
+    /**
+     * @see XSLOutputAttributes#getOmitXMLDeclaration()
+     */
+    public boolean getOmitXMLDeclaration() {
+        aMethodIsCalled();
+        return false;
+    }
+
     /**
      * @see XSLOutputAttributes#getStandalone()
      */
-    public String getStandalone()
-    {
+    public String getStandalone() {
         aMethodIsCalled();
         return null;
     }
+
     /**
      * @see XSLOutputAttributes#getVersion()
      */
-    public String getVersion()
-    {
+    public String getVersion() {
         aMethodIsCalled();
         return null;
     }
+
     /**
      * @see XSLOutputAttributes#setDoctype(java.lang.String, java.lang.String)
      */
-    public void setDoctype(String system, String pub)
-    {
+    public void setDoctype(String system, String pub) {
         aMethodIsCalled();
     }
+
     /**
      * @see XSLOutputAttributes#setDoctypePublic(java.lang.String)
      */
-    public void setDoctypePublic(String doctype)
-    {
+    public void setDoctypePublic(String doctype) {
         aMethodIsCalled();
     }
+
     /**
      * @see XSLOutputAttributes#setDoctypeSystem(java.lang.String)
      */
-    public void setDoctypeSystem(String doctype)
-    {
+    public void setDoctypeSystem(String doctype) {
         aMethodIsCalled();
     }
+
     /**
      * @see XSLOutputAttributes#setEncoding(java.lang.String)
      */
-    public void setEncoding(String encoding)
-    {
+    public void setEncoding(String encoding) {
         aMethodIsCalled();
     }
+
     /**
      * @see XSLOutputAttributes#setMediaType(java.lang.String)
      */
-    public void setMediaType(String mediatype)
-    {
+    public void setMediaType(String mediatype) {
         aMethodIsCalled();
     }
+
     /**
      * @see XSLOutputAttributes#setOmitXMLDeclaration(boolean)
      */
-    public void setOmitXMLDeclaration(boolean b)
-    {
+    public void setOmitXMLDeclaration(boolean b) {
         aMethodIsCalled();
     }
+
     /**
      * @see XSLOutputAttributes#setStandalone(java.lang.String)
      */
-    public void setStandalone(String standalone)
-    {
+    public void setStandalone(String standalone) {
         aMethodIsCalled();
     }
+
     /**
      * @see org.xml.sax.ext.DeclHandler#elementDecl(java.lang.String, java.lang.String)
      */
-    public void elementDecl(String arg0, String arg1) throws SAXException
-    {
+    public void elementDecl(String arg0, String arg1) throws SAXException {
         couldThrowSAXException();
     }
+
     /**
      * @see org.xml.sax.ext.DeclHandler#attributeDecl(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String)
      */
-    public void attributeDecl(
-        String arg0,
-        String arg1,
-        String arg2,
-        String arg3,
-        String arg4)
+    public void attributeDecl(String arg0, String arg1, String arg2,
+                              String arg3, String arg4)
         throws SAXException
     {
         couldThrowSAXException();
     }
+
     /**
      * @see org.xml.sax.ext.DeclHandler#internalEntityDecl(java.lang.String, java.lang.String)
      */
@@ -636,6 +623,7 @@
     {
         couldThrowSAXException();
     }
+
     /**
      * @see org.xml.sax.ext.DeclHandler#externalEntityDecl(java.lang.String, java.lang.String, java.lang.String)
      */
@@ -644,32 +632,32 @@
     {
         couldThrowSAXException();
     }
+
     /**
      * @see org.xml.sax.ErrorHandler#warning(org.xml.sax.SAXParseException)
      */
-    public void warning(SAXParseException arg0) throws SAXException
-    {
+    public void warning(SAXParseException arg0) throws SAXException {
         couldThrowSAXException();
     }
+
     /**
      * @see org.xml.sax.ErrorHandler#error(org.xml.sax.SAXParseException)
      */
-    public void error(SAXParseException arg0) throws SAXException
-    {
+    public void error(SAXParseException arg0) throws SAXException {
         couldThrowSAXException();
     }
+
     /**
      * @see org.xml.sax.ErrorHandler#fatalError(org.xml.sax.SAXParseException)
      */
-    public void fatalError(SAXParseException arg0) throws SAXException
-    {
+    public void fatalError(SAXParseException arg0) throws SAXException {
         couldThrowSAXException();
     }
+
     /**
      * @see Serializer#asDOMSerializer()
      */
-    public DOMSerializer asDOMSerializer() throws IOException
-    {
+    public DOMSerializer asDOMSerializer() throws IOException {
         couldThrowIOException();
         return null;
     }
@@ -684,8 +672,7 @@
     /**
      * @see ExtendedContentHandler#setSourceLocator(javax.xml.transform.SourceLocator)
      */
-    public void setSourceLocator(SourceLocator locator)
-    {
+    public void setSourceLocator(SourceLocator locator) {
         aMethodIsCalled();
     }
 
@@ -701,30 +688,30 @@
     /**
      * @see ExtendedContentHandler#characters(org.w3c.dom.Node)
      */
-    public void characters(Node node) throws SAXException
-    {
+    public void characters(Node node) throws SAXException {
         couldThrowSAXException();
     }
 
     /**
      * @see ExtendedContentHandler#addXSLAttribute(java.lang.String, java.lang.String, java.lang.String)
      */
-    public void addXSLAttribute(String qName, String value, String uri)
-    {
+    public void addXSLAttribute(String qName, String value, String uri) {
         aMethodIsCalled();
     }
 
     /**
      * @see ExtendedContentHandler#addAttribute(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String)
      */
-    public void addAttribute(String uri, String localName, String rawName, String type, String value) throws SAXException
-    {
+    public void addAttribute(String uri, String localName, String rawName,
+                             String type, String value) throws SAXException {
         couldThrowSAXException();
     }
+
     /**
      * @see org.xml.sax.DTDHandler#notationDecl(java.lang.String, java.lang.String, java.lang.String)
      */
-    public void notationDecl(String arg0, String arg1, String arg2) throws SAXException
+    public void notationDecl(String arg0, String arg1, String arg2)
+        throws SAXException
     {
         couldThrowSAXException();
     }
@@ -732,12 +719,8 @@
     /**
      * @see org.xml.sax.DTDHandler#unparsedEntityDecl(java.lang.String, java.lang.String, java.lang.String, java.lang.String)
      */
-    public void unparsedEntityDecl(
-        String arg0,
-        String arg1,
-        String arg2,
-        String arg3)
-        throws SAXException {
+    public void unparsedEntityDecl(String arg0, String arg1, String arg2,
+                                   String arg3) throws SAXException {
         couldThrowSAXException();
     }
 
@@ -746,10 +729,8 @@
      */
     public void setDTDEntityExpansion(boolean expand) {
         aMethodIsCalled();
-
     }
 
-
     public String getOutputProperty(String name) {
         aMethodIsCalled();
         return null;
@@ -762,19 +743,16 @@
 
     public void setOutputProperty(String name, String val) {
         aMethodIsCalled();
-
     }
 
     public void setOutputPropertyDefault(String name, String val) {
         aMethodIsCalled();
-
     }
 
     /**
      * @see org.apache.xml.serializer.Serializer#asDOM3Serializer()
      */
-    public Object asDOM3Serializer() throws IOException
-    {
+    public Object asDOM3Serializer() throws IOException {
         couldThrowIOException();
         return null;
     }
--- a/jaxp/src/java.xml/share/classes/com/sun/org/apache/xml/internal/serializer/SerializerBase.java	Tue Nov 22 14:48:16 2016 +0100
+++ b/jaxp/src/java.xml/share/classes/com/sun/org/apache/xml/internal/serializer/SerializerBase.java	Wed Nov 23 08:58:15 2016 +0100
@@ -1,15 +1,13 @@
 /*
- * reserved comment block
- * DO NOT REMOVE OR ALTER!
+ * Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved.
  */
 /*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the  "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
  *
  *     http://www.apache.org/licenses/LICENSE-2.0
  *
@@ -19,22 +17,18 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-/*
- * $Id: SerializerBase.java,v 1.5 2006/04/14 12:09:19 sunithareddy Exp $
- */
+
 package com.sun.org.apache.xml.internal.serializer;
 
+import com.sun.org.apache.xml.internal.serializer.utils.MsgKey;
+import com.sun.org.apache.xml.internal.serializer.utils.Utils;
 import java.io.IOException;
 import java.util.HashMap;
 import java.util.Set;
 import java.util.ArrayList;
-
 import javax.xml.transform.OutputKeys;
 import javax.xml.transform.SourceLocator;
 import javax.xml.transform.Transformer;
-
-import com.sun.org.apache.xml.internal.serializer.utils.MsgKey;
-import com.sun.org.apache.xml.internal.serializer.utils.Utils;
 import org.xml.sax.Attributes;
 import org.xml.sax.ContentHandler;
 import org.xml.sax.Locator;
@@ -42,7 +36,6 @@
 import org.xml.sax.SAXParseException;
 import org.xml.sax.ext.Locator2;
 
-
 /**
  * This class acts as a base class for the XML "serializers"
  * and the stream serializers.
@@ -54,7 +47,6 @@
     implements SerializationHandler, SerializerConstants
 {
 
-
     /**
      * To fire off the end element trace event
      * @param name Name of element
@@ -62,8 +54,7 @@
     protected void fireEndElem(String name)
         throws org.xml.sax.SAXException
     {
-        if (m_tracer != null)
-        {
+        if (m_tracer != null) {
             flushMyWriter();
             m_tracer.fireGenerateEvent(SerializerTrace.EVENTTYPE_ENDELEMENT,name, (Attributes)null);
         }
@@ -78,8 +69,7 @@
     protected void fireCharEvent(char[] chars, int start, int length)
         throws org.xml.sax.SAXException
     {
-        if (m_tracer != null)
-        {
+        if (m_tracer != null) {
             flushMyWriter();
             m_tracer.fireGenerateEvent(SerializerTrace.EVENTTYPE_CHARACTERS, chars, start,length);
         }
@@ -87,7 +77,7 @@
 
     /**
      * true if we still need to call startDocumentInternal()
-         */
+     */
     protected boolean m_needToCallStartDocument = true;
 
     /** True if a trailing "]]>" still needs to be written to be
@@ -150,6 +140,7 @@
      * Flag to tell if indenting (pretty-printing) is on.
      */
     protected boolean m_doIndent = false;
+
     /**
      * Amount to indent.
      */
@@ -186,7 +177,6 @@
 
     protected SourceLocator m_sourceLocator;
 
-
     /**
      * The writer to send output to. This field is only used in the ToStream
      * serializers, but exists here just so that the fireStartDoc() and
@@ -227,11 +217,9 @@
      *
      * @see ExtendedLexicalHandler#comment(String)
      */
-    public void comment(String data) throws SAXException
-    {
+    public void comment(String data) throws SAXException {
         final int length = data.length();
-        if (length > m_charsBuff.length)
-        {
+        if (length > m_charsBuff.length) {
             m_charsBuff = new char[length * 2 + 1];
         }
         data.getChars(0, length, m_charsBuff, 0);
@@ -248,10 +236,7 @@
      * XML file, it sometimes generates a NS prefix of the form "ns?" for
      * an attribute.
      */
-    protected String patchName(String qname)
-    {
-
-
+    protected String patchName(String qname) {
         final int lastColon = qname.lastIndexOf(':');
 
         if (lastColon > 0) {
@@ -259,12 +244,11 @@
             final String prefix = qname.substring(0, firstColon);
             final String localName = qname.substring(lastColon + 1);
 
-        // If uri is "" then ignore prefix
+            // If uri is "" then ignore prefix
             final String uri = m_prefixMap.lookupNamespace(prefix);
             if (uri != null && uri.length() == 0) {
                 return localName;
-            }
-            else if (firstColon != lastColon) {
+            } else if (firstColon != lastColon) {
                 return prefix + ':' + localName;
             }
         }
@@ -277,8 +261,7 @@
      * @param qname the qualified name
      * @return the name, but excluding any prefix and colon.
      */
-    protected static String getLocalName(String qname)
-    {
+    protected static String getLocalName(String qname) {
         final int col = qname.lastIndexOf(':');
         return (col > 0) ? qname.substring(col + 1) : qname;
     }
@@ -309,8 +292,7 @@
      * during the invocation of the events in this interface.  The
      * application should not attempt to use it at any other time.</p>
      */
-    public void setDocumentLocator(Locator locator)
-    {
+    public void setDocumentLocator(Locator locator) {
         m_locator = locator;
     }
 
@@ -332,20 +314,13 @@
      * @param XSLAttribute true if this attribute is coming from an xsl:attriute element
      * @see ExtendedContentHandler#addAttribute(String, String, String, String, String)
      */
-    public void addAttribute(
-        String uri,
-        String localName,
-        String rawName,
-        String type,
-        String value,
-        boolean XSLAttribute)
+    public void addAttribute(String uri, String localName, String rawName,
+                             String type, String value, boolean XSLAttribute)
         throws SAXException
     {
-        if (m_elemContext.m_startTagOpen)
-        {
+        if (m_elemContext.m_startTagOpen) {
             addAttributeAlways(uri, localName, rawName, type, value, XSLAttribute);
         }
-
     }
 
     /**
@@ -362,51 +337,32 @@
      * @return true if the attribute was added,
      * false if an existing value was replaced.
      */
-    public boolean addAttributeAlways(
-        String uri,
-        String localName,
-        String rawName,
-        String type,
-        String value,
-        boolean XSLAttribute)
+    public boolean addAttributeAlways(String uri, String localName, String rawName,
+                                      String type, String value, boolean XSLAttribute)
     {
         boolean was_added;
-//            final int index =
-//                (localName == null || uri == null) ?
-//                m_attributes.getIndex(rawName):m_attributes.getIndex(uri, localName);
-            int index;
-//            if (localName == null || uri == null){
-//                index = m_attributes.getIndex(rawName);
-//            }
-//            else {
-//                index = m_attributes.getIndex(uri, localName);
-//            }
+        int index;
 
-            if (localName == null || uri == null || uri.length() == 0)
-                index = m_attributes.getIndex(rawName);
-            else {
-                index = m_attributes.getIndex(uri,localName);
-            }
-            if (index >= 0)
-            {
-                /* We've seen the attribute before.
-                 * We may have a null uri or localName, but all
-                 * we really want to re-set is the value anyway.
-                 */
-                m_attributes.setValue(index,value);
-                was_added = false;
-            }
-            else
-            {
-                // the attribute doesn't exist yet, create it
-                m_attributes.addAttribute(uri, localName, rawName, type, value);
-                was_added = true;
-            }
-            return was_added;
-
+        if (localName == null || uri == null || uri.length() == 0)
+            index = m_attributes.getIndex(rawName);
+        else {
+            index = m_attributes.getIndex(uri,localName);
+        }
+        if (index >= 0) {
+            /* We've seen the attribute before.
+             * We may have a null uri or localName, but all
+             * we really want to re-set is the value anyway.
+             */
+            m_attributes.setValue(index,value);
+            was_added = false;
+        } else {
+            // the attribute doesn't exist yet, create it
+            m_attributes.addAttribute(uri, localName, rawName, type, value);
+            was_added = true;
+        }
+        return was_added;
     }
 
-
     /**
      *  Adds  the given attribute to the set of collected attributes,
      * but only if there is a currently open element.
@@ -414,16 +370,14 @@
      * @param name the attribute's qualified name
      * @param value the value of the attribute
      */
-    public void addAttribute(String name, final String value)
-    {
-        if (m_elemContext.m_startTagOpen)
-        {
+    public void addAttribute(String name, final String value) {
+        if (m_elemContext.m_startTagOpen) {
             final String patchedName = patchName(name);
             final String localName = getLocalName(patchedName);
             final String uri = getNamespaceURI(patchedName, false);
 
             addAttributeAlways(uri,localName, patchedName, "CDATA", value, false);
-         }
+        }
     }
 
     /**
@@ -434,15 +388,13 @@
      * @param value the value of the attribute
      * @param uri the URI that the prefix of the name points to
      */
-    public void addXSLAttribute(String name, final String value, final String uri)
-    {
-        if (m_elemContext.m_startTagOpen)
-        {
+    public void addXSLAttribute(String name, final String value, final String uri) {
+        if (m_elemContext.m_startTagOpen) {
             final String patchedName = patchName(name);
             final String localName = getLocalName(patchedName);
 
             addAttributeAlways(uri,localName, patchedName, "CDATA", value, true);
-         }
+        }
     }
 
     /**
@@ -451,12 +403,9 @@
      * is currently open.
      * @param atts List of attributes to add to this list
      */
-    public void addAttributes(Attributes atts) throws SAXException
-    {
-
+    public void addAttributes(Attributes atts) throws SAXException {
         int nAtts = atts.getLength();
-        for (int i = 0; i < nAtts; i++)
-        {
+        for (int i = 0; i < nAtts; i++) {
             String uri = atts.getURI(i);
 
             if (null == uri)
@@ -469,7 +418,6 @@
                 atts.getType(i),
                 atts.getValue(i),
                 false);
-
         }
     }
 
@@ -482,8 +430,7 @@
      *  or null if the serializer is not SAX 2 capable
      * @throws IOException An I/O exception occured
      */
-    public ContentHandler asContentHandler() throws IOException
-    {
+    public ContentHandler asContentHandler() throws IOException {
         return this;
     }
 
@@ -494,8 +441,7 @@
      * @throws org.xml.sax.SAXException The application may raise an exception.
      * @see #startEntity
      */
-    public void endEntity(String name) throws org.xml.sax.SAXException
-    {
+    public void endEntity(String name) throws org.xml.sax.SAXException {
         if (name.equals("[dtd]"))
             m_inExternalDTD = false;
         m_inEntityRef = false;
@@ -509,27 +455,24 @@
      * ToStream serializers, not ToSAXHandler serializers.
      * @see ToStream
      */
-    public void close()
-    {
+    public void close() {
         // do nothing (base behavior)
     }
 
     /**
      * Initialize global variables
      */
-    protected void initCDATA()
-    {
+    protected void initCDATA() {
         // CDATA stack
-        //        _cdataStack = new Stack();
-        //        _cdataStack.push(new Integer(-1)); // push dummy value
+        // _cdataStack = new Stack();
+        // _cdataStack.push(new Integer(-1)); // push dummy value
     }
 
     /**
      * Returns the character encoding to be used in the output document.
      * @return the character encoding to be used in the output document.
      */
-    public String getEncoding()
-    {
+    public String getEncoding() {
         return getOutputProperty(OutputKeys.ENCODING);
     }
 
@@ -537,8 +480,7 @@
      * Sets the character encoding coming from the xsl:output encoding stylesheet attribute.
      * @param m_encoding the character encoding
      */
-    public void setEncoding(String encoding)
-    {
+    public void setEncoding(String encoding) {
         setOutputProperty(OutputKeys.ENCODING,encoding);
     }
 
@@ -547,19 +489,16 @@
      * @param b true if the XML declaration is to be omitted from the output
      * document.
      */
-    public void setOmitXMLDeclaration(boolean b)
-    {
+    public void setOmitXMLDeclaration(boolean b) {
         String val = b ? "yes":"no";
         setOutputProperty(OutputKeys.OMIT_XML_DECLARATION,val);
     }
 
-
     /**
      * @return true if the XML declaration is to be omitted from the output
      * document.
      */
-    public boolean getOmitXMLDeclaration()
-    {
+    public boolean getOmitXMLDeclaration() {
         return m_shouldNotWriteXMLHeader;
     }
 
@@ -625,8 +564,7 @@
      * document. This method remembers if the value was explicitly set using
      * this method, verses if the value is the default value.
      */
-    public void setStandalone(String standalone)
-    {
+    public void setStandalone(String standalone) {
         setOutputProperty(OutputKeys.STANDALONE, standalone);
     }
 
@@ -635,8 +573,7 @@
      * default or explicite setting.
      * @param standalone "yes" | "no"
      */
-    protected void setStandaloneInternal(String standalone)
-    {
+    protected void setStandaloneInternal(String standalone) {
         if ("yes".equals(standalone))
             m_standalone = "yes";
         else
@@ -650,8 +587,7 @@
      * be included in the output document.
      *  @see XSLOutputAttributes#getStandalone()
      */
-    public String getStandalone()
-    {
+    public String getStandalone() {
         return m_standalone;
     }
 
@@ -659,8 +595,7 @@
      * @return true if the output document should be indented to visually
      * indicate its structure.
      */
-    public boolean getIndent()
-    {
+    public boolean getIndent() {
         return m_doIndent;
     }
     /**
@@ -669,8 +604,7 @@
      * @return the mediatype the media-type or MIME type associated with the
      * output document.
      */
-    public String getMediaType()
-    {
+    public String getMediaType() {
         return m_mediatype;
     }
 
@@ -678,8 +612,7 @@
      * Gets the version of the output format.
      * @return the version of the output format.
      */
-    public String getVersion()
-    {
+    public String getVersion() {
         return m_version;
     }
 
@@ -688,8 +621,7 @@
      * @param version the version of the output format.
      * @see SerializationHandler#setVersion(String)
      */
-    public void setVersion(String version)
-    {
+    public void setVersion(String version) {
         setOutputProperty(OutputKeys.VERSION, version);
     }
 
@@ -700,16 +632,14 @@
      * @see javax.xml.transform.OutputKeys#MEDIA_TYPE
      * @see SerializationHandler#setMediaType(String)
      */
-    public void setMediaType(String mediaType)
-    {
+    public void setMediaType(String mediaType) {
         setOutputProperty(OutputKeys.MEDIA_TYPE,mediaType);
     }
 
     /**
      * @return the number of spaces to indent for each indentation level.
      */
-    public int getIndentAmount()
-    {
+    public int getIndentAmount() {
         return m_indentAmount;
     }
 
@@ -717,8 +647,7 @@
      * Sets the indentation amount.
      * @param m_indentAmount The m_indentAmount to set
      */
-    public void setIndentAmount(int m_indentAmount)
-    {
+    public void setIndentAmount(int m_indentAmount) {
         this.m_indentAmount = m_indentAmount;
     }
 
@@ -729,8 +658,7 @@
      * visually indicate its structure.
      * @see XSLOutputAttributes#setIndent(boolean)
      */
-    public void setIndent(boolean doIndent)
-    {
+    public void setIndent(boolean doIndent) {
         String val = doIndent ? "yes":"no";
         setOutputProperty(OutputKeys.INDENT,val);
     }
@@ -740,8 +668,7 @@
      * @param isStandalone true if the ORACLE_IS_STANDALONE is set to yes
      * @see OutputPropertiesFactory ORACLE_IS_STANDALONE
      */
-    public void setIsStandalone(boolean isStandalone)
-    {
+    public void setIsStandalone(boolean isStandalone) {
        m_isStandalone = isStandalone;
     }
 
@@ -772,8 +699,7 @@
      * @throws IOException An I/O exception occured
      * @see Serializer#asDOMSerializer()
      */
-    public DOMSerializer asDOMSerializer() throws IOException
-    {
+    public DOMSerializer asDOMSerializer() throws IOException {
         return this;
     }
 
@@ -785,8 +711,7 @@
      *
      * @return true if strings are equal.
      */
-    private static final boolean subPartMatch(String p, String t)
-    {
+    private static final boolean subPartMatch(String p, String t) {
         return (p == t) || ((null != p) && (p.equals(t)));
     }
 
@@ -799,8 +724,7 @@
      * @return returns the prefix of the qualified name,
      * or null if there is no prefix.
      */
-    protected static final String getPrefixPart(String qname)
-    {
+    protected static final String getPrefixPart(String qname) {
         final int col = qname.indexOf(':');
         return (col > 0) ? qname.substring(0, col) : null;
         //return (col > 0) ? qname.substring(0,col) : "";
@@ -811,8 +735,7 @@
      * @return the current namespace mappings (prefix/uri)
      * @see ExtendedContentHandler#getNamespaceMappings()
      */
-    public NamespaceMappings getNamespaceMappings()
-    {
+    public NamespaceMappings getNamespaceMappings() {
         return m_prefixMap;
     }
 
@@ -822,8 +745,7 @@
      * @return a prefix pointing to the given URI (if any).
      * @see ExtendedContentHandler#getPrefix(String)
      */
-    public String getPrefix(String namespaceURI)
-    {
+    public String getPrefix(String namespaceURI) {
         String prefix = m_prefixMap.lookupPrefix(namespaceURI);
         return prefix;
     }
@@ -836,19 +758,15 @@
      * an element.
      * @return returns the namespace URI associated with the qualified name.
      */
-    public String getNamespaceURI(String qname, boolean isElement)
-    {
+    public String getNamespaceURI(String qname, boolean isElement) {
         String uri = EMPTYSTRING;
         int col = qname.lastIndexOf(':');
         final String prefix = (col > 0) ? qname.substring(0, col) : EMPTYSTRING;
 
-        if (!EMPTYSTRING.equals(prefix) || isElement)
-        {
-            if (m_prefixMap != null)
-            {
+        if (!EMPTYSTRING.equals(prefix) || isElement) {
+            if (m_prefixMap != null) {
                 uri = m_prefixMap.lookupNamespace(prefix);
-                if (uri == null && !prefix.equals(XMLNS_PREFIX))
-                {
+                if (uri == null && !prefix.equals(XMLNS_PREFIX)) {
                     throw new RuntimeException(
                         Utils.messages.createMessage(
                             MsgKey.ER_NAMESPACE_PREFIX,
@@ -866,8 +784,7 @@
      * @return the namespace URI currently associated with the
      * prefix, null if the prefix is undefined.
      */
-    public String getNamespaceURIFromPrefix(String prefix)
-    {
+    public String getNamespaceURIFromPrefix(String prefix) {
         String uri = null;
         if (m_prefixMap != null)
             uri = m_prefixMap.lookupNamespace(prefix);
@@ -881,16 +798,14 @@
      *
      * @throws org.xml.sax.SAXException
      */
-    public void entityReference(String name) throws org.xml.sax.SAXException
-    {
-
+    public void entityReference(String name) throws org.xml.sax.SAXException {
         flushPending();
 
         startEntity(name);
         endEntity(name);
 
         if (m_tracer != null)
-                    fireEntityReference(name);
+            fireEntityReference(name);
     }
 
     /**
@@ -898,8 +813,7 @@
      * @param t the transformer associated with this serializer.
      * @see SerializationHandler#setTransformer(Transformer)
      */
-    public void setTransformer(Transformer t)
-    {
+    public void setTransformer(Transformer t) {
         m_transformer = t;
 
         // If this transformer object implements the SerializerTrace interface
@@ -912,13 +826,13 @@
            m_tracer = null;
         }
     }
+
     /**
      * Gets the transformer associated with this serializer
      * @return returns the transformer associated with this serializer.
      * @see SerializationHandler#getTransformer()
      */
-    public Transformer getTransformer()
-    {
+    public Transformer getTransformer() {
         return m_transformer;
     }
 
@@ -933,11 +847,9 @@
     {
         flushPending();
         String data = node.getNodeValue();
-        if (data != null)
-        {
+        if (data != null) {
             final int length = data.length();
-            if (length > m_charsBuff.length)
-            {
+            if (length > m_charsBuff.length) {
                 m_charsBuff = new char[length * 2 + 1];
             }
             data.getChars(0, length, m_charsBuff, 0);
@@ -956,16 +868,13 @@
      * @see org.xml.sax.ErrorHandler#fatalError(SAXParseException)
      */
     public void fatalError(SAXParseException exc) throws SAXException {
-
-      m_elemContext.m_startTagOpen = false;
-
+        m_elemContext.m_startTagOpen = false;
     }
 
     /**
      * @see org.xml.sax.ErrorHandler#warning(SAXParseException)
      */
-    public void warning(SAXParseException exc) throws SAXException
-    {
+    public void warning(SAXParseException exc) throws SAXException {
     }
 
     /**
@@ -983,20 +892,6 @@
     }
 
     /**
-     * Report the characters event
-     * @param chars  content of characters
-     * @param start  starting index of characters to output
-     * @param length  number of characters to output
-     */
-//    protected void fireCharEvent(char[] chars, int start, int length)
-//        throws org.xml.sax.SAXException
-//    {
-//        if (m_tracer != null)
-//            m_tracer.fireGenerateEvent(SerializerTrace.EVENTTYPE_CHARACTERS, chars, start,length);
-//    }
-//
-
-    /**
      * This method is only used internally when flushing the writer from the
      * various fire...() trace events.  Due to the writer being wrapped with
      * SerializerTraceWriter it may cause the flush of these trace events:
@@ -1005,20 +900,15 @@
      * which trace the output written to the output stream.
      *
      */
-    private void flushMyWriter()
-    {
-        if (m_writer != null)
-        {
-            try
-            {
+    private void flushMyWriter() {
+        if (m_writer != null) {
+            try {
                 m_writer.flush();
-            }
-            catch(IOException ioe)
-            {
-
+            } catch(IOException ioe) {
             }
         }
     }
+
     /**
      * Report the CDATA trace event
      * @param chars  content of CDATA
@@ -1028,10 +918,9 @@
     protected void fireCDATAEvent(char[] chars, int start, int length)
         throws org.xml.sax.SAXException
     {
-                if (m_tracer != null)
-        {
+        if (m_tracer != null) {
             flushMyWriter();
-                        m_tracer.fireGenerateEvent(SerializerTrace.EVENTTYPE_CDATA, chars, start,length);
+            m_tracer.fireGenerateEvent(SerializerTrace.EVENTTYPE_CDATA, chars, start,length);
         }
     }
 
@@ -1044,10 +933,9 @@
     protected void fireCommentEvent(char[] chars, int start, int length)
         throws org.xml.sax.SAXException
     {
-                if (m_tracer != null)
-        {
+        if (m_tracer != null) {
             flushMyWriter();
-                        m_tracer.fireGenerateEvent(SerializerTrace.EVENTTYPE_COMMENT, new String(chars, start, length));
+            m_tracer.fireGenerateEvent(SerializerTrace.EVENTTYPE_COMMENT, new String(chars, start, length));
         }
     }
 
@@ -1221,12 +1109,10 @@
      *
      * @see ExtendedContentHandler#setSourceLocator(javax.xml.transform.SourceLocator)
      */
-    public void setSourceLocator(SourceLocator locator)
-    {
+    public void setSourceLocator(SourceLocator locator) {
         m_sourceLocator = locator;
     }
 
-
     /**
      * Used only by TransformerSnapshotImpl to restore the serialization
      * to a previous state.
@@ -1237,8 +1123,7 @@
         m_prefixMap = mappings;
     }
 
-    public boolean reset()
-    {
+    public boolean reset() {
         resetSerializerBase();
         return true;
     }
@@ -1247,8 +1132,7 @@
      * Reset all of the fields owned by SerializerBase
      *
      */
-    private void resetSerializerBase()
-    {
+    private void resetSerializerBase() {
         this.m_attributes.clear();
         this.m_StringOfCDATASections = null;
         this.m_elemContext = new ElemContext();
@@ -1280,13 +1164,12 @@
      *
      * This concept is made clear in the XSLT 2.0 draft.
      */
-    final boolean inTemporaryOutputState()
-    {
+    final boolean inTemporaryOutputState() {
         /* This is a hack. We should really be letting the serializer know
          * that it is in temporary output state with an explicit call, but
          * from a pragmatic point of view (for now anyways) having no output
-         * encoding at all, not even the default UTF-8 indicates that the serializer
-         * is being used for temporary RTF.
+         * encoding at all, not even the default UTF-8 indicates that the
+         * serializer is being used for temporary RTF.
          */
         return (getEncoding() == null);
 
@@ -1295,36 +1178,38 @@
     /**
      * This method adds an attribute the the current element,
      * but should not be used for an xsl:attribute child.
-     * @see ExtendedContentHandler#addAttribute(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String)
+     * @see ExtendedContentHandler#addAttribute(java.lang.String, java.lang.String,
+     *          java.lang.String, java.lang.String, java.lang.String)
      */
-    public void addAttribute(String uri, String localName, String rawName, String type, String value) throws SAXException
+    public void addAttribute(String uri, String localName, String rawName,
+                             String type, String value) throws SAXException
     {
-        if (m_elemContext.m_startTagOpen)
-        {
+        if (m_elemContext.m_startTagOpen) {
             addAttributeAlways(uri, localName, rawName, type, value, false);
         }
     }
 
     /**
-     * @see org.xml.sax.DTDHandler#notationDecl(java.lang.String, java.lang.String, java.lang.String)
+     * @see org.xml.sax.DTDHandler#notationDecl(java.lang.String,
+     *          java.lang.String, java.lang.String)
      */
     public void notationDecl(String arg0, String arg1, String arg2)
-        throws SAXException {
+        throws SAXException
+    {
         // This method just provides a definition to satisfy the interface
-        // A particular sub-class of SerializerBase provides the implementation (if desired)
+        // A particular sub-class of SerializerBase provides the implementation
+        // (if desired)
     }
 
     /**
-     * @see org.xml.sax.DTDHandler#unparsedEntityDecl(java.lang.String, java.lang.String, java.lang.String, java.lang.String)
+     * @see org.xml.sax.DTDHandler#unparsedEntityDecl(java.lang.String,
+     *          java.lang.String, java.lang.String, java.lang.String)
      */
-    public void unparsedEntityDecl(
-        String arg0,
-        String arg1,
-        String arg2,
-        String arg3)
-        throws SAXException {
+    public void unparsedEntityDecl(String arg0, String arg1, String arg2,
+                                   String arg3) throws SAXException {
         // This method just provides a definition to satisfy the interface
-        // A particular sub-class of SerializerBase provides the implementation (if desired)
+        // A particular sub-class of SerializerBase provides the implementation
+        // (if desired)
     }
 
     /**
@@ -1606,6 +1491,7 @@
      * map will have what that attribute maps to.
      */
     private HashMap<String, String> m_OutputProps;
+
     /**
      * A mapping of keys to default values, for example if
      * the default value of the encoding is "UTF-8" then this
@@ -1616,6 +1502,7 @@
     Set<String> getOutputPropDefaultKeys() {
         return m_OutputPropsDefault.keySet();
     }
+
     Set<String> getOutputPropKeys() {
         return m_OutputProps.keySet();
     }
@@ -1634,6 +1521,7 @@
 
         return val;
     }
+
     /**
      *
      * @param name The name of the property, e.g. "{http://myprop}indent-tabs" or "indent".
--- a/jaxp/src/java.xml/share/classes/com/sun/org/apache/xml/internal/serializer/ToSAXHandler.java	Tue Nov 22 14:48:16 2016 +0100
+++ b/jaxp/src/java.xml/share/classes/com/sun/org/apache/xml/internal/serializer/ToSAXHandler.java	Wed Nov 23 08:58:15 2016 +0100
@@ -1,13 +1,13 @@
 /*
- * reserved comment block
- * DO NOT REMOVE OR ALTER!
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
  */
 /*
- * Copyright 2001-2004 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
  *
  *     http://www.apache.org/licenses/LICENSE-2.0
  *
@@ -17,13 +17,10 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-/*
- * $Id: ToSAXHandler.java,v 1.2.4.1 2005/09/22 11:03:15 pvedula Exp $
- */
+
 package com.sun.org.apache.xml.internal.serializer;
 
 import java.util.ArrayList;
-
 import org.xml.sax.Attributes;
 import org.xml.sax.ContentHandler;
 import org.xml.sax.ErrorHandler;
@@ -39,23 +36,16 @@
  *
  * @xsl.usage internal
  */
-public abstract class ToSAXHandler extends SerializerBase
-{
-    public ToSAXHandler()
-    {
-    }
+public abstract class ToSAXHandler extends SerializerBase {
+    public ToSAXHandler() { }
 
-    public ToSAXHandler(
-        ContentHandler hdlr,
-        LexicalHandler lex,
-        String encoding)
-    {
+    public ToSAXHandler(ContentHandler hdlr, LexicalHandler lex, String encoding) {
         setContentHandler(hdlr);
         setLexHandler(lex);
         setEncoding(encoding);
     }
-    public ToSAXHandler(ContentHandler handler, String encoding)
-    {
+
+    public ToSAXHandler(ContentHandler handler, String encoding) {
         setContentHandler(handler);
         setEncoding(encoding);
     }
@@ -90,16 +80,14 @@
     /**
      * Pass callback to the SAX Handler
      */
-    protected void startDocumentInternal() throws SAXException
-    {
-        if (m_needToCallStartDocument)
-        {
+    protected void startDocumentInternal() throws SAXException {
+        if (m_needToCallStartDocument) {
             super.startDocumentInternal();
-
             m_saxHandler.startDocument();
             m_needToCallStartDocument = false;
         }
     }
+
     /**
      * Do nothing.
      * @see org.xml.sax.ext.LexicalHandler#startDTD(String, String, String)
@@ -113,20 +101,20 @@
     /**
      * Receive notification of character data.
      *
-     * @param characters The string of characters to process.
+     * @param chars The string of characters to process.
      *
      * @throws org.xml.sax.SAXException
      *
      * @see ExtendedContentHandler#characters(String)
      */
-    public void characters(String characters) throws SAXException
-    {
-        final int len = characters.length();
-        if (len > m_charsBuff.length)
-        {
-           m_charsBuff = new char[len*2 + 1];
+    public void characters(String chars) throws SAXException {
+        final int len = (chars == null) ? 0 : chars.length();
+        if (len > m_charsBuff.length) {
+            m_charsBuff = new char[len * 2 + 1];
         }
-        characters.getChars(0,len, m_charsBuff, 0);
+        if (len > 0) {
+            chars.getChars(0, len, m_charsBuff, 0);
+        }
         characters(m_charsBuff, 0, len);
     }
 
@@ -135,16 +123,13 @@
      *
      * @see ExtendedLexicalHandler#comment(String)
      */
-    public void comment(String comment) throws SAXException
-    {
+    public void comment(String comment) throws SAXException {
         flushPending();
 
         // Ignore if a lexical handler has not been set
-        if (m_lexHandler != null)
-        {
+        if (m_lexHandler != null) {
             final int len = comment.length();
-            if (len > m_charsBuff.length)
-            {
+            if (len > m_charsBuff.length) {
                m_charsBuff = new char[len*2 + 1];
             }
             comment.getChars(0,len, m_charsBuff, 0);
@@ -153,7 +138,6 @@
             if (m_tracer != null)
                 super.fireCommentEvent(m_charsBuff, 0, len);
         }
-
     }
 
     /**
@@ -167,12 +151,10 @@
         // Redefined in SAXXMLOutput
     }
 
-    protected void closeStartTag() throws SAXException
-    {
+    protected void closeStartTag() throws SAXException {
     }
 
-    protected void closeCDATA() throws SAXException
-    {
+    protected void closeCDATA() throws SAXException {
         // Redefined in SAXXMLOutput
     }
 
@@ -191,12 +173,8 @@
      *
      * @see org.xml.sax.ContentHandler#startElement(String,String,String,Attributes)
      */
-    public void startElement(
-        String arg0,
-        String arg1,
-        String arg2,
-        Attributes arg3)
-        throws SAXException
+    public void startElement(String arg0, String arg1, String arg2,
+                             Attributes arg3) throws SAXException
     {
         if (m_state != null) {
             m_state.resetState(getTransformer());
@@ -211,8 +189,7 @@
      * Sets the LexicalHandler.
      * @param _lexHandler The LexicalHandler to set
      */
-    public void setLexHandler(LexicalHandler _lexHandler)
-    {
+    public void setLexHandler(LexicalHandler _lexHandler) {
         this.m_lexHandler = _lexHandler;
     }
 
@@ -220,11 +197,9 @@
      * Sets the SAX ContentHandler.
      * @param _saxHandler The ContentHandler to set
      */
-    public void setContentHandler(ContentHandler _saxHandler)
-    {
+    public void setContentHandler(ContentHandler _saxHandler) {
         this.m_saxHandler = _saxHandler;
-        if (m_lexHandler == null && _saxHandler instanceof LexicalHandler)
-        {
+        if (m_lexHandler == null && _saxHandler instanceof LexicalHandler) {
             // we are not overwriting an existing LexicalHandler, and _saxHandler
             // is also implements LexicalHandler, so lets use it
             m_lexHandler = (LexicalHandler) _saxHandler;
@@ -236,8 +211,7 @@
      * stream serializers.
      * @see SerializationHandler#setCdataSectionElements(java.util.ArrayList<String>)
      */
-    public void setCdataSectionElements(ArrayList<String> URI_and_localNames)
-    {
+    public void setCdataSectionElements(ArrayList<String> URI_and_localNames) {
         // do nothing
     }
 
@@ -247,8 +221,7 @@
      * @param doOutputNSAttr whether or not namespace declarations
      * should appear as attributes
      */
-    public void setShouldOutputNSAttr(boolean doOutputNSAttr)
-    {
+    public void setShouldOutputNSAttr(boolean doOutputNSAttr) {
         m_shouldGenerateNSAttribute = doOutputNSAttr;
     }
 
@@ -258,8 +231,7 @@
      * also be mirrored with self generated additional attributes of elements
      * that declare the namespace, for example the attribute xmlns:prefix1="uri1"
      */
-    boolean getShouldOutputNSAttr()
-    {
+    boolean getShouldOutputNSAttr() {
         return m_shouldGenerateNSAttribute;
     }
 
@@ -267,27 +239,21 @@
      * This method flushes any pending events, which can be startDocument()
      * closing the opening tag of an element, or closing an open CDATA section.
      */
-    public void flushPending() throws SAXException
-    {
-
-            if (m_needToCallStartDocument)
-            {
+    public void flushPending() throws SAXException {
+            if (m_needToCallStartDocument) {
                 startDocumentInternal();
                 m_needToCallStartDocument = false;
             }
 
-            if (m_elemContext.m_startTagOpen)
-            {
+            if (m_elemContext.m_startTagOpen) {
                 closeStartTag();
                 m_elemContext.m_startTagOpen = false;
             }
 
-            if (m_cdataTagOpen)
-            {
+            if (m_cdataTagOpen) {
                 closeCDATA();
                 m_cdataTagOpen = false;
             }
-
     }
 
     /**
@@ -350,8 +316,7 @@
         throws org.xml.sax.SAXException
     {
         // remember the current node
-        if (m_state != null)
-        {
+        if (m_state != null) {
             m_state.setCurrentNode(node);
         }
 
@@ -392,12 +357,10 @@
      */
     public void warning(SAXParseException exc) throws SAXException {
         super.warning(exc);
-
         if (m_saxHandler instanceof ErrorHandler)
             ((ErrorHandler)m_saxHandler).warning(exc);
     }
 
-
     /**
      * Try's to reset the super class and reset this class for
      * re-use, so that you don't need to create a new serializer
@@ -406,11 +369,9 @@
      * @return true if the class was successfuly reset.
      * @see Serializer#reset()
      */
-    public boolean reset()
-    {
+    public boolean reset() {
         boolean wasReset = false;
-        if (super.reset())
-        {
+        if (super.reset()) {
             resetToSAXHandler();
             wasReset = true;
         }
@@ -421,8 +382,7 @@
      * Reset all of the fields owned by ToSAXHandler class
      *
      */
-    private void resetToSAXHandler()
-    {
+    private void resetToSAXHandler() {
         this.m_lexHandler = null;
         this.m_saxHandler = null;
         this.m_state = null;
--- a/jaxp/src/java.xml/share/classes/com/sun/org/apache/xml/internal/serializer/ToStream.java	Tue Nov 22 14:48:16 2016 +0100
+++ b/jaxp/src/java.xml/share/classes/com/sun/org/apache/xml/internal/serializer/ToStream.java	Wed Nov 23 08:58:15 2016 +0100
@@ -1,15 +1,13 @@
 /*
- * reserved comment block
- * DO NOT REMOVE OR ALTER!
+ * Copyright (c) 2006, 2016, Oracle and/or its affiliates. All rights reserved.
  */
 /*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the  "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
  *
  *     http://www.apache.org/licenses/LICENSE-2.0
  *
@@ -19,12 +17,13 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-/*
- * $Id: ToStream.java,v 1.4 2005/11/10 06:43:26 suresh_emailid Exp $
- */
+
 package com.sun.org.apache.xml.internal.serializer;
 
 import com.sun.org.apache.xalan.internal.utils.SecuritySupport;
+import com.sun.org.apache.xml.internal.serializer.utils.MsgKey;
+import com.sun.org.apache.xml.internal.serializer.utils.Utils;
+import com.sun.org.apache.xml.internal.serializer.utils.WrappedRuntimeException;
 import java.io.IOException;
 import java.io.OutputStream;
 import java.io.OutputStreamWriter;
@@ -36,30 +35,22 @@
 import java.util.Set;
 import java.util.StringTokenizer;
 import java.util.ArrayList;
-
 import javax.xml.transform.ErrorListener;
 import javax.xml.transform.OutputKeys;
 import javax.xml.transform.Transformer;
 import javax.xml.transform.TransformerException;
-
-import com.sun.org.apache.xml.internal.serializer.utils.MsgKey;
-import com.sun.org.apache.xml.internal.serializer.utils.Utils;
-import com.sun.org.apache.xml.internal.serializer.utils.WrappedRuntimeException;
 import org.w3c.dom.Node;
 import org.xml.sax.Attributes;
 import org.xml.sax.ContentHandler;
 import org.xml.sax.SAXException;
 
-//import com.sun.media.sound.IESecurity;
-
 /**
  * This abstract class is a base class for other stream
  * serializers (xml, html, text ...) that write output to a stream.
  *
  * @xsl.usage internal
  */
-abstract public class ToStream extends SerializerBase
-{
+abstract public class ToStream extends SerializerBase {
 
     private static final String COMMENT_BEGIN = "<!--";
     private static final String COMMENT_END = "-->";
@@ -67,7 +58,6 @@
     /** Stack to keep track of disabling output escaping. */
     protected BoolStack m_disableOutputEscapingStates = new BoolStack();
 
-
     /**
      * The encoding information associated with this serializer.
      * Although initially there is no encoding,
@@ -87,21 +77,17 @@
      */
     java.lang.reflect.Method m_canConvertMeth;
 
-
-
     /**
      * Boolean that tells if we already tried to get the converter.
      */
     boolean m_triedToGetConverter = false;
 
-
     /**
      * Opaque reference to the sun.io.CharToByteConverter for this
      * encoding.
      */
     Object m_charToByteConverter = null;
 
-
     /**
      * Stack to keep track of whether or not we need to
      * preserve whitespace.
@@ -139,7 +125,6 @@
      */
     protected int m_maxCharacter = Encodings.getLastPrintable();
 
-
     /**
      * The system line separator for writing out line breaks.
      * The default value is from the system property,
@@ -188,8 +173,8 @@
     protected boolean m_inDoctype = false;
 
     /**
-       * Flag to quickly tell if the encoding is UTF8.
-       */
+     * Flag to quickly tell if the encoding is UTF8.
+     */
     boolean m_isUTF8 = false;
 
     /**
@@ -203,29 +188,23 @@
      */
     private boolean m_expandDTDEntities = true;
 
-
     /**
      * Default constructor
      */
-    public ToStream()
-    {
-    }
+    public ToStream() { }
 
     /**
      * This helper method to writes out "]]>" when closing a CDATA section.
      *
      * @throws org.xml.sax.SAXException
      */
-    protected void closeCDATA() throws org.xml.sax.SAXException
-    {
-        try
-        {
+    protected void closeCDATA() throws org.xml.sax.SAXException {
+        try {
             m_writer.write(CDATA_DELIMITER_CLOSE);
             // write out a CDATA section closing "]]>"
             m_cdataTagOpen = false; // Remember that we have done so.
         }
-        catch (IOException e)
-        {
+        catch (IOException e) {
             throw new SAXException(e);
         }
     }
@@ -237,18 +216,11 @@
      * @param node Node to serialize.
      * @throws IOException An I/O exception occured while serializing
      */
-    public void serialize(Node node) throws IOException
-    {
-
-        try
-        {
-            TreeWalker walker =
-                new TreeWalker(this);
-
+    public void serialize(Node node) throws IOException {
+        try {
+            TreeWalker walker = new TreeWalker(this);
             walker.traverse(node);
-        }
-        catch (org.xml.sax.SAXException se)
-        {
+        } catch (org.xml.sax.SAXException se) {
             throw new WrappedRuntimeException(se);
         }
     }
@@ -260,8 +232,7 @@
      *
      * NEEDSDOC ($objectName$) @return
      */
-    static final boolean isUTF16Surrogate(char c)
-    {
+    static final boolean isUTF16Surrogate(char c) {
         return (c & 0xFC00) == 0xD800;
     }
 
@@ -275,49 +246,40 @@
      *
      * @throws org.xml.sax.SAXException
      */
-    protected final void flushWriter() throws org.xml.sax.SAXException
-    {
-        final java.io.Writer writer = m_writer;
-        if (null != writer)
-        {
-            try
-            {
-                if (writer instanceof WriterToUTF8Buffered)
-                {
+    protected final void flushWriter() throws org.xml.sax.SAXException {
+        final Writer writer = m_writer;
+        if (null != writer) {
+            try {
+                if (writer instanceof WriterToUTF8Buffered) {
                     if (m_shouldFlush)
-                         ((WriterToUTF8Buffered) writer).flush();
+                        ((WriterToUTF8Buffered)writer).flush();
                     else
-                         ((WriterToUTF8Buffered) writer).flushBuffer();
+                        ((WriterToUTF8Buffered)writer).flushBuffer();
                 }
-                if (writer instanceof WriterToASCI)
-                {
+                if (writer instanceof WriterToASCI) {
                     if (m_shouldFlush)
                         writer.flush();
-                }
-                else
-                {
+                } else {
                     // Flush always.
                     // Not a great thing if the writer was created
                     // by this class, but don't have a choice.
                     writer.flush();
                 }
-            }
-            catch (IOException ioe)
-            {
+            } catch (IOException ioe) {
                 throw new org.xml.sax.SAXException(ioe);
             }
         }
     }
 
     OutputStream m_outputStream;
+
     /**
      * Get the output stream where the events will be serialized to.
      *
      * @return reference to the result stream, or null of only a writer was
      * set.
      */
-    public OutputStream getOutputStream()
-    {
+    public OutputStream getOutputStream() {
         return m_outputStream;
     }
 
@@ -341,9 +303,8 @@
         // Do not inline external DTD
         if (m_inExternalDTD)
             return;
-        try
-        {
-            final java.io.Writer writer = m_writer;
+        try {
+            final Writer writer = m_writer;
             DTDprolog();
 
             writer.write("<!ELEMENT ");
@@ -379,13 +340,10 @@
         // Do not inline external DTD
         if (m_inExternalDTD)
             return;
-        try
-        {
+        try {
             DTDprolog();
             outputEntityDecl(name, value);
-        }
-        catch (IOException e)
-        {
+        } catch (IOException e) {
             throw new SAXException(e);
         }
 
@@ -401,7 +359,7 @@
      */
     void outputEntityDecl(String name, String value) throws IOException
     {
-        final java.io.Writer writer = m_writer;
+        final Writer writer = m_writer;
         writer.write("<!ENTITY ");
         writer.write(name);
         writer.write(" \"");
@@ -415,8 +373,7 @@
      *
      * @throws org.xml.sax.SAXException
      */
-    protected final void outputLineSep() throws IOException
-    {
+    protected final void outputLineSep() throws IOException {
         m_writer.write(m_lineSep, 0, m_lineSepLen);
     }
 
@@ -594,20 +551,17 @@
      *
      * @param format The output format to use
      */
-    public void setOutputFormat(Properties format)
-    {
+    public void setOutputFormat(Properties format) {
         boolean shouldFlush = m_shouldFlush;
 
-        if (format != null)
-        {
+        if (format != null) {
             // Set the default values first,
             // and the non-default values after that,
             // just in case there is some unexpected
             // residual values left over from over-ridden default values
             Enumeration propNames;
             propNames = format.propertyNames();
-            while (propNames.hasMoreElements())
-            {
+            while (propNames.hasMoreElements()) {
                 String key = (String) propNames.nextElement();
                 // Get the value, possibly a default value
                 String value = format.getProperty(key);
@@ -629,18 +583,11 @@
         String entitiesFileName =
             (String) format.get(OutputPropertiesFactory.S_KEY_ENTITIES);
 
-        if (null != entitiesFileName)
-        {
-
-            String method =
-                (String) format.get(OutputKeys.METHOD);
-
+        if (null != entitiesFileName) {
+            String method = (String) format.get(OutputKeys.METHOD);
             m_charInfo = CharInfo.getCharInfo(entitiesFileName, method);
         }
 
-
-
-
         m_shouldFlush = shouldFlush;
     }
 
@@ -678,8 +625,7 @@
      *
      * @param writer The output writer stream
      */
-    public void setWriter(Writer writer)
-    {
+    public void setWriter(Writer writer) {
         setWriterInternal(writer, true);
     }
 
@@ -716,8 +662,7 @@
      * operating systems end-of-line separator.
      * @return The previously set value of the serializer.
      */
-    public boolean setLineSepUse(boolean use_sytem_line_break)
-    {
+    public boolean setLineSepUse(boolean use_sytem_line_break) {
         boolean oldValue = m_lineSepUse;
         m_lineSepUse = use_sytem_line_break;
         return oldValue;
@@ -734,8 +679,7 @@
      *
      * @param output The output stream
      */
-    public void setOutputStream(OutputStream output)
-    {
+    public void setOutputStream(OutputStream output) {
         setOutputStreamInternal(output, true);
     }
 
@@ -848,7 +792,7 @@
      */
     private void printSpace(int n) throws IOException
     {
-        final java.io.Writer writer = m_writer;
+        final Writer writer = m_writer;
         for (int i = 0; i < n; i++)
         {
             writer.write(' ');
@@ -888,7 +832,7 @@
             return;
         try
         {
-            final java.io.Writer writer = m_writer;
+            final Writer writer = m_writer;
             DTDprolog();
 
             writer.write("<!ATTLIST ");
@@ -1038,7 +982,7 @@
                             + Integer.toHexString(low)}));
         }
 
-        final java.io.Writer writer = m_writer;
+        final Writer writer = m_writer;
 
         // If we make it to here we have a valid high, low surrogate pair
         if (m_encodingInfo.isInEncoding(c,low)) {
@@ -1089,7 +1033,7 @@
      * @throws java.io.IOException
      */
     protected int accumDefaultEntity(
-        java.io.Writer writer,
+        Writer writer,
         char ch,
         int i,
         char[] chars,
@@ -1146,7 +1090,7 @@
         boolean useSystemLineSeparator)
         throws IOException, org.xml.sax.SAXException
     {
-        final java.io.Writer writer = m_writer;
+        final Writer writer = m_writer;
         int end = start + length;
 
         for (int i = start; i < end; i++)
@@ -1855,7 +1799,7 @@
 
             m_startNewLine = true;
 
-            final java.io.Writer writer = m_writer;
+            final Writer writer = m_writer;
             writer.write('<');
             writer.write(name);
         }
@@ -1926,7 +1870,7 @@
             closeCDATA();
         try
         {
-            final java.io.Writer writer = m_writer;
+            final Writer writer = m_writer;
             writer.write("<!DOCTYPE ");
             writer.write(name);
 
@@ -1987,7 +1931,7 @@
      * @throws java.io.IOException
      * @throws org.xml.sax.SAXException
      */
-    public void processAttributes(java.io.Writer writer, int nAttrs) throws IOException, SAXException
+    public void processAttributes(Writer writer, int nAttrs) throws IOException, SAXException
     {
             /* real SAX attributes are not passed in, so process the
              * attributes that were collected after the startElement call.
@@ -2084,7 +2028,7 @@
 
         try
         {
-            final java.io.Writer writer = m_writer;
+            final Writer writer = m_writer;
             if (m_elemContext.m_startTagOpen)
             {
                 if (m_tracer != null)
@@ -2290,7 +2234,7 @@
             if (shouldIndent() && !m_isStandalone)
                 indent();
 
-            final java.io.Writer writer = m_writer;
+            final Writer writer = m_writer;
             writer.write(COMMENT_BEGIN);
             // Detect occurrences of two consecutive dashes, handle as necessary.
             for (int i = start; i < limit; i++)
@@ -2370,7 +2314,7 @@
                 outputDocTypeDecl(m_elemContext.m_elementName, false);
                 m_needToOutputDocTypeDecl = false;
             }
-            final java.io.Writer writer = m_writer;
+            final Writer writer = m_writer;
             if (!m_inDoctype)
                 writer.write("]>");
             else
@@ -2598,15 +2542,12 @@
      * OutputProperties. Eventually this method should go away and a call
      * to setCdataSectionElements(ArrayList<String> v) should be made directly.
      */
-    private void setCdataSectionElements(String key, Properties props)
-    {
-
+    private void setCdataSectionElements(String key, Properties props) {
         String s = props.getProperty(key);
 
-        if (null != s)
-        {
+        if (null != s) {
             // ArrayList<String> of URI/LocalName pairs
-            ArrayList<String> v = new ArrayList<>();
+            ArrayList<String> al = new ArrayList<>();
             int l = s.length();
             boolean inCurly = false;
             StringBuilder buf = new StringBuilder();
@@ -2624,7 +2565,7 @@
                     {
                         if (buf.length() > 0)
                         {
-                            addCdataSectionElement(buf.toString(), v);
+                            addCdataSectionElement(buf.toString(), al);
                             buf.setLength(0);
                         }
                         continue;
@@ -2640,11 +2581,11 @@
 
             if (buf.length() > 0)
             {
-                addCdataSectionElement(buf.toString(), v);
+                addCdataSectionElement(buf.toString(), al);
                 buf.setLength(0);
             }
             // call the official, public method to set the collected names
-            setCdataSectionElements(v);
+            setCdataSectionElements(al);
         }
 
     }
@@ -2656,25 +2597,19 @@
      *
      * @return a QName object
      */
-    private void addCdataSectionElement(String URI_and_localName, ArrayList<String> v)
-    {
-
-        StringTokenizer tokenizer =
-            new StringTokenizer(URI_and_localName, "{}", false);
+    private void addCdataSectionElement(String URI_and_localName, ArrayList<String> al) {
+        StringTokenizer tokenizer = new StringTokenizer(URI_and_localName, "{}", false);
         String s1 = tokenizer.nextToken();
         String s2 = tokenizer.hasMoreTokens() ? tokenizer.nextToken() : null;
 
-        if (null == s2)
-        {
+        if (null == s2) {
             // add null URI and the local name
-            v.add(null);
-            v.add(s1);
-        }
-        else
-        {
+            al.add(null);
+            al.add(s1);
+        } else {
             // add URI, then local name
-            v.add(s1);
-            v.add(s2);
+            al.add(s1);
+            al.add(s2);
         }
     }
 
@@ -2685,25 +2620,20 @@
      *
      * @param URI_and_localNames an ArrayList of pairs of Strings (URI/local)
      */
-    public void setCdataSectionElements(ArrayList<String> URI_and_localNames)
-    {
+    public void setCdataSectionElements(ArrayList<String> URI_and_localNames) {
         // convert to the new way.
-        if (URI_and_localNames != null)
-        {
+        if (URI_and_localNames != null) {
             final int len = URI_and_localNames.size() - 1;
-            if (len > 0)
-            {
+            if (len > 0) {
                 final StringBuilder sb = new StringBuilder();
-                for (int i = 0; i < len; i += 2)
-                {
+                for (int i = 0; i < len; i += 2) {
                     // whitspace separated "{uri1}local1 {uri2}local2 ..."
                     if (i != 0)
                         sb.append(' ');
                     final String uri = (String) URI_and_localNames.get(i);
                     final String localName =
                         (String) URI_and_localNames.get(i + 1);
-                    if (uri != null)
-                    {
+                    if (uri != null) {
                         // If there is no URI don't put this in, just the localName then.
                         sb.append('{');
                         sb.append(uri);
@@ -3007,25 +2937,19 @@
      * exist. This method should be called everytime an attribute is added,
      * or when an attribute value is changed, or an element is created.
      */
-
-    protected void firePseudoAttributes()
-    {
-        if (m_tracer != null)
-        {
-            try
-            {
+    protected void firePseudoAttributes() {
+        if (m_tracer != null) {
+            try {
                 // flush out the "<elemName" if not already flushed
                 m_writer.flush();
 
                 // make a StringBuffer to write the name="value" pairs to.
                 StringBuffer sb = new StringBuffer();
                 int nAttrs = m_attributes.getLength();
-                if (nAttrs > 0)
-                {
+                if (nAttrs > 0) {
                     // make a writer that internally appends to the same
                     // StringBuffer
-                    java.io.Writer writer =
-                        new ToStream.WritertoStringBuffer(sb);
+                    Writer writer = new ToStream.WritertoStringBuffer(sb);
 
                     processAttributes(writer, nAttrs);
                     // Don't clear the attributes!
@@ -3042,13 +2966,9 @@
                     ch,
                     0,
                     ch.length);
-            }
-            catch (IOException ioe)
-            {
+            } catch (IOException ioe) {
                 // ignore ?
-            }
-            catch (SAXException se)
-            {
+            } catch (SAXException se) {
                 // ignore ?
             }
         }
@@ -3060,41 +2980,35 @@
      * In this manner trace events, and the real writing of attributes will use
      * the same code.
      */
-    private class WritertoStringBuffer extends java.io.Writer
-    {
+    private class WritertoStringBuffer extends Writer {
         final private StringBuffer m_stringbuf;
+
         /**
          * @see java.io.Writer#write(char[], int, int)
          */
-        WritertoStringBuffer(StringBuffer sb)
-        {
+        WritertoStringBuffer(StringBuffer sb) {
             m_stringbuf = sb;
         }
 
-        public void write(char[] arg0, int arg1, int arg2) throws IOException
-        {
+        public void write(char[] arg0, int arg1, int arg2) throws IOException {
             m_stringbuf.append(arg0, arg1, arg2);
         }
+
         /**
          * @see java.io.Writer#flush()
          */
-        public void flush() throws IOException
-        {
-        }
+        public void flush() throws IOException {}
+
         /**
          * @see java.io.Writer#close()
          */
-        public void close() throws IOException
-        {
-        }
-
-        public void write(int i)
-        {
+        public void close() throws IOException {}
+
+        public void write(int i) {
             m_stringbuf.append((char) i);
         }
 
-        public void write(String s)
-        {
+        public void write(String s) {
             m_stringbuf.append(s);
         }
     }
@@ -3104,12 +3018,11 @@
      */
     public void setTransformer(Transformer transformer) {
         super.setTransformer(transformer);
-        if (m_tracer != null
-         && !(m_writer instanceof SerializerTraceWriter)  )
+        if (m_tracer != null && !(m_writer instanceof SerializerTraceWriter)) {
             m_writer = new SerializerTraceWriter(m_writer, m_tracer);
-
-
+        }
     }
+
     /**
      * Try's to reset the super class and reset this class for
      * re-use, so that you don't need to create a new serializer
@@ -3117,11 +3030,9 @@
      *
      * @return true if the class was successfuly reset.
      */
-    public boolean reset()
-    {
+    public boolean reset() {
         boolean wasReset = false;
-        if (super.reset())
-        {
+        if (super.reset()) {
             resetToStream();
             wasReset = true;
         }
@@ -3132,14 +3043,12 @@
      * Reset all of the fields owned by ToStream class
      *
      */
-    private void resetToStream()
-    {
+    private void resetToStream() {
          this.m_cdataStartCalled = false;
          /* The stream is being reset. It is one of
           * ToXMLStream, ToHTMLStream ... and this type can't be changed
           * so neither should m_charInfo which is associated with the
           * type of Stream. Just leave m_charInfo as-is for the next re-use.
-          *
           */
          // this.m_charInfo = null; // don't set to null
 
@@ -3183,173 +3092,150 @@
      *
      * @xsl.usage internal
      */
-    static final class BoolStack
-    {
-
-      /** Array of boolean values          */
-      private boolean m_values[];
-
-      /** Array size allocated           */
-      private int m_allocatedSize;
-
-      /** Index into the array of booleans          */
-      private int m_index;
-
-      /**
-       * Default constructor.  Note that the default
-       * block size is very small, for small lists.
-       */
-      public BoolStack()
-      {
-        this(32);
-      }
-
-      /**
-       * Construct a IntVector, using the given block size.
-       *
-       * @param size array size to allocate
-       */
-      public BoolStack(int size)
-      {
-
-        m_allocatedSize = size;
-        m_values = new boolean[size];
-        m_index = -1;
-      }
-
-      /**
-       * Get the length of the list.
-       *
-       * @return Current length of the list
-       */
-      public final int size()
-      {
-        return m_index + 1;
-      }
-
-      /**
-       * Clears the stack.
-       *
-       */
-      public final void clear()
-      {
-        m_index = -1;
-      }
-
-      /**
-       * Pushes an item onto the top of this stack.
-       *
-       *
-       * @param val the boolean to be pushed onto this stack.
-       * @return  the <code>item</code> argument.
-       */
-      public final boolean push(boolean val)
-      {
-
-        if (m_index == m_allocatedSize - 1)
-          grow();
-
-        return (m_values[++m_index] = val);
-      }
-
-      /**
-       * Removes the object at the top of this stack and returns that
-       * object as the value of this function.
-       *
-       * @return     The object at the top of this stack.
-       * @throws  EmptyStackException  if this stack is empty.
-       */
-      public final boolean pop()
-      {
-        return m_values[m_index--];
-      }
-
-      /**
-       * Removes the object at the top of this stack and returns the
-       * next object at the top as the value of this function.
-       *
-       *
-       * @return Next object to the top or false if none there
-       */
-      public final boolean popAndTop()
-      {
-
-        m_index--;
-
-        return (m_index >= 0) ? m_values[m_index] : false;
-      }
-
-      /**
-       * Set the item at the top of this stack
-       *
-       *
-       * @param b Object to set at the top of this stack
-       */
-      public final void setTop(boolean b)
-      {
-        m_values[m_index] = b;
-      }
-
-      /**
-       * Looks at the object at the top of this stack without removing it
-       * from the stack.
-       *
-       * @return     the object at the top of this stack.
-       * @throws  EmptyStackException  if this stack is empty.
-       */
-      public final boolean peek()
-      {
-        return m_values[m_index];
-      }
-
-      /**
-       * Looks at the object at the top of this stack without removing it
-       * from the stack.  If the stack is empty, it returns false.
-       *
-       * @return     the object at the top of this stack.
-       */
-      public final boolean peekOrFalse()
-      {
-        return (m_index > -1) ? m_values[m_index] : false;
-      }
-
-      /**
-       * Looks at the object at the top of this stack without removing it
-       * from the stack.  If the stack is empty, it returns true.
-       *
-       * @return     the object at the top of this stack.
-       */
-      public final boolean peekOrTrue()
-      {
-        return (m_index > -1) ? m_values[m_index] : true;
-      }
-
-      /**
-       * Tests if this stack is empty.
-       *
-       * @return  <code>true</code> if this stack is empty;
-       *          <code>false</code> otherwise.
-       */
-      public boolean isEmpty()
-      {
-        return (m_index == -1);
-      }
-
-      /**
-       * Grows the size of the stack
-       *
-       */
-      private void grow()
-      {
-
-        m_allocatedSize *= 2;
-
-        boolean newVector[] = new boolean[m_allocatedSize];
-
-        System.arraycopy(m_values, 0, newVector, 0, m_index + 1);
-
-        m_values = newVector;
-      }
+    static final class BoolStack {
+        /** Array of boolean values */
+        private boolean m_values[];
+
+        /** Array size allocated */
+        private int m_allocatedSize;
+
+        /** Index into the array of booleans */
+        private int m_index;
+
+        /**
+         * Default constructor.  Note that the default
+         * block size is very small, for small lists.
+         */
+        public BoolStack() {
+            this(32);
+        }
+
+        /**
+         * Construct a IntVector, using the given block size.
+         *
+         * @param size array size to allocate
+         */
+        public BoolStack(int size) {
+            m_allocatedSize = size;
+            m_values = new boolean[size];
+            m_index = -1;
+        }
+
+        /**
+         * Get the length of the list.
+         *
+         * @return Current length of the list
+         */
+        public final int size() {
+            return m_index + 1;
+        }
+
+        /**
+         * Clears the stack.
+         *
+         */
+        public final void clear() {
+            m_index = -1;
+        }
+
+        /**
+         * Pushes an item onto the top of this stack.
+         *
+         *
+         * @param val the boolean to be pushed onto this stack.
+         * @return  the <code>item</code> argument.
+         */
+        public final boolean push(boolean val) {
+            if (m_index == m_allocatedSize - 1)
+                grow();
+
+            return (m_values[++m_index] = val);
+        }
+
+        /**
+         * Removes the object at the top of this stack and returns that
+         * object as the value of this function.
+         *
+         * @return     The object at the top of this stack.
+         * @throws  EmptyStackException  if this stack is empty.
+         */
+        public final boolean pop() {
+            return m_values[m_index--];
+        }
+
+        /**
+         * Removes the object at the top of this stack and returns the
+         * next object at the top as the value of this function.
+         *
+         *
+         * @return Next object to the top or false if none there
+         */
+        public final boolean popAndTop() {
+            m_index--;
+            return (m_index >= 0) ? m_values[m_index] : false;
+        }
+
+        /**
+         * Set the item at the top of this stack
+         *
+         *
+         * @param b Object to set at the top of this stack
+         */
+        public final void setTop(boolean b) {
+            m_values[m_index] = b;
+        }
+
+        /**
+         * Looks at the object at the top of this stack without removing it
+         * from the stack.
+         *
+         * @return     the object at the top of this stack.
+         * @throws  EmptyStackException  if this stack is empty.
+         */
+        public final boolean peek() {
+            return m_values[m_index];
+        }
+
+        /**
+         * Looks at the object at the top of this stack without removing it
+         * from the stack.  If the stack is empty, it returns false.
+         *
+         * @return     the object at the top of this stack.
+         */
+        public final boolean peekOrFalse() {
+            return (m_index > -1) ? m_values[m_index] : false;
+        }
+
+        /**
+         * Looks at the object at the top of this stack without removing it
+         * from the stack.  If the stack is empty, it returns true.
+         *
+         * @return     the object at the top of this stack.
+         */
+        public final boolean peekOrTrue() {
+            return (m_index > -1) ? m_values[m_index] : true;
+        }
+
+        /**
+         * Tests if this stack is empty.
+         *
+         * @return  <code>true</code> if this stack is empty;
+         *          <code>false</code> otherwise.
+         */
+        public boolean isEmpty() {
+            return (m_index == -1);
+        }
+
+        /**
+         * Grows the size of the stack
+         *
+         */
+        private void grow() {
+            m_allocatedSize *= 2;
+            boolean newVector[] = new boolean[m_allocatedSize];
+            System.arraycopy(m_values, 0, newVector, 0, m_index + 1);
+            m_values = newVector;
+        }
     }
 
     // Implement DTDHandler
@@ -3421,14 +3307,12 @@
      * @throws IOException
      */
     private void DTDprolog() throws SAXException, IOException {
-        final java.io.Writer writer = m_writer;
-        if (m_needToOutputDocTypeDecl)
-        {
+        final Writer writer = m_writer;
+        if (m_needToOutputDocTypeDecl) {
             outputDocTypeDecl(m_elemContext.m_elementName, false);
             m_needToOutputDocTypeDecl = false;
         }
-        if (m_inDoctype)
-        {
+        if (m_inDoctype) {
             writer.write(" [");
             writer.write(m_lineSep, 0, m_lineSepLen);
             m_inDoctype = false;
--- a/jaxp/src/java.xml/share/classes/com/sun/org/apache/xml/internal/serializer/ToUnknownStream.java	Tue Nov 22 14:48:16 2016 +0100
+++ b/jaxp/src/java.xml/share/classes/com/sun/org/apache/xml/internal/serializer/ToUnknownStream.java	Wed Nov 23 08:58:15 2016 +0100
@@ -1,13 +1,13 @@
 /*
- * reserved comment block
- * DO NOT REMOVE OR ALTER!
+ * Copyright (c) 2007, 2016, Oracle and/or its affiliates. All rights reserved.
  */
 /*
- * Copyright 1999-2004 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
  *
  *     http://www.apache.org/licenses/LICENSE-2.0
  *
@@ -17,9 +17,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-/*
- * $Id: ToUnknownStream.java,v 1.3 2005/09/28 13:49:08 pvedula Exp $
- */
+
 package com.sun.org.apache.xml.internal.serializer;
 
 import java.io.IOException;
@@ -27,17 +25,14 @@
 import java.io.Writer;
 import java.util.Properties;
 import java.util.ArrayList;
-
 import javax.xml.transform.SourceLocator;
 import javax.xml.transform.Transformer;
-
 import org.w3c.dom.Node;
 import org.xml.sax.Attributes;
 import org.xml.sax.ContentHandler;
 import org.xml.sax.Locator;
 import org.xml.sax.SAXException;
 
-
 /**
  *This class wraps another SerializationHandler. The wrapped object will either
  * handler XML or HTML, which is not known until a little later when the first XML
@@ -55,7 +50,6 @@
  */
 public final class ToUnknownStream extends SerializerBase
 {
-
     /**
      * The wrapped handler, initially XML but possibly switched to HTML
      */
@@ -71,11 +65,11 @@
      */
     private boolean m_wrapped_handler_not_initialized = false;
 
-
     /**
      * the prefix of the very first tag in the document
      */
     private String m_firstElementPrefix;
+
     /**
      * the element name (including any prefix) of the very first tag in the document
      */
@@ -101,6 +95,7 @@
      * _namespacePrefix has the matching prefix for these URI's
      */
     private ArrayList<String> m_namespaceURI = null;
+
     /**
      * A collection of namespace Prefix (only for first element)
      * _namespaceURI has the matching URIs for these prefix'
@@ -112,34 +107,13 @@
      * was initialized
      */
     private boolean m_needToCallStartDocument = false;
-    /**
-     * true if setVersion() was called before the underlying handler
-     * was initialized
-     */
-    private boolean m_setVersion_called = false;
-    /**
-     * true if setDoctypeSystem() was called before the underlying handler
-     * was initialized
-     */
-    private boolean m_setDoctypeSystem_called = false;
-    /**
-     * true if setDoctypePublic() was called before the underlying handler
-     * was initialized
-     */
-    private boolean m_setDoctypePublic_called = false;
-    /**
-     * true if setMediaType() was called before the underlying handler
-     * was initialized
-     */
-    private boolean m_setMediaType_called = false;
 
     /**
      * Default constructor.
      * Initially this object wraps an XML Stream object, so _handler is never null.
      * That may change later to an HTML Stream object.
      */
-    public ToUnknownStream()
-    {
+    public ToUnknownStream() {
         m_handler = new ToXMLStream();
     }
 
@@ -147,8 +121,7 @@
      * @see Serializer#asContentHandler()
      * @return the wrapped XML or HTML handler
      */
-    public ContentHandler asContentHandler() throws IOException
-    {
+    public ContentHandler asContentHandler() throws IOException {
         /* don't return the real handler ( m_handler ) because
          * that would expose the real handler to the outside.
          * Keep m_handler private so it can be internally swapped
@@ -160,8 +133,7 @@
     /**
      * @see SerializationHandler#close()
      */
-    public void close()
-    {
+    public void close() {
         m_handler.close();
     }
 
@@ -169,8 +141,7 @@
      * @see Serializer#getOutputFormat()
      * @return the properties of the underlying handler
      */
-    public Properties getOutputFormat()
-    {
+    public Properties getOutputFormat() {
         return m_handler.getOutputFormat();
     }
 
@@ -178,8 +149,7 @@
      * @see Serializer#getOutputStream()
      * @return the OutputStream of the underlying XML or HTML handler
      */
-    public OutputStream getOutputStream()
-    {
+    public OutputStream getOutputStream() {
         return m_handler.getOutputStream();
     }
 
@@ -187,8 +157,7 @@
      * @see Serializer#getWriter()
      * @return the Writer of the underlying XML or HTML handler
      */
-    public Writer getWriter()
-    {
+    public Writer getWriter() {
         return m_handler.getWriter();
     }
 
@@ -197,8 +166,7 @@
      * @see Serializer#reset()
      * @return ???
      */
-    public boolean reset()
-    {
+    public boolean reset() {
         return m_handler.reset();
     }
 
@@ -208,10 +176,8 @@
      * @see DOMSerializer#serialize(Node)
      *
      */
-    public void serialize(Node node) throws IOException
-    {
-        if (m_firstTagNotEmitted)
-        {
+    public void serialize(Node node) throws IOException {
+        if (m_firstTagNotEmitted) {
             flush();
         }
         m_handler.serialize(node);
@@ -220,8 +186,7 @@
     /**
      * @see SerializationHandler#setEscaping(boolean)
      */
-    public boolean setEscaping(boolean escape) throws SAXException
-    {
+    public boolean setEscaping(boolean escape) throws SAXException {
         return m_handler.setEscaping(escape);
     }
 
@@ -230,8 +195,7 @@
      * @param format the output properties to set
      * @see Serializer#setOutputFormat(Properties)
      */
-    public void setOutputFormat(Properties format)
-    {
+    public void setOutputFormat(Properties format) {
         m_handler.setOutputFormat(format);
     }
 
@@ -240,8 +204,7 @@
      * @param output the OutputStream to write to
      * @see Serializer#setOutputStream(OutputStream)
      */
-    public void setOutputStream(OutputStream output)
-    {
+    public void setOutputStream(OutputStream output) {
         m_handler.setOutputStream(output);
     }
 
@@ -250,8 +213,7 @@
      * @param writer the writer to write to
      * @see Serializer#setWriter(Writer)
      */
-    public void setWriter(Writer writer)
-    {
+    public void setWriter(Writer writer) {
         m_handler.setWriter(writer);
     }
 
@@ -265,12 +227,8 @@
      * @param XSLAttribute true if this attribute is coming from an xsl:attribute element
      * @see ExtendedContentHandler#addAttribute(String, String, String, String, String)
      */
-    public void addAttribute(
-        String uri,
-        String localName,
-        String rawName,
-        String type,
-        String value)
+    public void addAttribute(String uri, String localName, String rawName,
+                             String type, String value)
         throws SAXException
     {
         addAttribute(uri, localName, rawName, type, value, false);
@@ -286,35 +244,27 @@
      * @param XSLAttribute true if this attribute is coming from an xsl:attribute element
      * @see ExtendedContentHandler#addAttribute(String, String, String, String, String)
      */
-    public void addAttribute(
-        String uri,
-        String localName,
-        String rawName,
-        String type,
-        String value,
-        boolean XSLAttribute)
+    public void addAttribute(String uri, String localName, String rawName,
+                             String type, String value, boolean XSLAttribute)
         throws SAXException
     {
-        if (m_firstTagNotEmitted)
-        {
+        if (m_firstTagNotEmitted) {
             flush();
         }
         m_handler.addAttribute(uri, localName, rawName, type, value, XSLAttribute);
     }
+
     /**
      * Adds an attribute to the currenly open tag
      * @param rawName the attribute name, with prefix (if any)
      * @param value the value of the parameter
      * @see ExtendedContentHandler#addAttribute(String, String)
      */
-    public void addAttribute(String rawName, String value)
-    {
-        if (m_firstTagNotEmitted)
-        {
+    public void addAttribute(String rawName, String value) {
+        if (m_firstTagNotEmitted) {
             flush();
         }
         m_handler.addAttribute(rawName, value);
-
     }
 
     /**
@@ -323,52 +273,50 @@
     public void addUniqueAttribute(String rawName, String value, int flags)
         throws SAXException
     {
-        if (m_firstTagNotEmitted)
-        {
+        if (m_firstTagNotEmitted) {
             flush();
         }
         m_handler.addUniqueAttribute(rawName, value, flags);
-
     }
 
     /**
      * Converts the String to a character array and calls the SAX method
      * characters(char[],int,int);
      *
+     * @param chars The string of characters to process.
+     *
+     * @throws org.xml.sax.SAXException
+     *
      * @see ExtendedContentHandler#characters(String)
      */
-    public void characters(String chars) throws SAXException
-    {
-        final int length = chars.length();
-        if (length > m_charsBuff.length)
-        {
-            m_charsBuff = new char[length*2 + 1];
+    public void characters(String chars) throws SAXException {
+        final int len = (chars == null) ? 0 : chars.length();
+        if (len > m_charsBuff.length) {
+            m_charsBuff = new char[len * 2 + 1];
         }
-        chars.getChars(0, length, m_charsBuff, 0);
-        this.characters(m_charsBuff, 0, length);
+        if (len > 0) {
+            chars.getChars(0, len, m_charsBuff, 0);
+        }
+        this.characters(m_charsBuff, 0, len);
     }
 
     /**
      * Pass the call on to the underlying handler
      * @see ExtendedContentHandler#endElement(String)
      */
-    public void endElement(String elementName) throws SAXException
-    {
-        if (m_firstTagNotEmitted)
-        {
+    public void endElement(String elementName) throws SAXException {
+        if (m_firstTagNotEmitted) {
             flush();
         }
         m_handler.endElement(elementName);
     }
 
-
     /**
      * @see org.xml.sax.ContentHandler#startPrefixMapping(String, String)
      * @param prefix The prefix that maps to the URI
      * @param uri The URI for the namespace
      */
-    public void startPrefixMapping(String prefix, String uri) throws SAXException
-    {
+    public void startPrefixMapping(String prefix, String uri) throws SAXException {
         this.startPrefixMapping(prefix,uri, true);
     }
 
@@ -387,11 +335,12 @@
         throws SAXException
     {
         // hack for XSLTC with finding URI for default namespace
-        if (m_firstTagNotEmitted && m_firstElementURI == null && m_firstElementName != null)
+        if (m_firstTagNotEmitted &&
+            m_firstElementURI == null &&
+            m_firstElementName != null)
         {
             String prefix1 = getPrefixPart(m_firstElementName);
-            if (prefix1 == null && EMPTYSTRING.equals(prefix))
-            {
+            if (prefix1 == null && EMPTYSTRING.equals(prefix)) {
                 // the elements URI is not known yet, and it
                 // doesn't have a prefix, and we are currently
                 // setting the uri for prefix "", so we have
@@ -399,45 +348,36 @@
                 m_firstElementURI = uri;
             }
         }
-        startPrefixMapping(prefix,uri, false);
+        startPrefixMapping(prefix, uri, false);
     }
 
     public boolean startPrefixMapping(String prefix, String uri, boolean shouldFlush)
         throws SAXException
     {
         boolean pushed = false;
-        if (m_firstTagNotEmitted)
-        {
-            if (m_firstElementName != null && shouldFlush)
-            {
+        if (m_firstTagNotEmitted) {
+            if (m_firstElementName != null && shouldFlush) {
                 /* we've already seen a startElement, and this is a prefix mapping
                  * for the up coming element, so flush the old element
                  * then send this event on its way.
                  */
                 flush();
                 pushed = m_handler.startPrefixMapping(prefix, uri, shouldFlush);
-            }
-            else
-            {
-                if (m_namespacePrefix == null)
-                {
+            } else {
+                if (m_namespacePrefix == null) {
                     m_namespacePrefix = new ArrayList<>();
                     m_namespaceURI = new ArrayList<>();
                 }
                 m_namespacePrefix.add(prefix);
                 m_namespaceURI.add(uri);
 
-                if (m_firstElementURI == null)
-                {
+                if (m_firstElementURI == null) {
                     if (prefix.equals(m_firstElementPrefix))
                         m_firstElementURI = uri;
                 }
             }
-
-        }
-        else
-        {
-           pushed = m_handler.startPrefixMapping(prefix, uri, shouldFlush);
+        } else {
+            pushed = m_handler.startPrefixMapping(prefix, uri, shouldFlush);
         }
         return pushed;
     }
@@ -446,54 +386,39 @@
       * This method cannot be cached because default is different in
       * HTML and XML (we need more than a boolean).
       */
-
-    public void setVersion(String version)
-    {
+    public void setVersion(String version) {
         m_handler.setVersion(version);
-
-        // Cache call to setVersion()
-        //       super.setVersion(version);
-        m_setVersion_called = true;
     }
 
     /**
      * @see org.xml.sax.ContentHandler#startDocument()
      */
-    public void startDocument() throws SAXException
-    {
+    public void startDocument() throws SAXException {
         m_needToCallStartDocument = true;
     }
 
-
-
-    public void startElement(String qName) throws SAXException
-    {
+    public void startElement(String qName) throws SAXException {
         this.startElement(null, null, qName, null);
     }
 
-    public void startElement(String namespaceURI, String localName, String qName) throws SAXException
-    {
+    public void startElement(String namespaceURI, String localName,
+                             String qName) throws SAXException {
         this.startElement(namespaceURI, localName, qName, null);
     }
 
-    public void startElement(
-        String namespaceURI,
-        String localName,
-        String elementName,
-        Attributes atts) throws SAXException
+    public void startElement(String namespaceURI, String localName,
+                             String elementName, Attributes atts)
+        throws SAXException
     {
-
-        if (m_needToCallSetDocumentInfo){
+        if (m_needToCallSetDocumentInfo) {
             super.setDocumentInfo();
             m_needToCallSetDocumentInfo = false;
         }
 
         /* we are notified of the start of an element */
-        if (m_firstTagNotEmitted)
-        {
+        if (m_firstTagNotEmitted) {
             /* we have not yet sent the first element on its way */
-            if (m_firstElementName != null)
-            {
+            if (m_firstElementName != null) {
                 /* this is not the first element, but a later one.
                  * But we have the old element pending, so flush it out,
                  * then send this one on its way.
@@ -645,16 +570,14 @@
      * Pass the call on to the underlying handler
      * @see XSLOutputAttributes#getVersion()
      */
-    public String getVersion()
-    {
+    public String getVersion() {
         return m_handler.getVersion();
     }
 
     /**
      * @see XSLOutputAttributes#setDoctype(String, String)
      */
-    public void setDoctype(String system, String pub)
-    {
+    public void setDoctype(String system, String pub) {
         m_handler.setDoctypePublic(pub);
         m_handler.setDoctypeSystem(system);
     }
@@ -665,10 +588,8 @@
      * @param doctype the public doctype to set
      * @see XSLOutputAttributes#setDoctypePublic(String)
      */
-    public void setDoctypePublic(String doctype)
-    {
+    public void setDoctypePublic(String doctype) {
         m_handler.setDoctypePublic(doctype);
-        m_setDoctypePublic_called = true;
     }
 
     /**
@@ -677,18 +598,15 @@
      * @param doctype the system doctype to set
      * @see XSLOutputAttributes#setDoctypeSystem(String)
      */
-    public void setDoctypeSystem(String doctype)
-    {
+    public void setDoctypeSystem(String doctype) {
         m_handler.setDoctypeSystem(doctype);
-        m_setDoctypeSystem_called = true;
     }
 
     /**
      * Pass the call on to the underlying handler
      * @see XSLOutputAttributes#setEncoding(String)
      */
-    public void setEncoding(String encoding)
-    {
+    public void setEncoding(String encoding) {
         m_handler.setEncoding(encoding);
     }
 
@@ -696,34 +614,29 @@
      * Pass the call on to the underlying handler
      * @see XSLOutputAttributes#setIndent(boolean)
      */
-    public void setIndent(boolean indent)
-    {
+    public void setIndent(boolean indent) {
         m_handler.setIndent(indent);
     }
 
     /**
      * Pass the call on to the underlying handler
      */
-    public void setIndentAmount(int value)
-    {
+    public void setIndentAmount(int value) {
         m_handler.setIndentAmount(value);
     }
 
     /**
      * @see XSLOutputAttributes#setMediaType(String)
      */
-    public void setMediaType(String mediaType)
-    {
+    public void setMediaType(String mediaType) {
         m_handler.setMediaType(mediaType);
-        m_setMediaType_called = true;
     }
 
     /**
      * Pass the call on to the underlying handler
      * @see XSLOutputAttributes#setOmitXMLDeclaration(boolean)
      */
-    public void setOmitXMLDeclaration(boolean b)
-    {
+    public void setOmitXMLDeclaration(boolean b) {
         m_handler.setOmitXMLDeclaration(b);
     }
 
@@ -731,27 +644,16 @@
      * Pass the call on to the underlying handler
      * @see XSLOutputAttributes#setStandalone(String)
      */
-    public void setStandalone(String standalone)
-    {
+    public void setStandalone(String standalone) {
         m_handler.setStandalone(standalone);
     }
 
     /**
-     * @see XSLOutputAttributes#setVersion(String)
-     */
-
-    /**
      * Pass the call on to the underlying handler
      * @see org.xml.sax.ext.DeclHandler#attributeDecl(String, String, String, String, String)
      */
-    public void attributeDecl(
-        String arg0,
-        String arg1,
-        String arg2,
-        String arg3,
-        String arg4)
-        throws SAXException
-    {
+    public void attributeDecl(String arg0, String arg1, String arg2,
+                              String arg3, String arg4) throws SAXException {
         m_handler.attributeDecl(arg0, arg1, arg2, arg3, arg4);
     }
 
@@ -761,8 +663,7 @@
      */
     public void elementDecl(String arg0, String arg1) throws SAXException
     {
-        if (m_firstTagNotEmitted)
-        {
+        if (m_firstTagNotEmitted) {
             emitFirstTag();
         }
         m_handler.elementDecl(arg0, arg1);
@@ -778,8 +679,7 @@
         String systemId)
         throws SAXException
     {
-        if (m_firstTagNotEmitted)
-        {
+        if (m_firstTagNotEmitted) {
             flush();
         }
         m_handler.externalEntityDecl(name, publicId, systemId);
@@ -792,8 +692,7 @@
     public void internalEntityDecl(String arg0, String arg1)
         throws SAXException
     {
-        if (m_firstTagNotEmitted)
-        {
+        if (m_firstTagNotEmitted) {
             flush();
         }
         m_handler.internalEntityDecl(arg0, arg1);
@@ -806,29 +705,21 @@
     public void characters(char[] characters, int offset, int length)
         throws SAXException
     {
-        if (m_firstTagNotEmitted)
-        {
+        if (m_firstTagNotEmitted) {
             flush();
         }
-
         m_handler.characters(characters, offset, length);
-
     }
 
     /**
      * Pass the call on to the underlying handler
      * @see org.xml.sax.ContentHandler#endDocument()
      */
-    public void endDocument() throws SAXException
-    {
-        if (m_firstTagNotEmitted)
-        {
+    public void endDocument() throws SAXException {
+        if (m_firstTagNotEmitted) {
             flush();
         }
-
         m_handler.endDocument();
-
-
     }
 
     /**
@@ -838,17 +729,14 @@
     public void endElement(String namespaceURI, String localName, String qName)
         throws SAXException
     {
-        if (m_firstTagNotEmitted)
-        {
+        if (m_firstTagNotEmitted) {
             flush();
             if (namespaceURI == null && m_firstElementURI != null)
                 namespaceURI = m_firstElementURI;
 
-
             if (localName == null && m_firstElementLocalName != null)
                 localName = m_firstElementLocalName;
         }
-
         m_handler.endElement(namespaceURI, localName, qName);
     }
 
@@ -856,8 +744,7 @@
      * Pass the call on to the underlying handler
      * @see org.xml.sax.ContentHandler#endPrefixMapping(String)
      */
-    public void endPrefixMapping(String prefix) throws SAXException
-    {
+    public void endPrefixMapping(String prefix) throws SAXException {
         m_handler.endPrefixMapping(prefix);
     }
 
@@ -1071,12 +958,9 @@
         m_wrapped_handler_not_initialized = false;
     }
 
-    private void emitFirstTag() throws SAXException
-    {
-        if (m_firstElementName != null)
-        {
-            if (m_wrapped_handler_not_initialized)
-            {
+    private void emitFirstTag() throws SAXException {
+        if (m_firstElementName != null) {
+            if (m_wrapped_handler_not_initialized) {
                 initStreamOutput();
                 m_wrapped_handler_not_initialized = false;
             }
@@ -1086,14 +970,11 @@
             m_attributes = null;
 
             // Output namespaces of first tag
-            if (m_namespacePrefix != null)
-            {
+            if (m_namespacePrefix != null) {
                 final int n = m_namespacePrefix.size();
-                for (int i = 0; i < n; i++)
-                {
-                    final String prefix =
-                        (String) m_namespacePrefix.get(i);
-                    final String uri = (String) m_namespaceURI.get(i);
+                for (int i = 0; i < n; i++) {
+                    final String prefix = m_namespacePrefix.get(i);
+                    final String uri = m_namespaceURI.get(i);
                     m_handler.startPrefixMapping(prefix, uri, false);
                 }
                 m_namespacePrefix = null;
@@ -1109,8 +990,7 @@
      * Don't want to override static function on SerializerBase
      * So added Unknown suffix to method name.
      */
-    private String getLocalNameUnknown(String value)
-    {
+    private String getLocalNameUnknown(String value) {
         int idx = value.lastIndexOf(':');
         if (idx >= 0)
             value = value.substring(idx + 1);
@@ -1121,13 +1001,12 @@
     }
 
     /**
-         * Utility function to return prefix
-         *
-         * Don't want to override static function on SerializerBase
-         * So added Unknown suffix to method name.
-         */
-    private String getPrefixPartUnknown(String qname)
-    {
+     * Utility function to return prefix
+     *
+     * Don't want to override static function on SerializerBase
+     * So added Unknown suffix to method name.
+     */
+    private String getPrefixPartUnknown(String qname) {
         final int index = qname.indexOf(':');
         return (index > 0) ? qname.substring(0, index) : EMPTYSTRING;
     }
@@ -1139,8 +1018,7 @@
      *
      * @return true if the first element is an opening <html> tag
      */
-    private boolean isFirstElemHTML()
-    {
+    private boolean isFirstElemHTML() {
         boolean isHTML;
 
         // is the first tag html, not considering the prefix ?
@@ -1148,29 +1026,27 @@
             getLocalNameUnknown(m_firstElementName).equalsIgnoreCase("html");
 
         // Try to rule out if this is not to be an HTML document based on URI
-        if (isHTML
-            && m_firstElementURI != null
-            && !EMPTYSTRING.equals(m_firstElementURI))
+        if (isHTML &&
+            m_firstElementURI != null &&
+            !EMPTYSTRING.equals(m_firstElementURI))
         {
             // the <html> element has a non-trivial namespace
             isHTML = false;
         }
         // Try to rule out if this is an not to be an HTML document based on prefix
-        if (isHTML && m_namespacePrefix != null)
-        {
+        if (isHTML && m_namespacePrefix != null) {
             /* the first element has a name of "html", but lets check the prefix.
              * If the prefix points to a namespace with a URL that is not ""
              * then the doecument doesn't start with an <html> tag, and isn't html
              */
             final int max = m_namespacePrefix.size();
-            for (int i = 0; i < max; i++)
-            {
+            for (int i = 0; i < max; i++) {
                 final String prefix = m_namespacePrefix.get(i);
                 final String uri = m_namespaceURI.get(i);
 
-                if (m_firstElementPrefix != null
-                    && m_firstElementPrefix.equals(prefix)
-                    && !EMPTYSTRING.equals(uri))
+                if (m_firstElementPrefix != null &&
+                    m_firstElementPrefix.equals(prefix) &&
+                    !EMPTYSTRING.equals(uri))
                 {
                     // The first element has a prefix, so it can't be <html>
                     isHTML = false;
@@ -1181,11 +1057,11 @@
         }
         return isHTML;
     }
+
     /**
      * @see Serializer#asDOMSerializer()
      */
-    public DOMSerializer asDOMSerializer() throws IOException
-    {
+    public DOMSerializer asDOMSerializer() throws IOException {
         return m_handler.asDOMSerializer();
     }
 
@@ -1194,15 +1070,14 @@
      * specified in the cdata-section-elements attribute.
      * @see SerializationHandler#setCdataSectionElements(java.util.Vector)
      */
-    public void setCdataSectionElements(ArrayList<String> URI_and_localNames)
-    {
+    public void setCdataSectionElements(ArrayList<String> URI_and_localNames) {
         m_handler.setCdataSectionElements(URI_and_localNames);
     }
+
     /**
      * @see ExtendedContentHandler#addAttributes(org.xml.sax.Attributes)
      */
-    public void addAttributes(Attributes atts) throws SAXException
-    {
+    public void addAttributes(Attributes atts) throws SAXException {
         m_handler.addAttributes(atts);
     }
 
@@ -1211,98 +1086,83 @@
      * Simply returns the mappings of the wrapped handler.
      * @see ExtendedContentHandler#getNamespaceMappings()
      */
-    public NamespaceMappings getNamespaceMappings()
-    {
+    public NamespaceMappings getNamespaceMappings() {
         NamespaceMappings mappings = null;
-        if (m_handler != null)
-        {
+        if (m_handler != null) {
             mappings = m_handler.getNamespaceMappings();
         }
         return mappings;
     }
+
     /**
      * @see SerializationHandler#flushPending()
      */
-    public void flushPending() throws SAXException
-    {
-
+    public void flushPending() throws SAXException {
         flush();
-
         m_handler.flushPending();
     }
 
-    private void flush()
-    {
-        try
-        {
-        if (m_firstTagNotEmitted)
-        {
-            emitFirstTag();
-        }
-        if (m_needToCallStartDocument)
-        {
-            m_handler.startDocument();
-            m_needToCallStartDocument = false;
-        }
-        }
-        catch(SAXException e)
-        {
+    private void flush() {
+        try {
+            if (m_firstTagNotEmitted) {
+                emitFirstTag();
+            }
+            if (m_needToCallStartDocument) {
+                m_handler.startDocument();
+                m_needToCallStartDocument = false;
+            }
+        } catch(SAXException e) {
             throw new RuntimeException(e.toString());
         }
-
-
     }
 
     /**
      * @see ExtendedContentHandler#getPrefix
      */
-    public String getPrefix(String namespaceURI)
-    {
+    public String getPrefix(String namespaceURI) {
         return m_handler.getPrefix(namespaceURI);
     }
+
     /**
      * @see ExtendedContentHandler#entityReference(java.lang.String)
      */
-    public void entityReference(String entityName) throws SAXException
-    {
+    public void entityReference(String entityName) throws SAXException {
         m_handler.entityReference(entityName);
     }
 
     /**
      * @see ExtendedContentHandler#getNamespaceURI(java.lang.String, boolean)
      */
-    public String getNamespaceURI(String qname, boolean isElement)
-    {
+    public String getNamespaceURI(String qname, boolean isElement) {
         return m_handler.getNamespaceURI(qname, isElement);
     }
 
-    public String getNamespaceURIFromPrefix(String prefix)
-    {
+    public String getNamespaceURIFromPrefix(String prefix) {
         return m_handler.getNamespaceURIFromPrefix(prefix);
     }
 
-    public void setTransformer(Transformer t)
-    {
+    public void setTransformer(Transformer t) {
         m_handler.setTransformer(t);
         if ((t instanceof SerializerTrace) &&
-            (((SerializerTrace) t).hasTraceListeners())) {
-           m_tracer = (SerializerTrace) t;
+            (((SerializerTrace) t).hasTraceListeners()))
+        {
+            m_tracer = (SerializerTrace) t;
         } else {
-           m_tracer = null;
+            m_tracer = null;
         }
     }
-    public Transformer getTransformer()
-    {
+
+    public Transformer getTransformer() {
         return m_handler.getTransformer();
     }
 
     /**
      * @see SerializationHandler#setContentHandler(org.xml.sax.ContentHandler)
      */
-    public void setContentHandler(ContentHandler ch)
-    {
+    public void setContentHandler(ContentHandler ch) {
         m_handler.setContentHandler(ch);
     }
+
     /**
      * This method is used to set the source locator, which might be used to
      * generated an error message.
@@ -1310,14 +1170,11 @@
      *
      * @see ExtendedContentHandler#setSourceLocator(javax.xml.transform.SourceLocator)
      */
-    public void setSourceLocator(SourceLocator locator)
-    {
+    public void setSourceLocator(SourceLocator locator) {
         m_handler.setSourceLocator(locator);
     }
 
-    protected void firePseudoElement(String elementName)
-    {
-
+    protected void firePseudoElement(String elementName) {
         if (m_tracer != null) {
             StringBuffer sb = new StringBuffer();
 
--- a/jaxp/src/java.xml/share/classes/com/sun/org/apache/xml/internal/serializer/XSLOutputAttributes.java	Tue Nov 22 14:48:16 2016 +0100
+++ b/jaxp/src/java.xml/share/classes/com/sun/org/apache/xml/internal/serializer/XSLOutputAttributes.java	Wed Nov 23 08:58:15 2016 +0100
@@ -3,13 +3,12 @@
  * DO NOT REMOVE OR ALTER!
  */
 /*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the  "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
  *
  *     http://www.apache.org/licenses/LICENSE-2.0
  *
@@ -19,9 +18,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-/*
- * $Id: XSLOutputAttributes.java,v 1.2.4.1 2005/09/15 08:15:32 suresh_emailid Exp $
- */
+
 package com.sun.org.apache.xml.internal.serializer;
 
 import java.util.ArrayList;
@@ -55,8 +52,7 @@
  *
  * @xsl.usage internal
  */
-interface XSLOutputAttributes
-{
+interface XSLOutputAttributes {
     /**
      * Returns the previously set value of the value to be used as the public
      * identifier in the document type declaration (DTD).
@@ -65,6 +61,7 @@
      * output document.
      */
     public String getDoctypePublic();
+
     /**
      * Returns the previously set value of the value to be used
      * as the system identifier in the document type declaration (DTD).
@@ -73,13 +70,15 @@
      *
      */
     public String getDoctypeSystem();
+
     /**
      * @return the character encoding to be used in the output document.
      */
     public String getEncoding();
+
     /**
-         * @return true if the output document should be indented to visually
-         * indicate its structure.
+     * @return true if the output document should be indented to visually
+     * indicate its structure.
      */
     public boolean getIndent();
 
@@ -87,21 +86,25 @@
      * @return the number of spaces to indent for each indentation level.
      */
     public int getIndentAmount();
+
     /**
      * @return the mediatype the media-type or MIME type associated with the
      * output document.
      */
     public String getMediaType();
+
     /**
      * @return true if the XML declaration is to be omitted from the output
      * document.
      */
     public boolean getOmitXMLDeclaration();
+
     /**
-      * @return a value of "yes" if the <code>standalone</code> delaration is to
-      * be included in the output document.
-      */
+     * @return a value of "yes" if the <code>standalone</code> delaration is to
+     * be included in the output document.
+     */
     public String getStandalone();
+
     /**
      * @return the version of the output format.
      */
@@ -132,20 +135,23 @@
     public void setDoctype(String system, String pub);
 
     /** Set the value coming from the xsl:output doctype-public stylesheet attribute.
-      * @param doctype the public identifier to be used in the DOCTYPE
-      * declaration in the output document.
-      */
+     * @param doctype the public identifier to be used in the DOCTYPE
+     * declaration in the output document.
+     */
     public void setDoctypePublic(String doctype);
+
     /** Set the value coming from the xsl:output doctype-system stylesheet attribute.
-      * @param doctype the system identifier to be used in the DOCTYPE
-      * declaration in the output document.
-      */
+     * @param doctype the system identifier to be used in the DOCTYPE
+     * declaration in the output document.
+     */
     public void setDoctypeSystem(String doctype);
+
     /**
      * Sets the character encoding coming from the xsl:output encoding stylesheet attribute.
      * @param encoding the character encoding
      */
     public void setEncoding(String encoding);
+
     /**
      * Sets the value coming from the xsl:output indent stylesheet
      * attribute.
@@ -153,18 +159,21 @@
      * indicate its structure.
      */
     public void setIndent(boolean indent);
+
     /**
      * Sets the value coming from the xsl:output media-type stylesheet attribute.
      * @param mediatype the media-type or MIME type associated with the output
      * document.
      */
     public void setMediaType(String mediatype);
+
     /**
      * Sets the value coming from the xsl:output omit-xml-declaration stylesheet attribute
      * @param b true if the XML declaration is to be omitted from the output
      * document.
      */
     public void setOmitXMLDeclaration(boolean b);
+
     /**
      * Sets the value coming from the xsl:output standalone stylesheet attribute.
      * @param standalone a value of "yes" indicates that the
@@ -172,6 +181,7 @@
      * document.
      */
     public void setStandalone(String standalone);
+
     /**
      * Sets the value coming from the xsl:output version attribute.
      * @param version the version of the output format.
@@ -194,6 +204,7 @@
      * @return The value of the parameter
      */
     public String getOutputProperty(String name);
+
     /**
      * Get the default value for a property that affects seraialization,
      * or null if there is none. It is possible that a non-default value
@@ -203,6 +214,7 @@
      * @return The default value of the parameter, or null if there is no default value.
      */
     public String getOutputPropertyDefault(String name);
+
     /**
      * Set the non-default value for a property that affects seraialization.
      * @param name The name of the property, which is just the local name
@@ -216,7 +228,7 @@
      * </ul>
      * @val The non-default value of the parameter
      */
-    public void   setOutputProperty(String name, String val);
+    public void setOutputProperty(String name, String val);
 
     /**
      * Set the default value for a property that affects seraialization.
@@ -231,5 +243,5 @@
      * </ul>
      * @val The default value of the parameter
      */
-    public void   setOutputPropertyDefault(String name, String val);
+    public void setOutputPropertyDefault(String name, String val);
 }
--- a/jaxp/test/javax/xml/jaxp/unittest/transform/TransformerTest.java	Tue Nov 22 14:48:16 2016 +0100
+++ b/jaxp/test/javax/xml/jaxp/unittest/transform/TransformerTest.java	Wed Nov 23 08:58:15 2016 +0100
@@ -27,17 +27,20 @@
 
 import java.io.BufferedReader;
 import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.FileReader;
 import java.io.IOException;
-import java.io.InputStream;
 import java.io.StringReader;
 import java.io.StringWriter;
 
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
 import javax.xml.transform.Transformer;
 import javax.xml.transform.TransformerException;
 import javax.xml.transform.TransformerFactory;
 import javax.xml.transform.dom.DOMResult;
+import javax.xml.transform.dom.DOMSource;
 import javax.xml.transform.sax.SAXSource;
 import javax.xml.transform.stream.StreamResult;
 import javax.xml.transform.stream.StreamSource;
@@ -47,6 +50,7 @@
 import org.testng.annotations.Listeners;
 import org.testng.annotations.Test;
 import org.w3c.dom.Document;
+import org.w3c.dom.Element;
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
 import org.xml.sax.ContentHandler;
@@ -69,33 +73,10 @@
  * @run testng/othervm -DrunSecMngr=true transform.TransformerTest
  * @run testng/othervm transform.TransformerTest
  * @summary Transformer Tests
- * @bug 6272879 6305029 6505031 8150704 8162598
+ * @bug 6272879 6305029 6505031 8150704 8162598 8169772
  */
 @Listeners({jaxp.library.FilePolicy.class})
 public class TransformerTest {
-    private Transformer createTransformer() throws TransformerException {
-        return TransformerFactory.newInstance().newTransformer();
-    }
-
-    private Transformer createTransformerFromInputstream(InputStream xslStream) throws TransformerException {
-        return TransformerFactory.newInstance().newTransformer(new StreamSource(xslStream));
-    }
-
-    private Transformer createTransformerFromResource(String xslResource) throws TransformerException {
-        return TransformerFactory.newInstance().newTransformer(new StreamSource(getClass().getResource(xslResource).toString()));
-    }
-
-    private Document transformInputStreamToDocument(Transformer transformer, InputStream sourceStream) throws TransformerException {
-        DOMResult response = new DOMResult();
-        transformer.transform(new StreamSource(sourceStream), response);
-        return (Document)response.getNode();
-    }
-
-    private StringWriter transformResourceToStringWriter(Transformer transformer, String xmlResource) throws TransformerException {
-        StringWriter sw = new StringWriter();
-        transformer.transform(new StreamSource(getClass().getResource(xmlResource).toString()), new StreamResult(sw));
-        return sw;
-    }
 
     /**
      * Reads the contents of the given file into a string.
@@ -302,10 +283,15 @@
         System.out.println(sourceXml);
         System.out.println();
 
+        // transform to DOM result
+        TransformerFactory tf = TransformerFactory.newInstance();
+        Transformer t = tf.newTransformer(new StreamSource(new ByteArrayInputStream(xsl.getBytes())));
+        DOMResult result = new DOMResult();
+        t.transform(new StreamSource(new ByteArrayInputStream(sourceXml.getBytes())), result);
+        Document document = (Document)result.getNode();
+
         System.out.println("Result after transformation:");
         System.out.println("============================");
-        Document document = transformInputStreamToDocument(createTransformerFromInputstream(new ByteArrayInputStream(xsl.getBytes())),
-            new ByteArrayInputStream(sourceXml.getBytes()));
         OutputFormat format = new OutputFormat();
         format.setIndenting(true);
         new XMLSerializer(System.out, format).serialize(document);
@@ -335,13 +321,14 @@
         // test SAXSource
         SAXSource saxSource = new SAXSource(new XMLReaderFor6305029(), new InputSource());
         StringWriter resultWriter = new StringWriter();
-        createTransformer().transform(saxSource, new StreamResult(resultWriter));
+        TransformerFactory tf = TransformerFactory.newInstance();
+        tf.newTransformer().transform(saxSource, new StreamResult(resultWriter));
         AssertJUnit.assertEquals("Identity transform of SAXSource", XML_DOCUMENT, resultWriter.toString());
 
         // test StreamSource
         StreamSource streamSource = new StreamSource(new StringReader(XML_DOCUMENT));
         resultWriter = new StringWriter();
-        createTransformer().transform(streamSource, new StreamResult(resultWriter));
+        tf.newTransformer().transform(streamSource, new StreamResult(resultWriter));
         AssertJUnit.assertEquals("Identity transform of StreamSource", XML_DOCUMENT, resultWriter.toString());
     }
 
@@ -351,10 +338,13 @@
      */
     @Test
     public final void testBug6505031() throws TransformerException {
-        Transformer transformer = createTransformerFromResource("transform.xsl");
-        transformer.setParameter("config", getClass().getResource("config.xml").toString());
-        transformer.setParameter("mapsFile", getClass().getResource("maps.xml").toString());
-        String s = transformResourceToStringWriter(transformer, "template.xml").toString();
+        TransformerFactory tf = TransformerFactory.newInstance();
+        Transformer t = tf.newTransformer(new StreamSource(getClass().getResource("transform.xsl").toString()));
+        t.setParameter("config", getClass().getResource("config.xml").toString());
+        t.setParameter("mapsFile", getClass().getResource("maps.xml").toString());
+        StringWriter sw = new StringWriter();
+        t.transform(new StreamSource(getClass().getResource("template.xml").toString()), new StreamResult(sw));
+        String s = sw.toString();
         Assert.assertTrue(s.contains("map1key1value") && s.contains("map2key1value"));
     }
 
@@ -365,17 +355,20 @@
     @Test
     public final void testBug8150704() throws TransformerException, IOException {
         System.out.println("Testing transformation of Bug8150704-1.xml...");
-        Transformer transformer = createTransformerFromResource("Bug8150704-1.xsl");
-        StringWriter result = transformResourceToStringWriter(transformer, "Bug8150704-1.xml");
-        String resultstring = result.toString().replaceAll("\\r\\n", "\n").replaceAll("\\r", "\n");
+        TransformerFactory tf = TransformerFactory.newInstance();
+        Transformer t = tf.newTransformer(new StreamSource(getClass().getResource("Bug8150704-1.xsl").toString()));
+        StringWriter sw = new StringWriter();
+        t.transform(new StreamSource(getClass().getResource("Bug8150704-1.xml").toString()), new StreamResult(sw));
+        String resultstring = sw.toString().replaceAll("\\r\\n", "\n").replaceAll("\\r", "\n");
         String reference = getFileContentAsString(new File(getClass().getResource("Bug8150704-1.ref").getPath()));
         Assert.assertEquals(resultstring, reference, "Output of transformation of Bug8150704-1.xml does not match reference");
         System.out.println("Passed.");
 
         System.out.println("Testing transformation of Bug8150704-2.xml...");
-        transformer = createTransformerFromResource("Bug8150704-2.xsl");
-        result = transformResourceToStringWriter(transformer, "Bug8150704-2.xml");
-        resultstring = result.toString().replaceAll("\\r\\n", "\n").replaceAll("\\r", "\n");
+        t = tf.newTransformer(new StreamSource(getClass().getResource("Bug8150704-2.xsl").toString()));
+        sw = new StringWriter();
+        t.transform(new StreamSource(getClass().getResource("Bug8150704-2.xml").toString()), new StreamResult(sw));
+        resultstring = sw.toString().replaceAll("\\r\\n", "\n").replaceAll("\\r", "\n");
         reference = getFileContentAsString(new File(getClass().getResource("Bug8150704-2.ref").getPath()));
         Assert.assertEquals(resultstring, reference, "Output of transformation of Bug8150704-2.xml does not match reference");
         System.out.println("Passed.");
@@ -422,11 +415,15 @@
         System.out.println(sourceXml);
         System.out.println();
 
+        // transform to DOM result
+        TransformerFactory tf = TransformerFactory.newInstance();
+        Transformer t = tf.newTransformer(new StreamSource(new ByteArrayInputStream(xsl.getBytes())));
+        DOMResult result = new DOMResult();
+        t.transform(new StreamSource(new ByteArrayInputStream(sourceXml.getBytes())), result);
+        Document document = (Document)result.getNode();
+
         System.out.println("Result after transformation:");
         System.out.println("============================");
-        Document document = transformInputStreamToDocument(
-            createTransformerFromInputstream(new ByteArrayInputStream(xsl.getBytes())),
-                                             new ByteArrayInputStream(sourceXml.getBytes()));
         OutputFormat format = new OutputFormat();
         format.setIndenting(true);
         new XMLSerializer(System.out, format).serialize(document);
@@ -438,4 +435,38 @@
         checkNodeNS8162598(document.getElementsByTagName("test5").item(0), "ns1", "ns1", null);
         Assert.assertNull(document.getElementsByTagName("test6").item(0).getNamespaceURI(), "unexpected namespace for test6");
     }
+
+    /**
+     * @bug 8169772
+     * @summary Test transformation of DOM with null valued text node
+     *
+     * This test would throw a NullPointerException during transform when the
+     * fix was not present.
+     */
+    @Test
+    public final void testBug8169772() throws ParserConfigurationException,
+        SAXException, IOException, TransformerException
+    {
+        // create a small DOM
+        Document doc = DocumentBuilderFactory.newInstance().
+            newDocumentBuilder().parse(
+                new ByteArrayInputStream(
+                    "<?xml version=\"1.0\"?><DOCROOT/>".getBytes()
+                )
+            );
+
+        // insert a bad element
+        Element e = doc.createElement("ERROR");
+        e.appendChild(doc.createTextNode(null));
+        doc.getDocumentElement().appendChild(e);
+
+        // transform
+        ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        TransformerFactory.newInstance().newTransformer().transform(
+            new DOMSource(doc.getDocumentElement()), new StreamResult(bos)
+        );
+        System.out.println("Transformation result (DOM with null text node):");
+        System.out.println("================================================");
+        System.out.println(bos);
+    }
 }