Program: 64791
Project: 64791
Buggy source:
private void parseEvent(XMLEvent xmlEvent) throws SAXException {
switch (xmlEvent.getEventType()) {
case XMLEvent.ATTRIBUTE:
{
      break;
    }
case XMLEvent.CDATA:
{
    Characters characters=xmlEvent.asCharacters();
    if (null == lexicalHandler) {
      contentHandler.characters(characters.getData().toCharArray(),0,characters.getData().length());
    }
 else {
      lexicalHandler.startCDATA();
      contentHandler.characters(characters.getData().toCharArray(),0,characters.getData().length());
      lexicalHandler.endCDATA();
    }
    break;
  }
case XMLEvent.CHARACTERS:
{
  char[] characters=xmlEvent.asCharacters().getData().toCharArray();
  contentHandler.characters(characters,0,characters.length);
  break;
}
case XMLEvent.COMMENT:
{
if (null != lexicalHandler) {
  char[] comment=((Comment)xmlEvent).getText().toCharArray();
  lexicalHandler.comment(comment,0,comment.length);
}
break;
}
case XMLEvent.DTD:
{
break;
}
case XMLEvent.END_DOCUMENT:
{
depth--;
return;
}
case XMLEvent.END_ELEMENT:
{
List<Namespace> declaredNs=this.namespaces.get(depth);
depth--;
EndElement endElement=xmlEvent.asEndElement();
QName name=endElement.getName();
String prefix=endElement.getName().getPrefix();
if (null == prefix || prefix.length() == 0) {
contentHandler.endElement(name.getNamespaceURI(),name.getLocalPart(),name.getLocalPart());
}
 else {
contentHandler.endElement(name.getNamespaceURI(),name.getLocalPart(),prefix + XMLConstants.COLON + name.getLocalPart());
}
if (declaredNs != null) {
for (Namespace next : declaredNs) {
contentHandler.endPrefixMapping(next.getPrefix());
}
}
break;
}
case XMLEvent.ENTITY_DECLARATION:
{
break;
}
case XMLEvent.ENTITY_REFERENCE:
{
break;
}
case XMLEvent.NAMESPACE:
{
break;
}
case XMLEvent.NOTATION_DECLARATION:
{
break;
}
case XMLEvent.PROCESSING_INSTRUCTION:
{
ProcessingInstruction pi=(ProcessingInstruction)xmlEvent;
contentHandler.processingInstruction(pi.getTarget(),pi.getData());
break;
}
case XMLEvent.SPACE:
{
char[] characters=xmlEvent.asCharacters().getData().toCharArray();
contentHandler.characters(characters,0,characters.length);
break;
}
case XMLEvent.START_DOCUMENT:
{
depth++;
break;
}
case XMLEvent.START_ELEMENT:
{
locator.setEvent(xmlEvent);
contentHandler.setDocumentLocator(locator);
depth++;
StartElement startElement=xmlEvent.asStartElement();
Iterator namespaces=startElement.getNamespaces();
List<Namespace> declaredNs=null;
if (namespaces.hasNext()) {
declaredNs=new ArrayList<Namespace>();
}
while (namespaces.hasNext()) {
Namespace next=(Namespace)namespaces.next();
contentHandler.startPrefixMapping(next.getPrefix(),next.getNamespaceURI());
declaredNs.add(next);
}
if (declaredNs != null) {
this.namespaces.put(depth,declaredNs);
}
QName qName=startElement.getName();
String prefix=qName.getPrefix();
indexedAttributeList.setIterators(startElement.getAttributes(),startElement.getNamespaces());
if (null == prefix || prefix.length() == 0) {
contentHandler.startElement(qName.getNamespaceURI(),qName.getLocalPart(),qName.getLocalPart(),indexedAttributeList);
}
 else {
contentHandler.startElement(qName.getNamespaceURI(),qName.getLocalPart(),prefix + XMLConstants.COLON + qName.getLocalPart(),indexedAttributeList);
}
break;
}
}
}

Fixed version (ground truth):
private void parseEvent(XMLEvent xmlEvent) throws SAXException {
switch (xmlEvent.getEventType()) {
case XMLEvent.ATTRIBUTE:
{
      break;
    }
case XMLEvent.CDATA:
{
    Characters characters=xmlEvent.asCharacters();
    if (null == lexicalHandler) {
      contentHandler.characters(characters.getData().toCharArray(),0,characters.getData().length());
    }
 else {
      lexicalHandler.startCDATA();
      contentHandler.characters(characters.getData().toCharArray(),0,characters.getData().length());
      lexicalHandler.endCDATA();
    }
    break;
  }
case XMLEvent.CHARACTERS:
{
  char[] characters=xmlEvent.asCharacters().getData().toCharArray();
  contentHandler.characters(characters,0,characters.length);
  break;
}
case XMLEvent.COMMENT:
{
if (null != lexicalHandler) {
  char[] comment=((Comment)xmlEvent).getText().toCharArray();
  lexicalHandler.comment(comment,0,comment.length);
}
break;
}
case XMLEvent.DTD:
{
break;
}
case XMLEvent.END_DOCUMENT:
{
depth--;
return;
}
case XMLEvent.END_ELEMENT:
{
List<Namespace> declaredNs=this.namespaces.get(depth);
depth--;
EndElement endElement=xmlEvent.asEndElement();
QName name=endElement.getName();
String prefix=endElement.getName().getPrefix();
if (null == prefix || prefix.length() == 0) {
contentHandler.endElement(name.getNamespaceURI(),name.getLocalPart(),name.getLocalPart());
}
 else {
contentHandler.endElement(name.getNamespaceURI(),name.getLocalPart(),prefix + XMLConstants.COLON + name.getLocalPart());
}
if (declaredNs != null) {
for (Namespace next : declaredNs) {
contentHandler.endPrefixMapping(next.getPrefix());
}
}
break;
}
case XMLEvent.ENTITY_DECLARATION:
{
break;
}
case XMLEvent.ENTITY_REFERENCE:
{
break;
}
case XMLEvent.NAMESPACE:
{
break;
}
case XMLEvent.NOTATION_DECLARATION:
{
break;
}
case XMLEvent.PROCESSING_INSTRUCTION:
{
ProcessingInstruction pi=(ProcessingInstruction)xmlEvent;
contentHandler.processingInstruction(pi.getTarget(),pi.getData());
break;
}
case XMLEvent.SPACE:
{
char[] characters=xmlEvent.asCharacters().getData().toCharArray();
contentHandler.characters(characters,0,characters.length);
break;
}
case XMLEvent.START_DOCUMENT:
{
depth++;
break;
}
case XMLEvent.START_ELEMENT:
{
lastEvent=xmlEvent;
depth++;
StartElement startElement=xmlEvent.asStartElement();
Iterator namespaces=startElement.getNamespaces();
List<Namespace> declaredNs=null;
if (namespaces.hasNext()) {
declaredNs=new ArrayList<Namespace>();
}
while (namespaces.hasNext()) {
Namespace next=(Namespace)namespaces.next();
contentHandler.startPrefixMapping(next.getPrefix(),next.getNamespaceURI());
declaredNs.add(next);
}
if (declaredNs != null) {
this.namespaces.put(depth,declaredNs);
}
QName qName=startElement.getName();
String prefix=qName.getPrefix();
indexedAttributeList.setIterators(startElement.getAttributes(),startElement.getNamespaces());
if (null == prefix || prefix.length() == 0) {
contentHandler.startElement(qName.getNamespaceURI(),qName.getLocalPart(),qName.getLocalPart(),indexedAttributeList);
}
 else {
contentHandler.startElement(qName.getNamespaceURI(),qName.getLocalPart(),prefix + XMLConstants.COLON + qName.getLocalPart(),indexedAttributeList);
}
break;
}
}
}