Program: 64167
Project: 64167
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();
  objectValue=xmlCompositeCollectionMapping.convertDataValueToObjectValue(objectValue,unmarshalRecord.getSession(),unmarshalRecord.getUnmarshaller());
  unmarshalRecord.addAttributeValue(this,objectValue,collection);
  InverseReferenceMapping inverseReferenceMapping=xmlCompositeCollectionMapping.getInverseReferenceMapping();
  if (null != inverseReferenceMapping) {
    if (inverseReferenceMapping.getContainerPolicy() == null) {
      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());
    }
  }
  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)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();
  objectValue=xmlCompositeCollectionMapping.convertDataValueToObjectValue(objectValue,unmarshalRecord.getSession(),unmarshalRecord.getUnmarshaller());
  unmarshalRecord.addAttributeValue(this,objectValue,collection);
  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());
    }
  }
  unmarshalRecord.setChildRecord(null);
}