Program: 66355
Project: 66355
Buggy source:
/** 
 * INTERNAL:
 * @param session typically will be a unit of work
 */
public void resolveReferences(AbstractSession session){
  for (int x=0, referencesSize=references.size(); x < referencesSize; x++) {
    Reference reference=(Reference)references.get(x);
    Object referenceSourceObject=reference.getSourceObject();
    if (reference.getMapping() instanceof XMLCollectionReferenceMapping) {
      XMLCollectionReferenceMapping mapping=(XMLCollectionReferenceMapping)reference.getMapping();
      ContainerPolicy cPolicy=mapping.getContainerPolicy();
      Object container=null;
      if (mapping.getReuseContainer()) {
        container=mapping.getAttributeAccessor().getAttributeValueFromObject(referenceSourceObject);
      }
 else {
        container=cPolicy.containerInstance();
      }
      createPKVectorsFromMap(reference,mapping);
      for (Iterator pkIt=((Vector)reference.getPrimaryKey()).iterator(); pkIt.hasNext(); ) {
        CacheId primaryKey=(CacheId)pkIt.next();
        Object value=getValue(session,reference,primaryKey);
        if (value != null) {
          cPolicy.addInto(value,container,session);
        }
      }
      mapping.setAttributeValueInObject(referenceSourceObject,container);
      XMLInverseReferenceMapping inverseReferenceMapping=mapping.getInverseReferenceMapping();
      if (inverseReferenceMapping != null) {
        AttributeAccessor backpointerAccessor=inverseReferenceMapping.getAttributeAccessor();
        ContainerPolicy backpointerContainerPolicy=inverseReferenceMapping.getContainerPolicy();
        Object iterator=cPolicy.iteratorFor(container);
        while (cPolicy.hasNext(iterator)) {
          Object next=cPolicy.next(iterator,session);
          if (backpointerContainerPolicy == null) {
            backpointerAccessor.setAttributeValueInObject(next,referenceSourceObject);
          }
 else {
            Object backpointerContainer=backpointerAccessor.getAttributeValueFromObject(next);
            if (backpointerContainer == null) {
              backpointerContainer=backpointerContainerPolicy.containerInstance();
              backpointerAccessor.setAttributeValueInObject(next,backpointerContainer);
            }
            backpointerContainerPolicy.addInto(referenceSourceObject,backpointerContainer,session);
          }
        }
      }
    }
 else     if (reference.getMapping() instanceof XMLObjectReferenceMapping) {
      CacheId primaryKey=(CacheId)reference.getPrimaryKey();
      Object value=getValue(session,reference,primaryKey);
      XMLObjectReferenceMapping mapping=(XMLObjectReferenceMapping)reference.getMapping();
      if (value != null) {
        mapping.setAttributeValueInObject(reference.getSourceObject(),value);
      }
      if (null != reference.getSetting()) {
        reference.getSetting().setValue(value);
      }
      XMLInverseReferenceMapping inverseReferenceMapping=mapping.getInverseReferenceMapping();
      if (inverseReferenceMapping != null) {
        AttributeAccessor backpointerAccessor=inverseReferenceMapping.getAttributeAccessor();
        ContainerPolicy backpointerContainerPolicy=inverseReferenceMapping.getContainerPolicy();
        if (backpointerContainerPolicy == null) {
          backpointerAccessor.setAttributeValueInObject(value,referenceSourceObject);
        }
 else {
          Object backpointerContainer=backpointerAccessor.getAttributeValueFromObject(value);
          if (backpointerContainer == null) {
            backpointerContainer=backpointerContainerPolicy.containerInstance();
            backpointerAccessor.setAttributeValueInObject(value,backpointerContainer);
          }
          backpointerContainerPolicy.addInto(reference.getSourceObject(),backpointerContainer,session);
        }
      }
    }
  }
  if (session.isUnitOfWork()) {
    ((UnitOfWork)session).release();
  }
  references=new ArrayList();
}

Fixed version (ground truth):
/** 
 * INTERNAL:
 * @param session typically will be a unit of work
 */
public void resolveReferences(AbstractSession session){
  for (int x=0, referencesSize=references.size(); x < referencesSize; x++) {
    Reference reference=(Reference)references.get(x);
    Object referenceSourceObject=reference.getSourceObject();
    if (reference.getMapping() instanceof XMLCollectionReferenceMapping) {
      XMLCollectionReferenceMapping mapping=(XMLCollectionReferenceMapping)reference.getMapping();
      ContainerPolicy cPolicy=mapping.getContainerPolicy();
      Object container=null;
      if (mapping.getReuseContainer()) {
        container=mapping.getAttributeAccessor().getAttributeValueFromObject(referenceSourceObject);
      }
 else {
        container=cPolicy.containerInstance();
      }
      createPKVectorsFromMap(reference,mapping);
      if (!mapping.isWriteOnly()) {
        for (Iterator pkIt=((Vector)reference.getPrimaryKey()).iterator(); pkIt.hasNext(); ) {
          CacheId primaryKey=(CacheId)pkIt.next();
          Object value=getValue(session,reference,primaryKey);
          if (value != null) {
            cPolicy.addInto(value,container,session);
          }
        }
      }
      mapping.setAttributeValueInObject(referenceSourceObject,container);
      XMLInverseReferenceMapping inverseReferenceMapping=mapping.getInverseReferenceMapping();
      if (inverseReferenceMapping != null) {
        AttributeAccessor backpointerAccessor=inverseReferenceMapping.getAttributeAccessor();
        ContainerPolicy backpointerContainerPolicy=inverseReferenceMapping.getContainerPolicy();
        Object iterator=cPolicy.iteratorFor(container);
        while (cPolicy.hasNext(iterator)) {
          Object next=cPolicy.next(iterator,session);
          if (backpointerContainerPolicy == null) {
            backpointerAccessor.setAttributeValueInObject(next,referenceSourceObject);
          }
 else {
            Object backpointerContainer=backpointerAccessor.getAttributeValueFromObject(next);
            if (backpointerContainer == null) {
              backpointerContainer=backpointerContainerPolicy.containerInstance();
              backpointerAccessor.setAttributeValueInObject(next,backpointerContainer);
            }
            backpointerContainerPolicy.addInto(referenceSourceObject,backpointerContainer,session);
          }
        }
      }
    }
 else     if (reference.getMapping() instanceof XMLObjectReferenceMapping) {
      CacheId primaryKey=(CacheId)reference.getPrimaryKey();
      Object value=getValue(session,reference,primaryKey);
      XMLObjectReferenceMapping mapping=(XMLObjectReferenceMapping)reference.getMapping();
      if (value != null) {
        mapping.setAttributeValueInObject(reference.getSourceObject(),value);
      }
      if (null != reference.getSetting()) {
        reference.getSetting().setValue(value);
      }
      XMLInverseReferenceMapping inverseReferenceMapping=mapping.getInverseReferenceMapping();
      if (inverseReferenceMapping != null) {
        AttributeAccessor backpointerAccessor=inverseReferenceMapping.getAttributeAccessor();
        ContainerPolicy backpointerContainerPolicy=inverseReferenceMapping.getContainerPolicy();
        if (backpointerContainerPolicy == null) {
          backpointerAccessor.setAttributeValueInObject(value,referenceSourceObject);
        }
 else {
          Object backpointerContainer=backpointerAccessor.getAttributeValueFromObject(value);
          if (backpointerContainer == null) {
            backpointerContainer=backpointerContainerPolicy.containerInstance();
            backpointerAccessor.setAttributeValueInObject(value,backpointerContainer);
          }
          backpointerContainerPolicy.addInto(reference.getSourceObject(),backpointerContainer,session);
        }
      }
    }
  }
  if (session.isUnitOfWork()) {
    ((UnitOfWork)session).release();
  }
  references=new ArrayList();
}