Program: 79441
Project: 79441
Buggy source:
private void unmanage(final Entity e,ManagementTransitionMode mode,boolean hasBeenReplaced){
  if (shouldSkipUnmanagement(e))   return;
  final ManagementTransitionInfo info=new ManagementTransitionInfo(managementContext,mode);
  if (hasBeenReplaced) {
    if (mode == ManagementTransitionMode.REBINDING_NO_LONGER_PRIMARY) {
      ((EntityInternal)e).getManagementSupport().onManagementStopping(info);
      stopTasks(e);
      ((EntityInternal)e).getManagementSupport().onManagementStopped(info);
    }
 else {
      if (!mode.wasReadOnly()) {
        log.warn("String_Node_Str" + e + "String_Node_Str"+ mode+ "String_Node_Str");
      }
    }
    return;
  }
 else   if (mode == ManagementTransitionMode.REBINDING_DESTROYED) {
    ((EntityInternal)e).getManagementSupport().onManagementStopping(info);
    unmanageNonRecursive(e);
    stopTasks(e);
    ((EntityInternal)e).getManagementSupport().onManagementStopped(info);
    managementContext.getRebindManager().getChangeListener().onUnmanaged(e);
    if (managementContext.getGarbageCollector() != null)     managementContext.getGarbageCollector().onUnmanaged(e);
  }
 else   if (mode == ManagementTransitionMode.DESTROYING) {
    final List<EntityInternal> allEntities=Lists.newArrayList();
    recursively(e,new Predicate<EntityInternal>(){
      public boolean apply(      EntityInternal it){
        if (shouldSkipUnmanagement(it))         return false;
        allEntities.add(it);
        it.getManagementSupport().onManagementStopping(info);
        return true;
      }
    }
);
    for (    EntityInternal it : allEntities) {
      if (shouldSkipUnmanagement(it))       continue;
      unmanageNonRecursive(it);
      stopTasks(it);
    }
    for (    EntityInternal it : allEntities) {
      it.getManagementSupport().onManagementStopped(info);
      managementContext.getRebindManager().getChangeListener().onUnmanaged(e);
      if (managementContext.getGarbageCollector() != null)       managementContext.getGarbageCollector().onUnmanaged(e);
    }
  }
 else {
    log.warn("String_Node_Str" + mode + "String_Node_Str"+ e+ "String_Node_Str");
  }
  preRegisteredEntitiesById.remove(e.getId());
  preManagedEntitiesById.remove(e.getId());
  entityProxiesById.remove(e.getId());
  entitiesById.remove(e.getId());
  entityModesById.remove(e.getId());
}

Fixed version (ground truth):
private void unmanage(final Entity e,ManagementTransitionMode mode,boolean hasBeenReplaced){
  if (shouldSkipUnmanagement(e))   return;
  final ManagementTransitionInfo info=new ManagementTransitionInfo(managementContext,mode);
  if (hasBeenReplaced) {
    if (mode == ManagementTransitionMode.REBINDING_NO_LONGER_PRIMARY) {
      ((EntityInternal)e).getManagementSupport().onManagementStopping(info);
      stopTasks(e);
      ((EntityInternal)e).getManagementSupport().onManagementStopped(info);
    }
 else {
      if (!mode.wasReadOnly()) {
        log.warn("String_Node_Str" + e + "String_Node_Str"+ mode+ "String_Node_Str");
      }
    }
    return;
  }
 else   if (mode == ManagementTransitionMode.REBINDING_DESTROYED) {
    ((EntityInternal)e).getManagementSupport().onManagementStopping(info);
    unmanageNonRecursive(e);
    stopTasks(e);
    ((EntityInternal)e).getManagementSupport().onManagementStopped(info);
    managementContext.getRebindManager().getChangeListener().onUnmanaged(e);
    if (managementContext.getGarbageCollector() != null)     managementContext.getGarbageCollector().onUnmanaged(e);
  }
 else   if (mode == ManagementTransitionMode.DESTROYING) {
    final List<EntityInternal> allEntities=Lists.newArrayList();
    recursively(e,new Predicate<EntityInternal>(){
      public boolean apply(      EntityInternal it){
        if (shouldSkipUnmanagement(it))         return false;
        allEntities.add(it);
        it.getManagementSupport().onManagementStopping(info);
        return true;
      }
    }
);
    for (    EntityInternal it : allEntities) {
      if (shouldSkipUnmanagement(it))       continue;
      unmanageNonRecursive(it);
      stopTasks(it);
    }
    for (    EntityInternal it : allEntities) {
      it.getManagementSupport().onManagementStopped(info);
      managementContext.getRebindManager().getChangeListener().onUnmanaged(it);
      if (managementContext.getGarbageCollector() != null)       managementContext.getGarbageCollector().onUnmanaged(e);
    }
  }
 else {
    log.warn("String_Node_Str" + mode + "String_Node_Str"+ e+ "String_Node_Str");
  }
  preRegisteredEntitiesById.remove(e.getId());
  preManagedEntitiesById.remove(e.getId());
  entityProxiesById.remove(e.getId());
  entitiesById.remove(e.getId());
  entityModesById.remove(e.getId());
}