Program: 65830
Project: 65830
Buggy source:
public void endDocument() throws SAXException {
  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);
      }
    }
  }
  try {
    if (null != containersMap) {
      for (      Entry<ContainerValue,Object> entry : containersMap.entrySet()) {
        entry.getKey().setContainerInstance(currentObject,entry.getValue());
      }
    }
    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 (getUnmarshaller().getUnmarshalListener() != null) {
      if (this.parentRecord != null) {
        getUnmarshaller().getUnmarshalListener().afterUnmarshal(currentObject,parentRecord.getCurrentObject());
      }
 else {
        getUnmarshaller().getUnmarshalListener().afterUnmarshal(currentObject,null);
      }
    }
    ClassDescriptor xmlDescriptor=treeObjectBuilder.getDescriptor();
    if (xmlDescriptor.getEventManager().hasAnyEventListeners()) {
      DescriptorEvent event=new DescriptorEvent(currentObject);
      event.setSession(session);
      event.setRecord(this);
      event.setEventCode(DescriptorEventManager.PostBuildEvent);
      xmlDescriptor.getEventManager().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()) {
    ClassDescriptor xmlDescriptor=treeObjectBuilder.getDescriptor();
    if (null != xmlDescriptor) {
      List primaryKeyFields=xmlDescriptor.getPrimaryKeyFields();
      int primaryKeyFieldsSize=primaryKeyFields.size();
      if (primaryKeyFieldsSize > 0) {
        Object pk=treeObjectBuilder.extractPrimaryKeyFromObject(currentObject,session);
        for (int x=0; x < primaryKeyFieldsSize; x++) {
          Object value=((CacheId)pk).getPrimaryKey()[x];
          if (null == value) {
            XMLField pkField=(XMLField)xmlDescriptor.getPrimaryKeyFields().get(x);
            ((CacheId)pk).set(x,getUnmarshaller().getXMLContext().getValueByXPath(currentObject,pkField.getXPath(),pkField.getNamespaceResolver(),Object.class));
          }
        }
        CacheKey key=session.getIdentityMapAccessorInstance().acquireDeferredLock(pk,xmlDescriptor.getJavaClass(),xmlDescriptor);
        key.setRecord(this);
        key.setObject(currentObject);
        key.releaseDeferredLock();
      }
    }
  }
  if (null != parentRecord) {
    reset();
  }
}

Fixed version (ground truth):
public void endDocument() throws SAXException {
  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);
      }
    }
  }
  try {
    if (null != containersMap) {
      for (      Entry<ContainerValue,Object> entry : containersMap.entrySet()) {
        entry.getKey().setContainerInstance(currentObject,entry.getValue());
      }
    }
    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 (getUnmarshaller().getUnmarshalListener() != null) {
      if (this.parentRecord != null) {
        getUnmarshaller().getUnmarshalListener().afterUnmarshal(currentObject,parentRecord.getCurrentObject());
      }
 else {
        getUnmarshaller().getUnmarshalListener().afterUnmarshal(currentObject,null);
      }
    }
    ClassDescriptor xmlDescriptor=treeObjectBuilder.getDescriptor();
    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()) {
    ClassDescriptor xmlDescriptor=treeObjectBuilder.getDescriptor();
    if (null != xmlDescriptor) {
      List primaryKeyFields=xmlDescriptor.getPrimaryKeyFields();
      int primaryKeyFieldsSize=primaryKeyFields.size();
      if (primaryKeyFieldsSize > 0) {
        Object pk=treeObjectBuilder.extractPrimaryKeyFromObject(currentObject,session);
        for (int x=0; x < primaryKeyFieldsSize; x++) {
          Object value=((CacheId)pk).getPrimaryKey()[x];
          if (null == value) {
            XMLField pkField=(XMLField)xmlDescriptor.getPrimaryKeyFields().get(x);
            ((CacheId)pk).set(x,getUnmarshaller().getXMLContext().getValueByXPath(currentObject,pkField.getXPath(),pkField.getNamespaceResolver(),Object.class));
          }
        }
        CacheKey key=session.getIdentityMapAccessorInstance().acquireDeferredLock(pk,xmlDescriptor.getJavaClass(),xmlDescriptor);
        key.setRecord(this);
        key.setObject(currentObject);
        key.releaseDeferredLock();
      }
    }
  }
  if (null != parentRecord) {
    reset();
  }
}