Program: 172356
Project: 172356
Buggy source:
/** 
 * Relink the content data from a new node to an existing node to preserve the version history.
 * @param oldNodeRef NodeRef
 * @param newNodeRef NodeRef
 */
public void relinkNode(NodeRef tempNodeRef,NodeRef nodeToMoveRef,NodeRef newParentNodeRef,String newName) throws FileNotFoundException, FileExistsException {
  org.alfresco.service.cmr.model.FileInfo tempFileInfo=fileFolderService.getFileInfo(tempNodeRef);
  org.alfresco.service.cmr.model.FileInfo fileToMoveInfo=fileFolderService.getFileInfo(nodeToMoveRef);
  String tempName=tempFileInfo.getName();
  try {
    fileFolderService.rename(tempNodeRef,newName);
    fileFolderService.rename(nodeToMoveRef,tempName);
  }
 catch (  org.alfresco.service.cmr.model.FileNotFoundException e) {
    throw new FileNotFoundException(e.getMessage());
  }
catch (  org.alfresco.service.cmr.model.FileExistsException e) {
    throw new FileExistsException(e.getMessage());
  }
  if (!tempFileInfo.isFolder() && !fileToMoveInfo.isFolder()) {
    ContentData oldContentData=tempFileInfo.getContentData();
    if (oldContentData == null) {
      String mimetype=mimetypeService.guessMimetype(tempName);
      oldContentData=ContentData.setMimetype(null,mimetype);
    }
    ContentData newContentData=fileToMoveInfo.getContentData();
    if (newContentData == null) {
      String mimetype=mimetypeService.guessMimetype(newName);
      newContentData=ContentData.setMimetype(null,mimetype);
    }
    nodeService.setProperty(tempNodeRef,ContentModel.PROP_CONTENT,newContentData);
    nodeService.setProperty(nodeToMoveRef,ContentModel.PROP_CONTENT,oldContentData);
  }
}

Fixed version (ground truth):
/** 
 * Relink the content data from a new node to an existing node to preserve the version history.
 * @param oldNodeRef NodeRef
 * @param newNodeRef NodeRef
 */
public void relinkNode(NodeRef tempNodeRef,NodeRef nodeToMoveRef,NodeRef newParentNodeRef,String newName) throws FileNotFoundException, FileExistsException {
  org.alfresco.service.cmr.model.FileInfo tempFileInfo=fileFolderService.getFileInfo(tempNodeRef);
  org.alfresco.service.cmr.model.FileInfo fileToMoveInfo=fileFolderService.getFileInfo(nodeToMoveRef);
  String tempName=tempFileInfo.getName();
  try {
    fileFolderService.rename(tempNodeRef,newName);
    fileFolderService.rename(nodeToMoveRef,tempName);
  }
 catch (  org.alfresco.service.cmr.model.FileNotFoundException e) {
    throw new FileNotFoundException(e.getMessage());
  }
catch (  org.alfresco.service.cmr.model.FileExistsException e) {
    throw new FileExistsException(e.getMessage());
  }
  if (!tempFileInfo.isFolder() && !fileToMoveInfo.isFolder()) {
    ContentData oldContentData=tempFileInfo.getContentData();
    if (oldContentData == null) {
      String mimetype=mimetypeService.guessMimetype(tempName);
      oldContentData=ContentData.setMimetype(null,mimetype);
    }
    ContentData newContentData=fileToMoveInfo.getContentData();
    String mimetype=mimetypeService.guessMimetype(newName);
    newContentData=ContentData.setMimetype(newContentData,mimetype);
    nodeService.setProperty(tempNodeRef,ContentModel.PROP_CONTENT,newContentData);
    nodeService.setProperty(nodeToMoveRef,ContentModel.PROP_CONTENT,oldContentData);
  }
}