Program: 65754
Project: 65754
Buggy source:
public void endElement(XPathFragment xPathFragment,UnmarshalRecord unmarshalRecord){
  Object collection=unmarshalRecord.getContainerInstance(this);
  UnmarshalRecord childRecord=unmarshalRecord.getChildRecord();
  if (null != childRecord) {
    if (!xmlAnyCollectionMapping.usesXMLRoot()) {
      Object objectValue=childRecord.getCurrentObject();
      if (xmlAnyCollectionMapping.getConverter() != null) {
        objectValue=xmlAnyCollectionMapping.getConverter().convertDataValueToObjectValue(objectValue,unmarshalRecord.getSession(),unmarshalRecord.getUnmarshaller());
      }
      unmarshalRecord.addAttributeValue(this,objectValue);
    }
 else {
      Object childObject=childRecord.getCurrentObject();
      XMLDescriptor workingDescriptor=childRecord.getDescriptor();
      if (workingDescriptor != null) {
        String prefix=xPathFragment.getPrefix();
        if ((prefix == null) && (xPathFragment.getNamespaceURI() != null)) {
          prefix=unmarshalRecord.resolveNamespaceUri(xPathFragment.getNamespaceURI());
        }
        childObject=workingDescriptor.wrapObjectInXMLRoot(childObject,xPathFragment.getNamespaceURI(),xPathFragment.getLocalName(),prefix,false);
        if (xmlAnyCollectionMapping.getConverter() != null) {
          childObject=xmlAnyCollectionMapping.getConverter().convertDataValueToObjectValue(childObject,unmarshalRecord.getSession(),unmarshalRecord.getUnmarshaller());
        }
        unmarshalRecord.addAttributeValue(this,childObject);
      }
    }
    unmarshalRecord.setChildRecord(null);
  }
 else {
    SAXFragmentBuilder builder=unmarshalRecord.getFragmentBuilder();
    UnmarshalKeepAsElementPolicy keepAsElementPolicy=xmlAnyCollectionMapping.getKeepAsElementPolicy();
    if ((((keepAsElementPolicy == UnmarshalKeepAsElementPolicy.KEEP_UNKNOWN_AS_ELEMENT) || (keepAsElementPolicy == UnmarshalKeepAsElementPolicy.KEEP_ALL_AS_ELEMENT))) && (builder.getNodes().size() > 1)) {
      setOrAddAttributeValueForKeepAsElement(builder,xmlAnyCollectionMapping,xmlAnyCollectionMapping.getConverter(),unmarshalRecord,true,null);
    }
 else {
      if (xmlAnyCollectionMapping.isMixedContent()) {
        endElementProcessText(unmarshalRecord,xmlAnyCollectionMapping.getConverter(),xPathFragment,null);
      }
 else {
        unmarshalRecord.resetStringBuffer();
      }
    }
  }
}

Fixed version (ground truth):
public void endElement(XPathFragment xPathFragment,UnmarshalRecord unmarshalRecord){
  Object collection=unmarshalRecord.getContainerInstance(this);
  UnmarshalRecord childRecord=unmarshalRecord.getChildRecord();
  if (null != childRecord) {
    if (!xmlAnyCollectionMapping.usesXMLRoot()) {
      Object objectValue=childRecord.getCurrentObject();
      if (xmlAnyCollectionMapping.getConverter() != null) {
        objectValue=xmlAnyCollectionMapping.getConverter().convertDataValueToObjectValue(objectValue,unmarshalRecord.getSession(),unmarshalRecord.getUnmarshaller());
      }
      unmarshalRecord.addAttributeValue(this,objectValue);
    }
 else {
      Object childObject=childRecord.getCurrentObject();
      XMLDescriptor workingDescriptor=childRecord.getDescriptor();
      if (workingDescriptor != null) {
        String prefix=xPathFragment.getPrefix();
        if ((prefix == null) && (xPathFragment.getNamespaceURI() != null)) {
          prefix=unmarshalRecord.resolveNamespaceUri(xPathFragment.getNamespaceURI());
        }
        childObject=workingDescriptor.wrapObjectInXMLRoot(childObject,xPathFragment.getNamespaceURI(),xPathFragment.getLocalName(),prefix,false,unmarshalRecord.getUnmarshaller().isNamespaceAware());
        if (xmlAnyCollectionMapping.getConverter() != null) {
          childObject=xmlAnyCollectionMapping.getConverter().convertDataValueToObjectValue(childObject,unmarshalRecord.getSession(),unmarshalRecord.getUnmarshaller());
        }
        unmarshalRecord.addAttributeValue(this,childObject);
      }
    }
    unmarshalRecord.setChildRecord(null);
  }
 else {
    SAXFragmentBuilder builder=unmarshalRecord.getFragmentBuilder();
    UnmarshalKeepAsElementPolicy keepAsElementPolicy=xmlAnyCollectionMapping.getKeepAsElementPolicy();
    if ((((keepAsElementPolicy == UnmarshalKeepAsElementPolicy.KEEP_UNKNOWN_AS_ELEMENT) || (keepAsElementPolicy == UnmarshalKeepAsElementPolicy.KEEP_ALL_AS_ELEMENT))) && (builder.getNodes().size() > 1)) {
      setOrAddAttributeValueForKeepAsElement(builder,xmlAnyCollectionMapping,xmlAnyCollectionMapping.getConverter(),unmarshalRecord,true,null);
    }
 else {
      if (xmlAnyCollectionMapping.isMixedContent()) {
        endElementProcessText(unmarshalRecord,xmlAnyCollectionMapping.getConverter(),xPathFragment,null);
      }
 else {
        unmarshalRecord.resetStringBuffer();
      }
    }
  }
}