Program: 63857
Project: 63857
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);
      }
    }
  }
  CoreDescriptor xmlDescriptor=(CoreDescriptor)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((AbstractSession)session);
      for (int x=0, transformationMappingsSize=transformationMappings.size(); x < transformationMappingsSize; x++) {
        AbstractTransformationMapping transformationMapping=(AbstractTransformationMapping)transformationMappings.get(x);
        transformationMapping.readFromRowIntoObject(transformationRecord,null,currentObject,null,query,(AbstractSession)session,true);
      }
    }
    XMLUnmarshalListener listener=unmarshaller.getUnmarshalListener();
    if (listener != null) {
      if (this.parentRecord != null) {
        listener.afterUnmarshal(currentObject,parentRecord.getCurrentObject());
      }
 else {
        listener.afterUnmarshal(currentObject,null);
      }
    }
    if (xmlDescriptor.hasEventManager()) {
      CoreDescriptorEventManager eventManager=xmlDescriptor.getEventManager();
      if (null != eventManager && eventManager.hasAnyEventListeners()) {
        DescriptorEvent event=new DescriptorEvent(currentObject);
        event.setSession((AbstractSession)session);
        event.setRecord(null);
        event.setEventCode(DescriptorEventManager.PostBuildEvent);
        eventManager.executeEvent(event);
      }
    }
  }
 catch (  EclipseLinkException e) {
    if (null == xmlReader.getErrorHandler()) {
      throw e;
    }
 else {
      SAXParseException saxParseException=new SAXParseException(null,getDocumentLocator(),e);
      xmlReader.getErrorHandler().error(saxParseException);
    }
  }
  if (null != referenceResolver) {
    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) {
              Field pkField=(Field)xmlDescriptor.getPrimaryKeyFields().get(x);
              pk.set(x,unmarshaller.getContext().getValueByXPath(currentObject,pkField.getXPath(),pkField.getNamespaceResolver(),Object.class));
            }
          }
          referenceResolver.putValue(xmlDescriptor.getJavaClass(),pk,currentObject);
          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=(String)xmlDescriptor.getPrimaryKeyFieldNames().get(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 (xmlLocation != null && ((Descriptor)xmlDescriptor).getLocationAccessor() != null) {
    ((Descriptor)xmlDescriptor).getLocationAccessor().setAttributeValueInObject(getCurrentObject(),xmlLocation);
  }
}

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);
      }
    }
  }
  CoreDescriptor xmlDescriptor=(CoreDescriptor)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((AbstractSession)session);
      for (int x=0, transformationMappingsSize=transformationMappings.size(); x < transformationMappingsSize; x++) {
        AbstractTransformationMapping transformationMapping=(AbstractTransformationMapping)transformationMappings.get(x);
        transformationMapping.readFromRowIntoObject(transformationRecord,null,currentObject,null,query,(AbstractSession)session,true);
      }
    }
    Unmarshaller.Listener listener=unmarshaller.getUnmarshalListener();
    if (listener != null) {
      if (this.parentRecord != null) {
        listener.afterUnmarshal(currentObject,parentRecord.getCurrentObject());
      }
 else {
        listener.afterUnmarshal(currentObject,null);
      }
    }
    if (xmlDescriptor.hasEventManager()) {
      CoreDescriptorEventManager eventManager=xmlDescriptor.getEventManager();
      if (null != eventManager && eventManager.hasAnyEventListeners()) {
        DescriptorEvent event=new DescriptorEvent(currentObject);
        event.setSession((AbstractSession)session);
        event.setRecord(null);
        event.setEventCode(DescriptorEventManager.PostBuildEvent);
        eventManager.executeEvent(event);
      }
    }
  }
 catch (  EclipseLinkException e) {
    if (null == xmlReader.getErrorHandler()) {
      throw e;
    }
 else {
      SAXParseException saxParseException=new SAXParseException(null,getDocumentLocator(),e);
      xmlReader.getErrorHandler().error(saxParseException);
    }
  }
  if (null != referenceResolver) {
    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) {
              Field pkField=(Field)xmlDescriptor.getPrimaryKeyFields().get(x);
              pk.set(x,unmarshaller.getContext().getValueByXPath(currentObject,pkField.getXPath(),pkField.getNamespaceResolver(),Object.class));
            }
          }
          referenceResolver.putValue(xmlDescriptor.getJavaClass(),pk,currentObject);
          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=(String)xmlDescriptor.getPrimaryKeyFieldNames().get(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 (xmlLocation != null && ((Descriptor)xmlDescriptor).getLocationAccessor() != null) {
    ((Descriptor)xmlDescriptor).getLocationAccessor().setAttributeValueInObject(getCurrentObject(),xmlLocation);
  }
}