Program: 172123
Project: 172123
Buggy source:
/** 
 * @param node
 * @param resolvedNodes
 * @param primaryParentAssoc
 */
private void update(TransferManifestNormalNode node,ResolvedParentChildPair resolvedNodes,ChildAssociationRef primaryParentAssoc){
  NodeRef nodeToUpdate=resolvedNodes.resolvedChild;
  if (nodeService.hasAspect(nodeToUpdate,TransferModel.ASPECT_TRANSFERRED)) {
    String fromRepository=(String)nodeService.getProperty(nodeToUpdate,TransferModel.PROP_FROM_REPOSITORY_ID);
    String transferringRepo=header.getRepositoryId();
    if (fromRepository != null && transferringRepo != null) {
      if (!fromRepository.equalsIgnoreCase(transferringRepo)) {
        logComment("String_Node_Str" + node.getNodeRef());
        return;
      }
    }
  }
  QName parentAssocType=primaryParentAssoc.getTypeQName();
  QName parentAssocName=primaryParentAssoc.getQName();
  NodeRef parentNodeRef=resolvedNodes.resolvedParent;
  if (parentNodeRef == null) {
    ChildAssociationRef tempLocation=getTemporaryLocation(node.getNodeRef());
    parentNodeRef=tempLocation.getParentRef();
    parentAssocType=tempLocation.getTypeQName();
    parentAssocName=tempLocation.getQName();
    storeOrphanNode(primaryParentAssoc);
  }
  ChildAssociationRef currentParent=nodeService.getPrimaryParent(nodeToUpdate);
  if (!currentParent.getParentRef().equals(parentNodeRef) || !currentParent.getTypeQName().equals(parentAssocType) || !currentParent.getQName().equals(parentAssocName)) {
    if (nodeService.hasAspect(currentParent.getParentRef(),TransferModel.ASPECT_ALIEN)) {
      alienProcessor.beforeDeleteAlien(currentParent.getChildRef(),null);
    }
    ChildAssociationRef newNode=nodeService.moveNode(nodeToUpdate,parentNodeRef,parentAssocType,parentAssocName);
    logMoved(node.getNodeRef(),nodeToUpdate,node.getParentPath(),newNode.getParentRef(),nodeService.getPath(newNode.getChildRef()));
    if (nodeService.hasAspect(newNode.getChildRef(),TransferModel.ASPECT_ALIEN)) {
      alienProcessor.afterMoveAlien(newNode);
    }
 else {
      if (nodeService.hasAspect(parentNodeRef,TransferModel.ASPECT_TRANSFERRED) || nodeService.hasAspect(parentNodeRef,TransferModel.ASPECT_ALIEN)) {
        alienProcessor.onCreateChild(newNode,header.getRepositoryId(),true);
      }
    }
  }
  log.info("String_Node_Str" + parentNodeRef);
  if (updateNeeded(node,nodeToUpdate)) {
    logUpdated(node.getNodeRef(),nodeToUpdate,nodeService.getPath(nodeToUpdate));
    Map<QName,Serializable> props=new HashMap<QName,Serializable>(node.getProperties());
    Map<QName,Serializable> existingProps=nodeService.getProperties(nodeToUpdate);
    injectTransferred(props);
    props.remove(TransferModel.PROP_INVADED_BY);
    if (header.isReadOnly()) {
      props.put(ContentModel.PROP_LOCK_OWNER,AuthenticationUtil.getAdminUserName());
      props.put(ContentModel.PROP_LOCK_TYPE,LockType.NODE_LOCK.toString());
      props.put(ContentModel.PROP_EXPIRY_DATE,null);
      log.debug("String_Node_Str");
    }
    Map<QName,Serializable> contentProps=processProperties(nodeToUpdate,props,existingProps);
    if (existingProps.containsKey(TransferModel.PROP_INVADED_BY)) {
      props.put(TransferModel.PROP_INVADED_BY,existingProps.get(TransferModel.PROP_INVADED_BY));
    }
    nodeService.setProperties(nodeToUpdate,props);
    writeContent(nodeToUpdate,contentProps);
    Set<QName> suppliedAspects=new HashSet<QName>(node.getAspects());
    Set<QName> existingAspects=nodeService.getAspects(nodeToUpdate);
    Set<QName> aspectsToRemove=new HashSet<QName>(existingAspects);
    List<AspectDefinition> aspectDefs=dictionaryService.getType(nodeService.getType(nodeToUpdate)).getDefaultAspects(true);
    for (    AspectDefinition aspectDef : aspectDefs) {
      suppliedAspects.add(aspectDef.getName());
    }
    if (header.isReadOnly()) {
      suppliedAspects.add(ContentModel.ASPECT_LOCKABLE);
    }
    aspectsToRemove.removeAll(suppliedAspects);
    aspectsToRemove.remove(TransferModel.ASPECT_TRANSFERRED);
    aspectsToRemove.remove(TransferModel.ASPECT_ALIEN);
    suppliedAspects.removeAll(existingAspects);
    for (    QName aspect : suppliedAspects) {
      nodeService.addAspect(nodeToUpdate,aspect,null);
    }
    for (    QName aspect : aspectsToRemove) {
      nodeService.removeAspect(nodeToUpdate,aspect);
    }
    ManifestAccessControl acl=node.getAccessControl();
    if (acl != null) {
      boolean existInherit=permissionService.getInheritParentPermissions(nodeToUpdate);
      if (existInherit != acl.isInherited()) {
        log.debug("String_Node_Str");
        permissionService.setInheritParentPermissions(nodeToUpdate,acl.isInherited());
      }
      Set<AccessPermission> existingPermissions=permissionService.getAllSetPermissions(nodeToUpdate);
      List<ManifestPermission> newPermissions=acl.getPermissions();
      if (existingPermissions.size() > 0 || newPermissions != null) {
        log.debug("String_Node_Str");
        Set<ManifestPermission> work=new HashSet<ManifestPermission>();
        for (        AccessPermission permission : existingPermissions) {
          if (permission.isSetDirectly()) {
            ManifestPermission p=new ManifestPermission();
            p.setAuthority(permission.getAuthority());
            p.setPermission(permission.getPermission());
            p.setStatus(permission.getAccessStatus().toString());
            work.add(p);
          }
        }
        if (newPermissions != null) {
          for (          ManifestPermission permission : acl.getPermissions()) {
            if (!work.contains(permission)) {
              log.debug("String_Node_Str" + permission);
              AccessStatus status=AccessStatus.valueOf(permission.getStatus());
              permissionService.setPermission(nodeToUpdate,permission.getAuthority(),permission.getPermission(),status == AccessStatus.ALLOWED);
            }
          }
          work.removeAll(newPermissions);
        }
        for (        ManifestPermission permission : work) {
          log.debug("String_Node_Str" + permission);
          permissionService.deletePermission(nodeToUpdate,permission.getAuthority(),permission.getPermission());
        }
      }
    }
  }
}

Fixed version (ground truth):
/** 
 * @param node
 * @param resolvedNodes
 * @param primaryParentAssoc
 */
private void update(TransferManifestNormalNode node,ResolvedParentChildPair resolvedNodes,ChildAssociationRef primaryParentAssoc){
  NodeRef nodeToUpdate=resolvedNodes.resolvedChild;
  if (nodeService.hasAspect(nodeToUpdate,TransferModel.ASPECT_TRANSFERRED)) {
    String fromRepository=(String)nodeService.getProperty(nodeToUpdate,TransferModel.PROP_FROM_REPOSITORY_ID);
    String transferringRepo=header.getRepositoryId();
    if (fromRepository != null && transferringRepo != null) {
      if (!fromRepository.equalsIgnoreCase(transferringRepo)) {
        logComment("String_Node_Str" + node.getNodeRef());
        return;
      }
    }
  }
  QName parentAssocType=primaryParentAssoc.getTypeQName();
  QName parentAssocName=primaryParentAssoc.getQName();
  NodeRef parentNodeRef=resolvedNodes.resolvedParent;
  if (parentNodeRef == null) {
    ChildAssociationRef tempLocation=getTemporaryLocation(node.getNodeRef());
    parentNodeRef=tempLocation.getParentRef();
    parentAssocType=tempLocation.getTypeQName();
    parentAssocName=tempLocation.getQName();
    storeOrphanNode(primaryParentAssoc);
  }
  ChildAssociationRef currentParent=nodeService.getPrimaryParent(nodeToUpdate);
  if (!currentParent.getParentRef().equals(parentNodeRef) || !currentParent.getTypeQName().equals(parentAssocType) || !currentParent.getQName().equals(parentAssocName)) {
    if (nodeService.hasAspect(currentParent.getParentRef(),TransferModel.ASPECT_ALIEN)) {
      alienProcessor.beforeDeleteAlien(currentParent.getChildRef(),null);
    }
    ChildAssociationRef newNode=nodeService.moveNode(nodeToUpdate,parentNodeRef,parentAssocType,parentAssocName);
    logMoved(node.getNodeRef(),nodeToUpdate,node.getParentPath().toString(),newNode.getParentRef(),nodeService.getPath(newNode.getChildRef()).toString());
    if (nodeService.hasAspect(newNode.getChildRef(),TransferModel.ASPECT_ALIEN)) {
      alienProcessor.afterMoveAlien(newNode);
    }
 else {
      if (nodeService.hasAspect(parentNodeRef,TransferModel.ASPECT_TRANSFERRED) || nodeService.hasAspect(parentNodeRef,TransferModel.ASPECT_ALIEN)) {
        alienProcessor.onCreateChild(newNode,header.getRepositoryId(),true);
      }
    }
  }
  log.info("String_Node_Str" + parentNodeRef);
  if (updateNeeded(node,nodeToUpdate)) {
    logUpdated(node.getNodeRef(),nodeToUpdate,nodeService.getPath(nodeToUpdate).toString());
    Map<QName,Serializable> props=new HashMap<QName,Serializable>(node.getProperties());
    Map<QName,Serializable> existingProps=nodeService.getProperties(nodeToUpdate);
    injectTransferred(props);
    props.remove(TransferModel.PROP_INVADED_BY);
    if (header.isReadOnly()) {
      props.put(ContentModel.PROP_LOCK_OWNER,AuthenticationUtil.getAdminUserName());
      props.put(ContentModel.PROP_LOCK_TYPE,LockType.NODE_LOCK.toString());
      props.put(ContentModel.PROP_EXPIRY_DATE,null);
      log.debug("String_Node_Str");
    }
    Map<QName,Serializable> contentProps=processProperties(nodeToUpdate,props,existingProps);
    if (existingProps.containsKey(TransferModel.PROP_INVADED_BY)) {
      props.put(TransferModel.PROP_INVADED_BY,existingProps.get(TransferModel.PROP_INVADED_BY));
    }
    nodeService.setProperties(nodeToUpdate,props);
    writeContent(nodeToUpdate,contentProps);
    Set<QName> suppliedAspects=new HashSet<QName>(node.getAspects());
    Set<QName> existingAspects=nodeService.getAspects(nodeToUpdate);
    Set<QName> aspectsToRemove=new HashSet<QName>(existingAspects);
    List<AspectDefinition> aspectDefs=dictionaryService.getType(nodeService.getType(nodeToUpdate)).getDefaultAspects(true);
    for (    AspectDefinition aspectDef : aspectDefs) {
      suppliedAspects.add(aspectDef.getName());
    }
    if (header.isReadOnly()) {
      suppliedAspects.add(ContentModel.ASPECT_LOCKABLE);
    }
    aspectsToRemove.removeAll(suppliedAspects);
    aspectsToRemove.remove(TransferModel.ASPECT_TRANSFERRED);
    aspectsToRemove.remove(TransferModel.ASPECT_ALIEN);
    suppliedAspects.removeAll(existingAspects);
    for (    QName aspect : suppliedAspects) {
      nodeService.addAspect(nodeToUpdate,aspect,null);
    }
    for (    QName aspect : aspectsToRemove) {
      nodeService.removeAspect(nodeToUpdate,aspect);
    }
    ManifestAccessControl acl=node.getAccessControl();
    if (acl != null) {
      boolean existInherit=permissionService.getInheritParentPermissions(nodeToUpdate);
      if (existInherit != acl.isInherited()) {
        log.debug("String_Node_Str");
        permissionService.setInheritParentPermissions(nodeToUpdate,acl.isInherited());
      }
      Set<AccessPermission> existingPermissions=permissionService.getAllSetPermissions(nodeToUpdate);
      List<ManifestPermission> newPermissions=acl.getPermissions();
      if (existingPermissions.size() > 0 || newPermissions != null) {
        log.debug("String_Node_Str");
        Set<ManifestPermission> work=new HashSet<ManifestPermission>();
        for (        AccessPermission permission : existingPermissions) {
          if (permission.isSetDirectly()) {
            ManifestPermission p=new ManifestPermission();
            p.setAuthority(permission.getAuthority());
            p.setPermission(permission.getPermission());
            p.setStatus(permission.getAccessStatus().toString());
            work.add(p);
          }
        }
        if (newPermissions != null) {
          for (          ManifestPermission permission : acl.getPermissions()) {
            if (!work.contains(permission)) {
              log.debug("String_Node_Str" + permission);
              AccessStatus status=AccessStatus.valueOf(permission.getStatus());
              permissionService.setPermission(nodeToUpdate,permission.getAuthority(),permission.getPermission(),status == AccessStatus.ALLOWED);
            }
          }
          work.removeAll(newPermissions);
        }
        for (        ManifestPermission permission : work) {
          log.debug("String_Node_Str" + permission);
          permissionService.deletePermission(nodeToUpdate,permission.getAuthority(),permission.getPermission());
        }
      }
    }
  }
}