Skip to content

Commit 8807747

Browse files
author
Michael Glavassevich
committed
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
1 parent 71c5010 commit 8807747

2 files changed

Lines changed: 19 additions & 7 deletions

File tree

src/org/apache/xerces/impl/xs/opti/SchemaDOM.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,12 +147,20 @@ public void endElement() {
147147

148148
// note that this will only be called within appinfo/documentation
149149
void comment(XMLString text) {
150-
fAnnotationBuffer.append("<!--").append(text.ch, text.offset, text.length).append("-->");
150+
fAnnotationBuffer.append("<!--");
151+
if (text.length > 0) {
152+
fAnnotationBuffer.append(text.ch, text.offset, text.length);
153+
}
154+
fAnnotationBuffer.append("-->");
151155
}
152156

153157
// note that this will only be called within appinfo/documentation
154158
void processingInstruction(String target, XMLString data) {
155-
fAnnotationBuffer.append("<?").append(target).append(" ").append(data.ch, data.offset, data.length).append("?>");
159+
fAnnotationBuffer.append("<?").append(target);
160+
if (data.length > 0) {
161+
fAnnotationBuffer.append(' ').append(data.ch, data.offset, data.length);
162+
}
163+
fAnnotationBuffer.append("?>");
156164
}
157165

158166
// note that this will only be called within appinfo/documentation

src/org/apache/xerces/parsers/AbstractDOMParser.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,9 @@ public void comment (XMLString text, Augmentations augs) throws XNIException {
580580
if (fInDTD) {
581581
if (fInternalSubset != null && !fInDTDExternalSubset) {
582582
fInternalSubset.append ("<!-- ");
583-
fInternalSubset.append (text.ch, text.offset, text.length);
583+
if (text.length > 0) {
584+
fInternalSubset.append (text.ch, text.offset, text.length);
585+
}
584586
fInternalSubset.append (" -->");
585587
}
586588
return;
@@ -654,10 +656,10 @@ public void processingInstruction (String target, XMLString data, Augmentations
654656
if (fInternalSubset != null && !fInDTDExternalSubset) {
655657
fInternalSubset.append ("<?");
656658
fInternalSubset.append (target);
657-
fInternalSubset.append (' ');
658-
fInternalSubset.append (data.ch, data.offset, data.length);
659+
if (data.length > 0) {
660+
fInternalSubset.append (' ').append (data.ch, data.offset, data.length);
661+
}
659662
fInternalSubset.append ("?>");
660-
661663
}
662664
return;
663665
}
@@ -1153,7 +1155,9 @@ else if (!fInDTD) {
11531155
}
11541156
fFirstChunk = false;
11551157
}
1156-
fStringBuffer.append (text.ch, text.offset, text.length);
1158+
if (text.length > 0) {
1159+
fStringBuffer.append (text.ch, text.offset, text.length);
1160+
}
11571161
}
11581162
else {
11591163
fFirstChunk = true;

0 commit comments

Comments
 (0)