Program: 64938
Project: 64938
Buggy source:
public void endDocument() throws SAXException {
  if (unmarshaller.getIDResolver() != null && parentRecord == null) {
    unmarshaller.getIDResolver().endDocument();
  }
  if (null != selfRecords) {
    for (int x=0, selfRecordsSize=selfRecords.size(); x < selfRecordsSize; x++) {
      UnmarshalRecord selfRecord=selfRecords.get(x);
      if (selfRecord != null) {
        selfRecord.endDocument();
      }
    }
  }
  if (null != xPathNode.getSelfChildren()) {
    int selfChildrenSize=xPathNode.getSelfChildren().size();
    for (int x=0; x < selfChildrenSize; x++) {
      XPathNode selfNode=xPathNode.getSelfChildren().get(x);
      if (null != selfNode.getNodeValue()) {
        selfNode.getNodeValue().endSelfNodeValue(this,selfRecords.get(x),attributes);
      }
    }
  }
  ClassDescriptor xmlDescriptor=treeObjectBuilder.getDescriptor();
  try {
    List containerValues=treeObjectBuilder.getContainerValues();
    if (null != containerValues) {
      int size=containerValues.size();
      for (int i=0; i < size; i++) {
        ContainerValue cv=((ContainerValue)containerValues.get(i));
        cv.setContainerInstance(currentObject,getContainerInstance(cv,cv.isDefaultEmptyContainer()));
      }
    }
    if (null != nullCapableValues) {
      for (int x=0, nullValuesSize=nullCapableValues.size(); x < nullValuesSize; x++) {
        nullCapableValues.get(x).setNullValue(currentObject,session);
      }
    }
    List transformationMappings=treeObjectBuilder.getTransformationMappings();
    if (null != transformationMappings) {
      ReadObjectQuery query=new ReadObjectQuery();
      query.setSession(session);
      for (int x=0, transformationMappingsSize=transformationMappings.size(); x < transformationMappingsSize; x++) {
        AbstractTransformationMapping transformationMapping=(AbstractTransformationMapping)transformationMappings.get(x);
        transformationMapping.readFromRowIntoObject(transformationRecord,null,currentObject,null,query,session,true);
      }
    }
    if (unmarshaller.getUnmarshalListener() != null) {
      if (this.parentRecord != null) {
        unmarshaller.getUnmarshalListener().afterUnmarshal(currentObject,parentRecord.getCurrentObject());
      }
 else {
        unmarshaller.getUnmarshalListener().afterUnmarshal(currentObject,null);
      }
    }
    if (xmlDescriptor.hasEventManager()) {
      DescriptorEventManager eventManager=xmlDescriptor.getEventManager();
      if (null != eventManager && eventManager.hasAnyEventListeners()) {
        DescriptorEvent event=new DescriptorEvent(currentObject);
        event.setSession(session);
        event.setRecord(this);
        event.setEventCode(DescriptorEventManager.PostBuildEvent);
        eventManager.executeEvent(event);
      }
    }
  }
 catch (  EclipseLinkException e) {
    if (null == xmlReader.getErrorHandler()) {
      throw e;
    }
 else {
      SAXParseException saxParseException=new SAXParseException(null,null,null,0,0,e);
      xmlReader.getErrorHandler().error(saxParseException);
    }
  }
  if (session.isUnitOfWork()) {
    if (null != xmlDescriptor) {
      List primaryKeyFields=xmlDescriptor.getPrimaryKeyFields();
      if (null != primaryKeyFields) {
        int primaryKeyFieldsSize=primaryKeyFields.size();
        if (primaryKeyFieldsSize > 0) {
          CacheId pk=(CacheId)treeObjectBuilder.extractPrimaryKeyFromObject(currentObject,session);
          for (int x=0; x < primaryKeyFieldsSize; x++) {
            Object value=pk.getPrimaryKey()[x];
            if (null == value) {
              XMLField pkField=(XMLField)xmlDescriptor.getPrimaryKeyFields().get(x);
              pk.set(x,unmarshaller.getXMLContext().getValueByXPath(currentObject,pkField.getXPath(),pkField.getNamespaceResolver(),Object.class));
            }
          }
          CacheKey key=session.getIdentityMapAccessorInstance().acquireDeferredLock(pk,xmlDescriptor.getJavaClass(),xmlDescriptor,false);
          key.setRecord(this);
          key.setObject(currentObject);
          key.releaseDeferredLock();
          if (unmarshaller.getIDResolver() != null) {
            try {
              if (primaryKeyFieldsSize > 1) {
                Map<String,Object> idWrapper=new HashMap<String,Object>();
                for (int x=0; x < primaryKeyFieldsSize; x++) {
                  String idName=xmlDescriptor.getPrimaryKeyFieldNames().elementAt(x);
                  Object idValue=pk.getPrimaryKey()[x];
                  idWrapper.put(idName,idValue);
                }
                unmarshaller.getIDResolver().bind(idWrapper,currentObject);
              }
 else {
                unmarshaller.getIDResolver().bind(pk.getPrimaryKey()[0],currentObject);
              }
            }
 catch (            SAXException e) {
              throw XMLMarshalException.unmarshalException(e);
            }
          }
        }
      }
    }
  }
  if (null != parentRecord) {
    reset();
  }
  if (getXmlLocation() != null && ((XMLDescriptor)xmlDescriptor).getLocationAccessor() != null) {
    ((XMLDescriptor)xmlDescriptor).getLocationAccessor().setAttributeValueInObject(getCurrentObject(),getXmlLocation());
  }
}

Fixed version (ground truth):
public void endDocument() throws SAXException {
  if (unmarshaller.getIDResolver() != null && parentRecord == null) {
    unmarshaller.getIDResolver().endDocument();
  }
  if (null != selfRecords) {
    for (int x=0, selfRecordsSize=selfRecords.size(); x < selfRecordsSize; x++) {
      UnmarshalRecord selfRecord=selfRecords.get(x);
      if (selfRecord != null) {
        selfRecord.endDocument();
      }
    }
  }
  if (null != xPathNode.getSelfChildren()) {
    int selfChildrenSize=xPathNode.getSelfChildren().size();
    for (int x=0; x < selfChildrenSize; x++) {
      XPathNode selfNode=xPathNode.getSelfChildren().get(x);
      if (null != selfNode.getNodeValue()) {
        selfNode.getNodeValue().endSelfNodeValue(this,selfRecords.get(x),attributes);
      }
    }
  }
  ClassDescriptor xmlDescriptor=treeObjectBuilder.getDescriptor();
  try {
    if (null != populatedContainerValues) {
      for (int populatedCVSize=populatedContainerValues.size(), i=populatedCVSize - 1; i >= 0; i--) {
        ContainerValue cv=((ContainerValue)populatedContainerValues.get(i));
        cv.setContainerInstance(currentObject,getContainerInstance(cv,cv.isDefaultEmptyContainer()));
      }
    }
    if (null != defaultEmptyContainerValues) {
      for (int defaultEmptyCVSize=defaultEmptyContainerValues.size(), i=defaultEmptyCVSize - 1; i >= 0; i--) {
        ContainerValue cv=((ContainerValue)defaultEmptyContainerValues.get(i));
        cv.setContainerInstance(currentObject,getContainerInstance(cv,cv.isDefaultEmptyContainer()));
      }
    }
    if (null != nullCapableValues) {
      for (int x=0, nullValuesSize=nullCapableValues.size(); x < nullValuesSize; x++) {
        nullCapableValues.get(x).setNullValue(currentObject,session);
      }
    }
    List transformationMappings=treeObjectBuilder.getTransformationMappings();
    if (null != transformationMappings) {
      ReadObjectQuery query=new ReadObjectQuery();
      query.setSession(session);
      for (int x=0, transformationMappingsSize=transformationMappings.size(); x < transformationMappingsSize; x++) {
        AbstractTransformationMapping transformationMapping=(AbstractTransformationMapping)transformationMappings.get(x);
        transformationMapping.readFromRowIntoObject(transformationRecord,null,currentObject,null,query,session,true);
      }
    }
    if (unmarshaller.getUnmarshalListener() != null) {
      if (this.parentRecord != null) {
        unmarshaller.getUnmarshalListener().afterUnmarshal(currentObject,parentRecord.getCurrentObject());
      }
 else {
        unmarshaller.getUnmarshalListener().afterUnmarshal(currentObject,null);
      }
    }
    if (xmlDescriptor.hasEventManager()) {
      DescriptorEventManager eventManager=xmlDescriptor.getEventManager();
      if (null != eventManager && eventManager.hasAnyEventListeners()) {
        DescriptorEvent event=new DescriptorEvent(currentObject);
        event.setSession(session);
        event.setRecord(this);
        event.setEventCode(DescriptorEventManager.PostBuildEvent);
        eventManager.executeEvent(event);
      }
    }
  }
 catch (  EclipseLinkException e) {
    if (null == xmlReader.getErrorHandler()) {
      throw e;
    }
 else {
      SAXParseException saxParseException=new SAXParseException(null,null,null,0,0,e);
      xmlReader.getErrorHandler().error(saxParseException);
    }
  }
  if (session.isUnitOfWork()) {
    if (null != xmlDescriptor) {
      List primaryKeyFields=xmlDescriptor.getPrimaryKeyFields();
      if (null != primaryKeyFields) {
        int primaryKeyFieldsSize=primaryKeyFields.size();
        if (primaryKeyFieldsSize > 0) {
          CacheId pk=(CacheId)treeObjectBuilder.extractPrimaryKeyFromObject(currentObject,session);
          for (int x=0; x < primaryKeyFieldsSize; x++) {
            Object value=pk.getPrimaryKey()[x];
            if (null == value) {
              XMLField pkField=(XMLField)xmlDescriptor.getPrimaryKeyFields().get(x);
              pk.set(x,unmarshaller.getXMLContext().getValueByXPath(currentObject,pkField.getXPath(),pkField.getNamespaceResolver(),Object.class));
            }
          }
          CacheKey key=session.getIdentityMapAccessorInstance().acquireDeferredLock(pk,xmlDescriptor.getJavaClass(),xmlDescriptor,false);
          key.setRecord(this);
          key.setObject(currentObject);
          key.releaseDeferredLock();
          if (unmarshaller.getIDResolver() != null) {
            try {
              if (primaryKeyFieldsSize > 1) {
                Map<String,Object> idWrapper=new HashMap<String,Object>();
                for (int x=0; x < primaryKeyFieldsSize; x++) {
                  String idName=xmlDescriptor.getPrimaryKeyFieldNames().elementAt(x);
                  Object idValue=pk.getPrimaryKey()[x];
                  idWrapper.put(idName,idValue);
                }
                unmarshaller.getIDResolver().bind(idWrapper,currentObject);
              }
 else {
                unmarshaller.getIDResolver().bind(pk.getPrimaryKey()[0],currentObject);
              }
            }
 catch (            SAXException e) {
              throw XMLMarshalException.unmarshalException(e);
            }
          }
        }
      }
    }
  }
  if (null != parentRecord) {
    reset();
  }
  if (getXmlLocation() != null && ((XMLDescriptor)xmlDescriptor).getLocationAccessor() != null) {
    ((XMLDescriptor)xmlDescriptor).getLocationAccessor().setAttributeValueInObject(getCurrentObject(),getXmlLocation());
  }
}