Fixing NPEs which can occur when the char array in the XMLString is null.

git-svn-id: https://svn.apache.org/repos/asf/xerces/java/tags/Xerces-J_2_8_0@381842 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/org/apache/xerces/impl/xs/opti/SchemaDOM.java b/src/org/apache/xerces/impl/xs/opti/SchemaDOM.java
index 008ac94..7d6df5f 100644
--- a/src/org/apache/xerces/impl/xs/opti/SchemaDOM.java
+++ b/src/org/apache/xerces/impl/xs/opti/SchemaDOM.java
@@ -147,12 +147,20 @@
     
     // note that this will only be called within appinfo/documentation
     void comment(XMLString text) {
-        fAnnotationBuffer.append("<!--").append(text.ch, text.offset, text.length).append("-->");
+        fAnnotationBuffer.append("<!--");
+        if (text.length > 0) {
+            fAnnotationBuffer.append(text.ch, text.offset, text.length);
+        }
+        fAnnotationBuffer.append("-->");
     }
     
     // note that this will only be called within appinfo/documentation
     void processingInstruction(String target, XMLString data) {
-        fAnnotationBuffer.append("<?").append(target).append(" ").append(data.ch, data.offset, data.length).append("?>");
+        fAnnotationBuffer.append("<?").append(target);
+        if (data.length > 0) {
+            fAnnotationBuffer.append(' ').append(data.ch, data.offset, data.length);
+        }
+        fAnnotationBuffer.append("?>");
     }
     
     // note that this will only be called within appinfo/documentation
diff --git a/src/org/apache/xerces/parsers/AbstractDOMParser.java b/src/org/apache/xerces/parsers/AbstractDOMParser.java
index b637d51..96e2708 100644
--- a/src/org/apache/xerces/parsers/AbstractDOMParser.java
+++ b/src/org/apache/xerces/parsers/AbstractDOMParser.java
@@ -580,7 +580,9 @@
         if (fInDTD) {
             if (fInternalSubset != null && !fInDTDExternalSubset) {
                 fInternalSubset.append ("<!-- ");
-                fInternalSubset.append (text.ch, text.offset, text.length);
+                if (text.length > 0) {
+                    fInternalSubset.append (text.ch, text.offset, text.length);
+                }
                 fInternalSubset.append (" -->");
             }
             return;
@@ -654,10 +656,10 @@
             if (fInternalSubset != null && !fInDTDExternalSubset) {
                 fInternalSubset.append ("<?");
                 fInternalSubset.append (target);
-                fInternalSubset.append (' ');
-                fInternalSubset.append (data.ch, data.offset, data.length);
+                if (data.length > 0) {
+                    fInternalSubset.append (' ').append (data.ch, data.offset, data.length);
+                }
                 fInternalSubset.append ("?>");
-
             }
             return;
         }
@@ -1153,7 +1155,9 @@
                         }
                         fFirstChunk = false;
                     }
-                    fStringBuffer.append (text.ch, text.offset, text.length);
+                    if (text.length > 0) {
+                        fStringBuffer.append (text.ch, text.offset, text.length);
+                    }
                 }
                 else {
                     fFirstChunk = true;