Program: 5935
Project: 5935
Buggy source:
@Override public void process(ApplicationDeployable appSpec) throws Exception {
  List<ProgramSpecification> deletedSpecs=store.getDeletedProgramSpecifications(appSpec.getApplicationId().toId(),appSpec.getSpecification());
  List<String> deletedFlows=Lists.newArrayList();
  for (  ProgramSpecification spec : deletedSpecs) {
    ProgramType type=ProgramTypes.fromSpecification(spec);
    final Id.Program programId=appSpec.getApplicationId().program(type,spec.getName()).toId();
    programTerminator.stop(programId);
    authorizer.revoke(programId.toEntityId());
    if (ProgramType.FLOW.equals(type)) {
      FlowSpecification flowSpecification=(FlowSpecification)spec;
      final Multimap<String,Long> streamGroups=HashMultimap.create();
      for (      FlowletConnection connection : flowSpecification.getConnections()) {
        if (connection.getSourceType() == FlowletConnection.Type.STREAM) {
          long groupId=FlowUtils.generateConsumerGroupId(programId,connection.getTargetName());
          streamGroups.put(connection.getSourceName(),groupId);
        }
      }
      final String namespace=String.format("String_Node_Str",programId.getApplicationId(),programId.getId());
      final NamespaceId namespaceId=appSpec.getApplicationId().getParent();
      impersonator.doAs(namespaceId,new Callable<Void>(){
        @Override public Void call() throws Exception {
          for (          Map.Entry<String,Collection<Long>> entry : streamGroups.asMap().entrySet()) {
            streamConsumerFactory.dropAll(namespaceId.stream(entry.getKey()).toId(),namespace,entry.getValue());
          }
          queueAdmin.dropAllForFlow(Id.Flow.from(programId.getApplication(),programId.getId()));
          return null;
        }
      }
);
      deletedFlows.add(programId.getId());
    }
    metadataStore.removeMetadata(programId);
  }
  if (!deletedFlows.isEmpty()) {
    deleteMetrics(appSpec.getApplicationId(),deletedFlows);
  }
  emit(appSpec);
}

Fixed version (ground truth):
@Override public void process(ApplicationDeployable appSpec) throws Exception {
  List<ProgramSpecification> deletedSpecs=store.getDeletedProgramSpecifications(appSpec.getApplicationId().toId(),appSpec.getSpecification());
  List<String> deletedFlows=Lists.newArrayList();
  for (  ProgramSpecification spec : deletedSpecs) {
    ProgramType type=ProgramTypes.fromSpecification(spec);
    final Id.Program programId=appSpec.getApplicationId().program(type,spec.getName()).toId();
    programTerminator.stop(programId);
    privilegesManager.revoke(programId.toEntityId());
    if (ProgramType.FLOW.equals(type)) {
      FlowSpecification flowSpecification=(FlowSpecification)spec;
      final Multimap<String,Long> streamGroups=HashMultimap.create();
      for (      FlowletConnection connection : flowSpecification.getConnections()) {
        if (connection.getSourceType() == FlowletConnection.Type.STREAM) {
          long groupId=FlowUtils.generateConsumerGroupId(programId,connection.getTargetName());
          streamGroups.put(connection.getSourceName(),groupId);
        }
      }
      final String namespace=String.format("String_Node_Str",programId.getApplicationId(),programId.getId());
      final NamespaceId namespaceId=appSpec.getApplicationId().getParent();
      impersonator.doAs(namespaceId,new Callable<Void>(){
        @Override public Void call() throws Exception {
          for (          Map.Entry<String,Collection<Long>> entry : streamGroups.asMap().entrySet()) {
            streamConsumerFactory.dropAll(namespaceId.stream(entry.getKey()).toId(),namespace,entry.getValue());
          }
          queueAdmin.dropAllForFlow(Id.Flow.from(programId.getApplication(),programId.getId()));
          return null;
        }
      }
);
      deletedFlows.add(programId.getId());
    }
    metadataStore.removeMetadata(programId);
  }
  if (!deletedFlows.isEmpty()) {
    deleteMetrics(appSpec.getApplicationId(),deletedFlows);
  }
  emit(appSpec);
}