Program: 64117
Project: 64117
Buggy source:
private void parse(Tree tree) throws SAXException {
  if (tree == null) {
    return;
  }
switch (tree.getType()) {
case JSONLexer.PAIR:
{
      Tree valueTree=tree.getChild(1);
      if (valueTree.getType() == JSONLexer.ARRAY) {
        parse(valueTree);
      }
 else {
        Tree stringTree=tree.getChild(0);
        String qualifiedName=stringTree.getText().substring(1,stringTree.getText().length() - 1);
        String localName=qualifiedName;
        if (attributePrefix != null && qualifiedName.startsWith(attributePrefix)) {
          break;
        }
        String uri=Constants.EMPTY_STRING;
        if (namespaceAware && namespaces != null) {
          if (localName.length() > 2) {
            int nsIndex=localName.indexOf(namespaceSeparator,1);
            String prefix=Constants.EMPTY_STRING;
            if (nsIndex > -1) {
              prefix=localName.substring(0,nsIndex);
            }
            uri=namespaces.resolveNamespacePrefix(prefix);
            if (uri == null) {
              uri=namespaces.getDefaultNamespaceURI();
            }
 else {
              localName=localName.substring(nsIndex + 1);
            }
            if (localName.equals(Constants.SCHEMA_TYPE_ATTRIBUTE) && uri.equals(javax.xml.XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI)) {
              break;
            }
          }
 else {
            uri=namespaces.getDefaultNamespaceURI();
          }
        }
        if (contentHandler instanceof XMLRootRecord || contentHandler instanceof DeferredContentHandler) {
          if (!namespaceAware && localName.equals(Constants.SCHEMA_TYPE_ATTRIBUTE)) {
            break;
          }
          if (textWrapper != null && textWrapper.equals(localName)) {
            parse(valueTree);
            break;
          }
        }
 else         if (contentHandler instanceof UnmarshalRecord && ((UnmarshalRecord)contentHandler).getXPathNode() != null) {
          if (!namespaceAware && localName.equals(Constants.SCHEMA_TYPE_ATTRIBUTE) && !((UnmarshalRecord)contentHandler).getXPathNode().hasTypeChild()) {
            break;
          }
          boolean isTextValue=isTextValue(localName);
          if (isTextValue) {
            parse(valueTree);
            break;
          }
        }
        if (valueTree != null && valueTree.getType() == JSONLexer.NULL) {
          contentHandler.setNil(true);
        }
        contentHandler.startElement(uri,localName,localName,attributes.setTree(valueTree,attributePrefix,namespaces,namespaceSeparator,namespaceAware));
        parse(valueTree);
        contentHandler.endElement(uri,localName,localName);
      }
      break;
    }
case JSONLexer.STRING:
{
    String string=string(tree.getChild(0).getText());
    contentHandler.characters(string);
    break;
  }
case JSONLexer.NUMBER:
{
  contentHandler.characters(tree.getChild(0).getText());
  break;
}
case JSONLexer.TRUE:
{
contentHandler.characters(TRUE);
break;
}
case JSONLexer.FALSE:
{
contentHandler.characters(FALSE);
break;
}
case JSONLexer.NULL:
{
break;
}
case JSONLexer.ARRAY:
{
Tree parentStringTree=tree.getParent().getChild(0);
String parentLocalName=parentStringTree.getText().substring(1,parentStringTree.getText().length() - 1);
if (attributePrefix != null && parentLocalName.startsWith(attributePrefix)) {
break;
}
String uri=Constants.EMPTY_STRING;
if (namespaceAware && namespaces != null) {
if (parentLocalName.length() > 2) {
int nsIndex=parentLocalName.indexOf(namespaceSeparator,1);
if (nsIndex > -1) {
String prefix=parentLocalName.substring(0,nsIndex);
uri=namespaces.resolveNamespacePrefix(prefix);
}
if (uri == null) {
uri=namespaces.getDefaultNamespaceURI();
}
 else {
parentLocalName=parentLocalName.substring(nsIndex + 1);
}
}
 else {
uri=namespaces.getDefaultNamespaceURI();
}
}
boolean isTextValue=isTextValue(parentLocalName);
int size=tree.getChildCount();
if (size == 0) {
if (contentHandler instanceof UnmarshalRecord) {
UnmarshalRecord ur=(UnmarshalRecord)contentHandler;
XPathNode node=ur.getNonAttributeXPathNode(uri,parentLocalName,parentLocalName,null);
if (node != null) {
NodeValue nv=node.getNodeValue();
if (nv == null && node.getTextNode() != null) {
  nv=node.getTextNode().getUnmarshalNodeValue();
}
if (nv != null && nv.isContainerValue()) {
  ur.getContainerInstance(((ContainerValue)nv));
}
}
}
}
startCollection();
if (size == 1) {
CommonTree ct=(CommonTree)tree.getChild(0);
if (ct != null && ct.getType() == JSONLexer.NULL) {
contentHandler.setNil(true);
}
if (!isTextValue) {
contentHandler.startElement(uri,parentLocalName,parentLocalName,attributes.setTree(ct,attributePrefix,namespaces,namespaceSeparator,namespaceAware));
}
parse(ct);
if (!isTextValue) {
contentHandler.endElement(uri,parentLocalName,parentLocalName);
}
}
 else {
for (int x=0; x < size; x++) {
CommonTree nextChildTree=(CommonTree)tree.getChild(x);
if (nextChildTree.getType() == JSONLexer.NULL) {
((UnmarshalRecord)contentHandler).setNil(true);
}
if (!isTextValue) {
contentHandler.startElement(uri,parentLocalName,parentLocalName,attributes.setTree(nextChildTree,attributePrefix,namespaces,namespaceSeparator,namespaceAware));
}
parse(nextChildTree);
if (!isTextValue) {
contentHandler.endElement(uri,parentLocalName,parentLocalName);
}
}
}
endCollection();
break;
}
default :
{
for (int x=0, size=tree.getChildCount(); x < size; x++) {
parse((CommonTree)tree.getChild(x));
}
}
}
}

Fixed version (ground truth):
private void parse(Tree tree) throws SAXException {
  if (tree == null) {
    return;
  }
switch (tree.getType()) {
case JSONLexer.PAIR:
{
      Tree valueTree=tree.getChild(1);
      if (valueTree.getType() == JSONLexer.ARRAY) {
        parse(valueTree);
      }
 else {
        Tree stringTree=tree.getChild(0);
        String qualifiedName=stringTree.getText().substring(1,stringTree.getText().length() - 1);
        String localName=qualifiedName;
        if (attributePrefix != null && qualifiedName.startsWith(attributePrefix)) {
          break;
        }
        String uri=Constants.EMPTY_STRING;
        if (namespaceAware && namespaces != null) {
          if (localName.length() > 2) {
            int nsIndex=localName.indexOf(namespaceSeparator,1);
            String prefix=Constants.EMPTY_STRING;
            if (nsIndex > -1) {
              prefix=localName.substring(0,nsIndex);
            }
            uri=namespaces.resolveNamespacePrefix(prefix);
            if (uri == null) {
              uri=namespaces.getDefaultNamespaceURI();
            }
 else {
              localName=localName.substring(nsIndex + 1);
            }
            if (localName.equals(Constants.SCHEMA_TYPE_ATTRIBUTE) && uri.equals(javax.xml.XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI)) {
              break;
            }
          }
 else {
            uri=namespaces.getDefaultNamespaceURI();
          }
        }
        if (contentHandler instanceof XMLRootRecord || contentHandler instanceof DeferredContentHandler) {
          if (!namespaceAware && localName.equals(Constants.SCHEMA_TYPE_ATTRIBUTE)) {
            break;
          }
          if (textWrapper != null && textWrapper.equals(localName)) {
            parse(valueTree);
            break;
          }
        }
 else         if (contentHandler instanceof UnmarshalRecord && ((UnmarshalRecord)contentHandler).getXPathNode() != null) {
          if (!namespaceAware && localName.equals(Constants.SCHEMA_TYPE_ATTRIBUTE) && !((UnmarshalRecord)contentHandler).getXPathNode().hasTypeChild()) {
            break;
          }
          boolean isTextValue=isTextValue(localName);
          if (isTextValue) {
            parse(valueTree);
            break;
          }
        }
        if (valueTree != null && valueTree.getType() == JSONLexer.NULL) {
          contentHandler.setNil(true);
        }
        contentHandler.startElement(uri,localName,localName,attributes.setTree(valueTree,attributePrefix,namespaces,namespaceSeparator,namespaceAware));
        parse(valueTree);
        contentHandler.endElement(uri,localName,localName);
      }
      break;
    }
case JSONLexer.STRING:
{
    String string=string(tree.getChild(0).getText());
    contentHandler.characters(string);
    break;
  }
case JSONLexer.NUMBER:
{
  contentHandler.characters(tree.getChild(0).getText());
  break;
}
case JSONLexer.TRUE:
{
contentHandler.characters(TRUE);
break;
}
case JSONLexer.FALSE:
{
contentHandler.characters(FALSE);
break;
}
case JSONLexer.NULL:
{
break;
}
case JSONLexer.ARRAY:
{
Tree parentStringTree=tree.getParent().getChild(0);
String parentLocalName=parentStringTree.getText().substring(1,parentStringTree.getText().length() - 1);
if (attributePrefix != null && parentLocalName.startsWith(attributePrefix)) {
break;
}
String uri=Constants.EMPTY_STRING;
if (namespaceAware && namespaces != null) {
if (parentLocalName.length() > 2) {
int nsIndex=parentLocalName.indexOf(namespaceSeparator,1);
if (nsIndex > -1) {
String prefix=parentLocalName.substring(0,nsIndex);
uri=namespaces.resolveNamespacePrefix(prefix);
}
if (uri == null) {
uri=namespaces.getDefaultNamespaceURI();
}
 else {
parentLocalName=parentLocalName.substring(nsIndex + 1);
}
}
 else {
uri=namespaces.getDefaultNamespaceURI();
}
}
boolean isTextValue=isTextValue(parentLocalName);
int size=tree.getChildCount();
if (size == 0) {
if (contentHandler instanceof UnmarshalRecord) {
UnmarshalRecord ur=(UnmarshalRecord)contentHandler;
XPathNode node=ur.getNonAttributeXPathNode(uri,parentLocalName,parentLocalName,null);
if (node != null) {
NodeValue nv=node.getNodeValue();
if (nv == null && node.getTextNode() != null) {
  nv=node.getTextNode().getUnmarshalNodeValue();
}
if (nv != null && nv.isContainerValue()) {
  ur.getContainerInstance(((ContainerValue)nv));
}
}
}
}
startCollection();
if (size == 1) {
CommonTree ct=(CommonTree)tree.getChild(0);
if (ct != null && ct.getType() == JSONLexer.NULL) {
contentHandler.setNil(true);
}
if (!isTextValue) {
contentHandler.startElement(uri,parentLocalName,parentLocalName,attributes.setTree(ct,attributePrefix,namespaces,namespaceSeparator,namespaceAware));
}
parse(ct);
if (!isTextValue) {
contentHandler.endElement(uri,parentLocalName,parentLocalName);
}
}
 else {
XPathFragment groupingXPathFragment=null;
XPathFragment itemXPathFragment=null;
if (contentHandler instanceof UnmarshalRecord) {
UnmarshalRecord unmarshalRecord=(UnmarshalRecord)contentHandler;
if (unmarshalRecord.getUnmarshaller().isWrapperAsCollectionName()) {
XPathNode unmarshalRecordXPathNode=unmarshalRecord.getXPathNode();
if (null != unmarshalRecordXPathNode) {
  XPathFragment currentFragment=new XPathFragment();
  currentFragment.setLocalName(parentLocalName);
  currentFragment.setNamespaceURI(uri);
  currentFragment.setNamespaceAware(namespaceAware);
  XPathNode groupingXPathNode=unmarshalRecordXPathNode.getNonAttributeChildrenMap().get(currentFragment);
  if (groupingXPathNode != null) {
    if (groupingXPathNode.getUnmarshalNodeValue() instanceof CollectionGroupingElementNodeValue) {
      groupingXPathFragment=groupingXPathNode.getXPathFragment();
      contentHandler.startElement(uri,parentLocalName,parentLocalName,new AttributesImpl());
      XPathNode itemXPathNode=groupingXPathNode.getNonAttributeChildren().get(0);
      itemXPathFragment=itemXPathNode.getXPathFragment();
    }
 else     if (groupingXPathNode.getUnmarshalNodeValue() == null) {
      XPathNode itemXPathNode=groupingXPathNode.getNonAttributeChildren().get(0);
      if (itemXPathNode != null) {
        if (((MappingNodeValue)itemXPathNode.getUnmarshalNodeValue()).isContainerValue()) {
          groupingXPathFragment=groupingXPathNode.getXPathFragment();
          contentHandler.startElement(uri,parentLocalName,parentLocalName,new AttributesImpl());
          itemXPathFragment=itemXPathNode.getXPathFragment();
        }
      }
    }
  }
}
}
}
for (int x=0; x < size; x++) {
CommonTree nextChildTree=(CommonTree)tree.getChild(x);
if (nextChildTree.getType() == JSONLexer.NULL) {
((UnmarshalRecord)contentHandler).setNil(true);
}
if (!isTextValue) {
if (null != itemXPathFragment) {
  contentHandler.startElement(itemXPathFragment.getNamespaceURI(),itemXPathFragment.getLocalName(),itemXPathFragment.getLocalName(),attributes.setTree(nextChildTree,attributePrefix,namespaces,namespaceSeparator,namespaceAware));
}
 else {
  contentHandler.startElement(uri,parentLocalName,parentLocalName,attributes.setTree(nextChildTree,attributePrefix,namespaces,namespaceSeparator,namespaceAware));
}
}
parse(nextChildTree);
if (!isTextValue) {
if (null != itemXPathFragment) {
  contentHandler.endElement(uri,itemXPathFragment.getLocalName(),itemXPathFragment.getLocalName());
}
 else {
  contentHandler.endElement(uri,parentLocalName,parentLocalName);
}
}
}
if (null != groupingXPathFragment) {
contentHandler.endElement(uri,groupingXPathFragment.getLocalName(),groupingXPathFragment.getLocalName());
}
}
endCollection();
break;
}
default :
{
for (int x=0, size=tree.getChildCount(); x < size; x++) {
parse((CommonTree)tree.getChild(x));
}
}
}
}