Program: 63824
Project: 63824
Buggy source:
private void parseRoot(Tree tree) throws SAXException {
  if (namespaces != null) {
    Map<String,String> namespacePairs=namespaces.getPrefixesToNamespaces();
    Iterator<String> keys=namespacePairs.keySet().iterator();
    while (keys.hasNext()) {
      String nextKey=keys.next();
      contentHandler.startPrefixMapping(nextKey,namespacePairs.get(nextKey));
    }
  }
  if (tree.getType() == JSONLexer.OBJECT) {
    contentHandler.startDocument();
    int children=tree.getChildCount();
    if (children == 0 && unmarshalClass == null) {
      return;
    }
    if (includeRoot) {
      parse((CommonTree)tree.getChild(0));
    }
 else {
      if (children == 1) {
        CommonTree ct=(CommonTree)tree.getChild(0);
        if (ct != null && ct.getType() == JSONLexer.NULL) {
          contentHandler.setNil(true);
        }
        contentHandler.startElement(Constants.EMPTY_STRING,Constants.EMPTY_STRING,null,attributes.setTree(tree,attributePrefix,namespaces,namespaceSeparator,namespaceAware));
        parse(ct);
        contentHandler.endElement(Constants.EMPTY_STRING,Constants.EMPTY_STRING,null);
      }
 else {
        contentHandler.startElement(Constants.EMPTY_STRING,Constants.EMPTY_STRING,null,attributes.setTree(tree,attributePrefix,namespaces,namespaceSeparator,namespaceAware));
        for (int x=0, size=children; x < size; x++) {
          parse((CommonTree)tree.getChild(x));
        }
        contentHandler.endElement(Constants.EMPTY_STRING,Constants.EMPTY_STRING,null);
      }
    }
    contentHandler.endDocument();
  }
 else   if (tree.getType() == JSONLexer.ARRAY) {
    SAXUnmarshallerHandler rootContentHandler=null;
    if (getContentHandler() instanceof SAXUnmarshallerHandler) {
      rootContentHandler=(SAXUnmarshallerHandler)getContentHandler();
    }
    int size=tree.getChildCount();
    List list=new ArrayList(size);
    for (int x=0; x < size; x++) {
      parseRoot(tree.getChild(x));
      if (getContentHandler() instanceof SAXUnmarshallerHandler) {
        SAXUnmarshallerHandler saxUnmarshallerHandler=(SAXUnmarshallerHandler)contentHandler;
        list.add(saxUnmarshallerHandler.getObject());
        saxUnmarshallerHandler.setObject(null);
      }
 else       if (getContentHandler() instanceof UnmarshalRecord) {
        UnmarshalRecord unmarshalRecord=(UnmarshalRecord)contentHandler;
        Object unmarshalledObject=unmarshalRecord.getCurrentObject();
        if (includeRoot && unmarshalClass != null) {
          if (!(unmarshalledObject instanceof Root)) {
            Root xmlRoot=unmarshalRecord.createRoot();
            xmlRoot.setNamespaceURI(unmarshalRecord.getRootElementNamespaceUri());
            xmlRoot.setLocalName(unmarshalRecord.getLocalName());
            xmlRoot.setObject(unmarshalledObject);
            unmarshalledObject=xmlRoot;
          }
        }
        list.add(unmarshalledObject);
        unmarshalRecord.setCurrentObject(null);
        unmarshalRecord.setRootElementName(null);
        unmarshalRecord.setLocalName(null);
      }
    }
    if (getContentHandler() instanceof SAXUnmarshallerHandler) {
      ((SAXUnmarshallerHandler)getContentHandler()).setObject(list);
    }
 else     if (getContentHandler() instanceof UnmarshalRecord) {
      ((UnmarshalRecord)getContentHandler()).setCurrentObject(list);
      ((UnmarshalRecord)getContentHandler()).setRootElementName(Constants.EMPTY_STRING);
      ((UnmarshalRecord)getContentHandler()).setLocalName(Constants.EMPTY_STRING);
      if (rootContentHandler != null) {
        rootContentHandler.setObject(list);
      }
    }
  }
}

Fixed version (ground truth):
private void parseRoot(Tree tree) throws SAXException {
  if (namespaces != null) {
    Map<String,String> namespacePairs=namespaces.getPrefixesToNamespaces();
    Iterator<String> keys=namespacePairs.keySet().iterator();
    while (keys.hasNext()) {
      String nextKey=keys.next();
      contentHandler.startPrefixMapping(nextKey,namespacePairs.get(nextKey));
    }
  }
  if (tree.getType() == JSONLexer.OBJECT) {
    contentHandler.startDocument();
    int children=tree.getChildCount();
    if (children == 0 && unmarshalClass == null) {
      return;
    }
    if (includeRoot) {
      parse((CommonTree)tree.getChild(0));
    }
 else {
      if (children == 1) {
        CommonTree ct=(CommonTree)tree.getChild(0);
        if (ct != null && ct.getType() == JSONLexer.NULL) {
          contentHandler.setNil(true);
        }
        contentHandler.startElement(Constants.EMPTY_STRING,Constants.EMPTY_STRING,null,attributes.setTree(tree,attributePrefix,namespaces,namespaceSeparator,namespaceAware));
        parse(ct);
        contentHandler.endElement(Constants.EMPTY_STRING,Constants.EMPTY_STRING,null);
      }
 else {
        contentHandler.startElement(Constants.EMPTY_STRING,Constants.EMPTY_STRING,null,attributes.setTree(tree,attributePrefix,namespaces,namespaceSeparator,namespaceAware));
        for (int x=0, size=children; x < size; x++) {
          parse((CommonTree)tree.getChild(x));
        }
        contentHandler.endElement(Constants.EMPTY_STRING,Constants.EMPTY_STRING,null);
      }
    }
    contentHandler.endDocument();
  }
 else   if (tree.getType() == JSONLexer.ARRAY) {
    SAXUnmarshallerHandler rootContentHandler=null;
    if (getContentHandler() instanceof SAXUnmarshallerHandler) {
      rootContentHandler=(SAXUnmarshallerHandler)getContentHandler();
    }
    int size=tree.getChildCount();
    List list=new ArrayList(size);
    for (int x=0; x < size; x++) {
      parseRoot(tree.getChild(x));
      if (getContentHandler() instanceof SAXUnmarshallerHandler) {
        SAXUnmarshallerHandler saxUnmarshallerHandler=(SAXUnmarshallerHandler)contentHandler;
        list.add(saxUnmarshallerHandler.getObject());
        saxUnmarshallerHandler.setObject(null);
      }
 else       if (getContentHandler() instanceof UnmarshalRecord) {
        UnmarshalRecord unmarshalRecord=(UnmarshalRecord)contentHandler;
        Object unmarshalledObject=unmarshalRecord.getCurrentObject();
        if (includeRoot && unmarshalClass != null) {
          if (!(unmarshalledObject instanceof Root)) {
            Root xmlRoot=unmarshalRecord.createRoot();
            xmlRoot.setNamespaceURI(unmarshalRecord.getRootElementNamespaceUri());
            xmlRoot.setLocalName(unmarshalRecord.getLocalName());
            xmlRoot.setObject(unmarshalledObject);
            unmarshalledObject=xmlRoot;
          }
        }
        list.add(unmarshalledObject);
        unmarshalRecord.setCurrentObject(null);
        unmarshalRecord.setRootElementName(null);
        unmarshalRecord.setLocalName(null);
      }
    }
    if (getContentHandler() instanceof SAXUnmarshallerHandler) {
      ((SAXUnmarshallerHandler)getContentHandler()).setObject(list);
    }
 else     if (getContentHandler() instanceof UnmarshalRecord) {
      ((UnmarshalRecord)getContentHandler()).setCurrentObject(list);
      ((UnmarshalRecord)getContentHandler()).setRootElementName(Constants.EMPTY_STRING);
      ((UnmarshalRecord)getContentHandler()).setLocalName(Constants.EMPTY_STRING);
      if (rootContentHandler != null) {
        rootContentHandler.setObject(list);
      }
    }
  }
 else {
    getContentHandler().startDocument();
    parse(tree);
  }
}