Program: 79432
Project: 79432
Buggy source:
/** 
 * stops all tasks (apart from any current one or its descendants) on this entity, optionally -- if a timeout is given -- waiting for completion and warning on incomplete tasks 
 */
@Beta public void stopTasks(Entity entity,@Nullable Duration timeout){
  CountdownTimer timeleft=timeout == null ? null : timeout.countdownTimer();
  Collection<Exception> exceptions=MutableSet.of();
  try {
    Set<Task<?>> tasksCancelled=MutableSet.of();
    for (    Task<?> t : managementContext.getExecutionContext(entity).getTasks()) {
      if (hasTaskAsAncestor(t,Tasks.current()))       continue;
      if (!t.isDone()) {
        try {
          log.debug("String_Node_Str" + t + "String_Node_Str"+ entity);
          tasksCancelled.add(t);
          t.cancel(true);
        }
 catch (        Exception e) {
          Exceptions.propagateIfFatal(e);
          log.debug("String_Node_Str" + t + "String_Node_Str"+ entity+ "String_Node_Str"+ e,e);
          exceptions.add(e);
        }
      }
    }
    if (timeleft != null) {
      Set<Task<?>> tasksIncomplete=MutableSet.of();
      for (      Task<?> t : managementContext.getExecutionContext(entity).getTasks()) {
        if (hasTaskAsAncestor(t,Tasks.current()))         continue;
        if (!Tasks.blockUntilInternalTasksEnded(t,timeleft.getDurationRemaining())) {
          tasksIncomplete.add(t);
        }
      }
      if (!tasksIncomplete.isEmpty()) {
        log.warn("String_Node_Str" + entity + "String_Node_Str"+ tasksIncomplete);
      }
      if (log.isTraceEnabled())       log.trace("String_Node_Str" + tasksCancelled + "String_Node_Str"+ entity+ "String_Node_Str"+ timeleft.getDurationRemaining()+ "String_Node_Str"+ timeout+ "String_Node_Str"+ tasksCancelled);
    }
 else {
      if (log.isTraceEnabled())       log.trace("String_Node_Str" + tasksCancelled + "String_Node_Str"+ entity+ "String_Node_Str"+ tasksCancelled);
    }
  }
 catch (  Exception e) {
    Exceptions.propagateIfFatal(e);
    log.warn("String_Node_Str" + e,e);
  }
  if (!exceptions.isEmpty())   log.warn("String_Node_Str" + entity + "String_Node_Str"+ Exceptions.create(exceptions));
}

Fixed version (ground truth):
/** 
 * stops all tasks (apart from any current one or its descendants) on this entity, optionally -- if a timeout is given -- waiting for completion and warning on incomplete tasks 
 */
@Beta public void stopTasks(Entity entity,@Nullable Duration timeout){
  CountdownTimer timeleft=timeout == null ? null : timeout.countdownTimer();
  Collection<Exception> exceptions=MutableSet.of();
  try {
    Set<Task<?>> tasksCancelled=MutableSet.of();
    for (    Task<?> t : managementContext.getExecutionContext(entity).getTasks()) {
      if (entity.equals(BrooklynTaskTags.getContextEntity(Tasks.current())) && hasTaskAsAncestor(t,Tasks.current())) {
        continue;
      }
      if (!t.isDone()) {
        try {
          log.debug("String_Node_Str" + t + "String_Node_Str"+ entity);
          tasksCancelled.add(t);
          t.cancel(true);
        }
 catch (        Exception e) {
          Exceptions.propagateIfFatal(e);
          log.debug("String_Node_Str" + t + "String_Node_Str"+ entity+ "String_Node_Str"+ e,e);
          exceptions.add(e);
        }
      }
    }
    if (timeleft != null) {
      Set<Task<?>> tasksIncomplete=MutableSet.of();
      for (      Task<?> t : managementContext.getExecutionContext(entity).getTasks()) {
        if (hasTaskAsAncestor(t,Tasks.current()))         continue;
        if (!Tasks.blockUntilInternalTasksEnded(t,timeleft.getDurationRemaining())) {
          tasksIncomplete.add(t);
        }
      }
      if (!tasksIncomplete.isEmpty()) {
        log.warn("String_Node_Str" + entity + "String_Node_Str"+ tasksIncomplete);
      }
      if (log.isTraceEnabled())       log.trace("String_Node_Str" + tasksCancelled + "String_Node_Str"+ entity+ "String_Node_Str"+ timeleft.getDurationRemaining()+ "String_Node_Str"+ timeout+ "String_Node_Str"+ tasksCancelled);
    }
 else {
      if (log.isTraceEnabled())       log.trace("String_Node_Str" + tasksCancelled + "String_Node_Str"+ entity+ "String_Node_Str"+ tasksCancelled);
    }
  }
 catch (  Exception e) {
    Exceptions.propagateIfFatal(e);
    log.warn("String_Node_Str" + e,e);
  }
  if (!exceptions.isEmpty())   log.warn("String_Node_Str" + entity + "String_Node_Str"+ Exceptions.create(exceptions));
}