Program: 48217
Project: 48217
Buggy source:
/** 
 * Emit node (start element or characters).
 * @param rtx Sirix {@link XdmNodeReadTrx}
 */
@Override protected void emitNode(final XdmNodeReadTrx rtx){
  try {
switch (rtx.getKind()) {
case DOCUMENT:
      if (mIndent) {
        mOut.write(CharsForSerializing.NEWLINE.getBytes());
      }
    break;
case ELEMENT:
  indent();
mOut.write(CharsForSerializing.OPEN.getBytes());
writeQName(rtx);
final long key=rtx.getNodeKey();
for (int index=0, nspCount=rtx.getNamespaceCount(); index < nspCount; index++) {
rtx.moveToNamespace(index);
if (rtx.getPrefixKey() == -1) {
mOut.write(CharsForSerializing.XMLNS.getBytes());
write(rtx.nameForKey(rtx.getURIKey()));
mOut.write(CharsForSerializing.QUOTE.getBytes());
}
 else {
mOut.write(CharsForSerializing.XMLNS_COLON.getBytes());
write(rtx.nameForKey(rtx.getPrefixKey()));
mOut.write(CharsForSerializing.EQUAL_QUOTE.getBytes());
write(rtx.nameForKey(rtx.getURIKey()));
mOut.write(CharsForSerializing.QUOTE.getBytes());
}
rtx.moveTo(key);
}
if (mSerializeId) {
if (mSerializeRest) {
mOut.write(CharsForSerializing.REST_PREFIX.getBytes());
}
 else {
mOut.write(CharsForSerializing.SPACE.getBytes());
}
mOut.write(CharsForSerializing.ID.getBytes());
mOut.write(CharsForSerializing.EQUAL_QUOTE.getBytes());
write(rtx.getNodeKey());
mOut.write(CharsForSerializing.QUOTE.getBytes());
}
for (int index=0, attCount=rtx.getAttributeCount(); index < attCount; index++) {
rtx.moveToAttribute(index);
mOut.write(CharsForSerializing.SPACE.getBytes());
writeQName(rtx);
mOut.write(CharsForSerializing.EQUAL_QUOTE.getBytes());
mOut.write(XMLToken.escapeAttribute(rtx.getValue()).getBytes(Constants.DEFAULT_ENCODING));
mOut.write(CharsForSerializing.QUOTE.getBytes());
rtx.moveTo(key);
}
if (rtx.hasFirstChild()) {
mOut.write(CharsForSerializing.CLOSE.getBytes());
}
 else {
mOut.write(CharsForSerializing.SLASH_CLOSE.getBytes());
}
if (mIndent) {
mOut.write(CharsForSerializing.NEWLINE.getBytes());
}
break;
case COMMENT:
indent();
mOut.write(CharsForSerializing.OPENCOMMENT.getBytes());
mOut.write(XMLToken.escapeContent(rtx.getValue()).getBytes(Constants.DEFAULT_ENCODING));
if (mIndent) {
mOut.write(CharsForSerializing.NEWLINE.getBytes());
}
mOut.write(CharsForSerializing.CLOSECOMMENT.getBytes());
break;
case TEXT:
indent();
mOut.write(XMLToken.escapeContent(rtx.getValue()).getBytes(Constants.DEFAULT_ENCODING));
if (mIndent) {
mOut.write(CharsForSerializing.NEWLINE.getBytes());
}
break;
case PROCESSING_INSTRUCTION:
indent();
mOut.write(CharsForSerializing.OPENPI.getBytes());
writeQName(rtx);
mOut.write(CharsForSerializing.SPACE.getBytes());
mOut.write(XMLToken.escapeContent(rtx.getValue()).getBytes(Constants.DEFAULT_ENCODING));
if (mIndent) {
mOut.write(CharsForSerializing.NEWLINE.getBytes());
}
mOut.write(CharsForSerializing.CLOSEPI.getBytes());
break;
default :
throw new IllegalStateException("String_Node_Str");
}
}
 catch (final IOException e) {
LOGWRAPPER.error(e.getMessage(),e);
}
}

Fixed version (ground truth):
/** 
 * Emit node (start element or characters).
 * @param rtx Sirix {@link XdmNodeReadTrx}
 */
@Override protected void emitNode(final XdmNodeReadTrx rtx){
  try {
switch (rtx.getKind()) {
case DOCUMENT:
      break;
case ELEMENT:
    indent();
  mOut.write(CharsForSerializing.OPEN.getBytes());
writeQName(rtx);
final long key=rtx.getNodeKey();
for (int index=0, nspCount=rtx.getNamespaceCount(); index < nspCount; index++) {
rtx.moveToNamespace(index);
if (rtx.getPrefixKey() == -1) {
mOut.write(CharsForSerializing.XMLNS.getBytes());
write(rtx.nameForKey(rtx.getURIKey()));
mOut.write(CharsForSerializing.QUOTE.getBytes());
}
 else {
mOut.write(CharsForSerializing.XMLNS_COLON.getBytes());
write(rtx.nameForKey(rtx.getPrefixKey()));
mOut.write(CharsForSerializing.EQUAL_QUOTE.getBytes());
write(rtx.nameForKey(rtx.getURIKey()));
mOut.write(CharsForSerializing.QUOTE.getBytes());
}
rtx.moveTo(key);
}
if (mSerializeId) {
if (mSerializeRest) {
mOut.write(CharsForSerializing.REST_PREFIX.getBytes());
}
 else {
mOut.write(CharsForSerializing.SPACE.getBytes());
}
mOut.write(CharsForSerializing.ID.getBytes());
mOut.write(CharsForSerializing.EQUAL_QUOTE.getBytes());
write(rtx.getNodeKey());
mOut.write(CharsForSerializing.QUOTE.getBytes());
}
for (int index=0, attCount=rtx.getAttributeCount(); index < attCount; index++) {
rtx.moveToAttribute(index);
mOut.write(CharsForSerializing.SPACE.getBytes());
writeQName(rtx);
mOut.write(CharsForSerializing.EQUAL_QUOTE.getBytes());
mOut.write(XMLToken.escapeAttribute(rtx.getValue()).getBytes(Constants.DEFAULT_ENCODING));
mOut.write(CharsForSerializing.QUOTE.getBytes());
rtx.moveTo(key);
}
if (rtx.hasFirstChild()) {
mOut.write(CharsForSerializing.CLOSE.getBytes());
}
 else {
mOut.write(CharsForSerializing.SLASH_CLOSE.getBytes());
}
if (mIndent) {
mOut.write(CharsForSerializing.NEWLINE.getBytes());
}
break;
case COMMENT:
indent();
mOut.write(CharsForSerializing.OPENCOMMENT.getBytes());
mOut.write(XMLToken.escapeContent(rtx.getValue()).getBytes(Constants.DEFAULT_ENCODING));
if (mIndent) {
mOut.write(CharsForSerializing.NEWLINE.getBytes());
}
mOut.write(CharsForSerializing.CLOSECOMMENT.getBytes());
break;
case TEXT:
indent();
mOut.write(XMLToken.escapeContent(rtx.getValue()).getBytes(Constants.DEFAULT_ENCODING));
if (mIndent) {
mOut.write(CharsForSerializing.NEWLINE.getBytes());
}
break;
case PROCESSING_INSTRUCTION:
indent();
mOut.write(CharsForSerializing.OPENPI.getBytes());
writeQName(rtx);
mOut.write(CharsForSerializing.SPACE.getBytes());
mOut.write(XMLToken.escapeContent(rtx.getValue()).getBytes(Constants.DEFAULT_ENCODING));
if (mIndent) {
mOut.write(CharsForSerializing.NEWLINE.getBytes());
}
mOut.write(CharsForSerializing.CLOSEPI.getBytes());
break;
default :
throw new IllegalStateException("String_Node_Str");
}
}
 catch (final IOException e) {
LOGWRAPPER.error(e.getMessage(),e);
}
}