Program: 66761
Project: 66761
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);
    if (reference.getMapping() instanceof XMLCollectionReferenceMapping) {
      XMLCollectionReferenceMapping mapping=(XMLCollectionReferenceMapping)reference.getMapping();
      ContainerPolicy cPolicy=mapping.getContainerPolicy();
      Object currentObject=reference.getSourceObject();
      Object container=null;
      if (mapping.getReuseContainer()) {
        container=mapping.getAttributeAccessor().getAttributeValueFromObject(currentObject);
      }
 else {
        container=cPolicy.containerInstance();
      }
      createPKVectorsFromMap(reference);
      for (Iterator pkIt=reference.getPrimaryKeys().iterator(); pkIt.hasNext(); ) {
        Vector pkVector=(Vector)pkIt.next();
        Object value=session.getIdentityMapAccessor().getFromIdentityMap(pkVector,reference.getTargetClass());
        if (value != null) {
          cPolicy.addInto(value,container,session);
        }
      }
      mapping.setAttributeValueInObject(currentObject,container);
      if (mapping.getBidirectionalTargetAccessor() != null) {
        Object iterator=cPolicy.iteratorFor(container);
        while (cPolicy.hasNext(iterator)) {
          Object next=cPolicy.next(iterator,session);
          if (mapping.getBidirectionalTargetContainerPolicy() == null) {
            mapping.getBidirectionalTargetAccessor().setAttributeValueInObject(next,currentObject);
          }
 else {
            Object backpointerContainer=mapping.getBidirectionalTargetAccessor().getAttributeValueFromObject(next);
            if (backpointerContainer == null) {
              backpointerContainer=mapping.getBidirectionalTargetContainerPolicy().containerInstance();
              mapping.getBidirectionalTargetAccessor().setAttributeValueInObject(next,backpointerContainer);
            }
            mapping.getBidirectionalTargetContainerPolicy().addInto(currentObject,backpointerContainer,session);
          }
        }
      }
    }
 else     if (reference.getMapping() instanceof XMLObjectReferenceMapping) {
      Object value=session.getIdentityMapAccessor().getFromIdentityMap(reference.getPrimaryKeys(),reference.getTargetClass());
      XMLObjectReferenceMapping mapping=(XMLObjectReferenceMapping)reference.getMapping();
      if (value != null) {
        mapping.setAttributeValueInObject(reference.getSourceObject(),value);
      }
      if (null != reference.getSetting()) {
        reference.getSetting().setValue(value);
      }
      AttributeAccessor backpointerAccessor=mapping.getBidirectionalTargetAccessor();
      if (backpointerAccessor != null) {
        if (mapping.getBidirectionalTargetContainerPolicy() == null) {
          mapping.getBidirectionalTargetAccessor().setAttributeValueInObject(value,reference.getSourceObject());
        }
 else {
          Object backpointerContainer=mapping.getBidirectionalTargetAccessor().getAttributeValueFromObject(value);
          if (backpointerContainer == null) {
            backpointerContainer=mapping.getBidirectionalTargetContainerPolicy().containerInstance();
            mapping.getBidirectionalTargetAccessor().setAttributeValueInObject(value,backpointerContainer);
          }
          mapping.getBidirectionalTargetContainerPolicy().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);
    if (reference.getMapping() instanceof XMLCollectionReferenceMapping) {
      XMLCollectionReferenceMapping mapping=(XMLCollectionReferenceMapping)reference.getMapping();
      ContainerPolicy cPolicy=mapping.getContainerPolicy();
      Object currentObject=reference.getSourceObject();
      Object container=null;
      if (mapping.getReuseContainer()) {
        container=mapping.getAttributeAccessor().getAttributeValueFromObject(currentObject);
      }
 else {
        container=cPolicy.containerInstance();
      }
      createPKVectorsFromMap(reference);
      for (Iterator pkIt=reference.getPrimaryKeys().iterator(); pkIt.hasNext(); ) {
        Vector pkVector=(Vector)pkIt.next();
        Object value=session.getIdentityMapAccessor().getFromIdentityMap(pkVector,reference.getTargetClass());
        if (value != null) {
          cPolicy.addInto(value,container,session);
        }
      }
      mapping.setAttributeValueInObject(currentObject,container);
      if (mapping.getInverseReferenceMapping() != null) {
        Object iterator=cPolicy.iteratorFor(container);
        while (cPolicy.hasNext(iterator)) {
          Object next=cPolicy.next(iterator,session);
          if (mapping.getInverseReferenceMapping().getContainerPolicy() == null) {
            mapping.getInverseReferenceMapping().getAttributeAccessor().setAttributeValueInObject(next,currentObject);
          }
 else {
            Object backpointerContainer=mapping.getInverseReferenceMapping().getAttributeAccessor().getAttributeValueFromObject(next);
            if (backpointerContainer == null) {
              backpointerContainer=mapping.getInverseReferenceMapping().getContainerPolicy().containerInstance();
              mapping.getInverseReferenceMapping().getAttributeAccessor().setAttributeValueInObject(next,backpointerContainer);
            }
            mapping.getInverseReferenceMapping().getContainerPolicy().addInto(currentObject,backpointerContainer,session);
          }
        }
      }
    }
 else     if (reference.getMapping() instanceof XMLObjectReferenceMapping) {
      Object value=session.getIdentityMapAccessor().getFromIdentityMap(reference.getPrimaryKeys(),reference.getTargetClass());
      XMLObjectReferenceMapping mapping=(XMLObjectReferenceMapping)reference.getMapping();
      if (value != null) {
        mapping.setAttributeValueInObject(reference.getSourceObject(),value);
      }
      if (null != reference.getSetting()) {
        reference.getSetting().setValue(value);
      }
      if (mapping.getInverseReferenceMapping() != null) {
        AttributeAccessor backpointerAccessor=mapping.getInverseReferenceMapping().getAttributeAccessor();
        if (mapping.getInverseReferenceMapping().getContainerPolicy() == null) {
          backpointerAccessor.setAttributeValueInObject(value,reference.getSourceObject());
        }
 else {
          Object backpointerContainer=backpointerAccessor.getAttributeValueFromObject(value);
          if (backpointerContainer == null) {
            backpointerContainer=mapping.getInverseReferenceMapping().getContainerPolicy().containerInstance();
            backpointerAccessor.setAttributeValueInObject(value,backpointerContainer);
          }
          mapping.getInverseReferenceMapping().getContainerPolicy().addInto(reference.getSourceObject(),backpointerContainer,session);
        }
      }
    }
  }
  if (session.isUnitOfWork()) {
    ((UnitOfWork)session).release();
  }
  references=new ArrayList();
}