Program: 63978
Project: 63978
Buggy source:
public void endElement(XPathFragment xPathFragment,UnmarshalRecord unmarshalRecord,Object collection){
  if (unmarshalRecord.isNil() && unmarshalRecord.getXMLReader().isNullRepresentedByXsiNil(xmlCompositeCollectionMapping.getNullPolicy())) {
    if (unmarshalRecord.getXMLReader().isInCollection()) {
      unmarshalRecord.addAttributeValue(this,null);
    }
 else {
      unmarshalRecord.setAttributeValueNull(this);
    }
    unmarshalRecord.resetStringBuffer();
    return;
  }
  if (null == unmarshalRecord.getChildRecord()) {
    SAXFragmentBuilder builder=unmarshalRecord.getFragmentBuilder();
    UnmarshalKeepAsElementPolicy keepAsElementPolicy=xmlCompositeCollectionMapping.getKeepAsElementPolicy();
    if (null != keepAsElementPolicy && (keepAsElementPolicy.isKeepUnknownAsElement() || keepAsElementPolicy.isKeepAllAsElement()) && builder.getNodes().size() > 1) {
      if (unmarshalRecord.getTypeQName() != null) {
        Class theClass=(Class)((XMLConversionManager)unmarshalRecord.getSession().getDatasourcePlatform().getConversionManager()).getDefaultXMLTypes().get(unmarshalRecord.getTypeQName());
        if (theClass != null) {
          endElementProcessText(unmarshalRecord,xmlCompositeCollectionMapping,xPathFragment,collection);
          return;
        }
      }
      if (builder.getNodes().size() > 1) {
        setOrAddAttributeValueForKeepAsElement(builder,xmlCompositeCollectionMapping,xmlCompositeCollectionMapping,unmarshalRecord,true,collection);
        return;
      }
    }
 else {
      endElementProcessText(unmarshalRecord,xmlCompositeCollectionMapping,xPathFragment,collection);
      return;
    }
    return;
  }
  Object objectValue=unmarshalRecord.getChildRecord().getCurrentObject();
  InverseReferenceMapping inverseReferenceMapping=xmlCompositeCollectionMapping.getInverseReferenceMapping();
  if (null != inverseReferenceMapping) {
    if (inverseReferenceMapping.getContainerPolicy() == null) {
      Object currentValue=inverseReferenceMapping.getAttributeAccessor().getAttributeValueFromObject(objectValue);
      if (!isInverseReference || (currentValue == null && isInverseReference)) {
        inverseReferenceMapping.getAttributeAccessor().setAttributeValueInObject(objectValue,unmarshalRecord.getCurrentObject());
      }
    }
 else {
      Object backpointerContainer=inverseReferenceMapping.getAttributeAccessor().getAttributeValueFromObject(objectValue);
      if (backpointerContainer == null) {
        backpointerContainer=inverseReferenceMapping.getContainerPolicy().containerInstance();
        inverseReferenceMapping.getAttributeAccessor().setAttributeValueInObject(objectValue,backpointerContainer);
      }
      inverseReferenceMapping.getContainerPolicy().addInto(unmarshalRecord.getCurrentObject(),backpointerContainer,unmarshalRecord.getSession());
    }
  }
  objectValue=xmlCompositeCollectionMapping.convertDataValueToObjectValue(objectValue,unmarshalRecord.getSession(),unmarshalRecord.getUnmarshaller());
  unmarshalRecord.addAttributeValue(this,objectValue,collection);
  unmarshalRecord.setChildRecord(null);
}

Fixed version (ground truth):
public void endElement(XPathFragment xPathFragment,UnmarshalRecord unmarshalRecord,Object collection){
  if (unmarshalRecord.isNil() && unmarshalRecord.getXMLReader().isNullRepresentedByXsiNil(xmlCompositeCollectionMapping.getNullPolicy())) {
    if (unmarshalRecord.getXMLReader().isInCollection()) {
      unmarshalRecord.addAttributeValue(this,null);
    }
 else {
      unmarshalRecord.setAttributeValueNull(this);
    }
    unmarshalRecord.resetStringBuffer();
    return;
  }
  if (null == unmarshalRecord.getChildRecord()) {
    SAXFragmentBuilder builder=unmarshalRecord.getFragmentBuilder();
    UnmarshalKeepAsElementPolicy keepAsElementPolicy=xmlCompositeCollectionMapping.getKeepAsElementPolicy();
    if (null != keepAsElementPolicy && (keepAsElementPolicy.isKeepUnknownAsElement() || keepAsElementPolicy.isKeepAllAsElement()) && builder.getNodes().size() > 1) {
      if (unmarshalRecord.getTypeQName() != null) {
        Class theClass=(Class)XMLConversionManager.getDefaultXMLTypes().get(unmarshalRecord.getTypeQName());
        if (theClass != null) {
          endElementProcessText(unmarshalRecord,xmlCompositeCollectionMapping,xPathFragment,collection);
          return;
        }
      }
      if (builder.getNodes().size() > 1) {
        setOrAddAttributeValueForKeepAsElement(builder,xmlCompositeCollectionMapping,xmlCompositeCollectionMapping,unmarshalRecord,true,collection);
        return;
      }
    }
 else {
      endElementProcessText(unmarshalRecord,xmlCompositeCollectionMapping,xPathFragment,collection);
      return;
    }
    return;
  }
  Object objectValue=unmarshalRecord.getChildRecord().getCurrentObject();
  InverseReferenceMapping inverseReferenceMapping=xmlCompositeCollectionMapping.getInverseReferenceMapping();
  if (null != inverseReferenceMapping) {
    if (inverseReferenceMapping.getContainerPolicy() == null) {
      Object currentValue=inverseReferenceMapping.getAttributeAccessor().getAttributeValueFromObject(objectValue);
      if (!isInverseReference || (currentValue == null && isInverseReference)) {
        inverseReferenceMapping.getAttributeAccessor().setAttributeValueInObject(objectValue,unmarshalRecord.getCurrentObject());
      }
    }
 else {
      Object backpointerContainer=inverseReferenceMapping.getAttributeAccessor().getAttributeValueFromObject(objectValue);
      if (backpointerContainer == null) {
        backpointerContainer=inverseReferenceMapping.getContainerPolicy().containerInstance();
        inverseReferenceMapping.getAttributeAccessor().setAttributeValueInObject(objectValue,backpointerContainer);
      }
      inverseReferenceMapping.getContainerPolicy().addInto(unmarshalRecord.getCurrentObject(),backpointerContainer,unmarshalRecord.getSession());
    }
  }
  objectValue=xmlCompositeCollectionMapping.convertDataValueToObjectValue(objectValue,unmarshalRecord.getSession(),unmarshalRecord.getUnmarshaller());
  unmarshalRecord.addAttributeValue(this,objectValue,collection);
  unmarshalRecord.setChildRecord(null);
}