Program: 7047
Project: 7047
Buggy source:
/** 
 * Delete an application specified by appId.
 * @param appId the {@link Id.Application} of the application to be removed
 * @throws Exception
 */
public void removeApplication(final Id.Application appId) throws Exception {
  boolean appRunning=runtimeService.checkAnyRunning(new Predicate<Id.Program>(){
    @Override public boolean apply(    Id.Program programId){
      return programId.getApplication().equals(appId);
    }
  }
,ProgramType.values());
  if (appRunning) {
    throw new CannotBeDeletedException(appId);
  }
  ApplicationSpecification spec=store.getApplication(appId);
  if (spec == null) {
    throw new NotFoundException(appId);
  }
  for (  WorkflowSpecification workflowSpec : spec.getWorkflows().values()) {
    Id.Program workflowProgramId=Id.Program.from(appId,ProgramType.WORKFLOW,workflowSpec.getName());
    scheduler.deleteSchedules(workflowProgramId,SchedulableProgramType.WORKFLOW);
  }
  deleteMetrics(appId.getNamespaceId(),appId.getId());
  deletePreferences(appId);
  for (  FlowSpecification flowSpecification : spec.getFlows().values()) {
    Id.Program flowProgramId=Id.Program.from(appId,ProgramType.FLOW,flowSpecification.getName());
    Multimap<String,Long> streamGroups=HashMultimap.create();
    for (    FlowletConnection connection : flowSpecification.getConnections()) {
      if (connection.getSourceType() == FlowletConnection.Type.STREAM) {
        long groupId=FlowUtils.generateConsumerGroupId(flowProgramId,connection.getTargetName());
        streamGroups.put(connection.getSourceName(),groupId);
      }
    }
    String namespace=String.format("String_Node_Str",flowProgramId.getApplicationId(),flowProgramId.getId());
    for (    Map.Entry<String,Collection<Long>> entry : streamGroups.asMap().entrySet()) {
      streamConsumerFactory.dropAll(Id.Stream.from(appId.getNamespaceId(),entry.getKey()),namespace,entry.getValue());
    }
    queueAdmin.dropAllForFlow(appId.getNamespaceId(),appId.getId(),flowSpecification.getName());
  }
  deleteProgramLocations(appId);
  Location appArchive=store.getApplicationArchiveLocation(appId);
  Preconditions.checkNotNull(appArchive,"String_Node_Str",appId.getId());
  appArchive.delete();
  store.removeApplication(appId);
  try {
    usageRegistry.unregister(appId);
  }
 catch (  Exception e) {
    LOG.warn("String_Node_Str",appId,e);
  }
}

Fixed version (ground truth):
/** 
 * Delete an application specified by appId.
 * @param appId the {@link Id.Application} of the application to be removed
 * @throws Exception
 */
public void removeApplication(final Id.Application appId) throws Exception {
  boolean appRunning=runtimeService.checkAnyRunning(new Predicate<Id.Program>(){
    @Override public boolean apply(    Id.Program programId){
      return programId.getApplication().equals(appId);
    }
  }
,ProgramType.values());
  if (appRunning) {
    throw new CannotBeDeletedException(appId);
  }
  ApplicationSpecification spec=store.getApplication(appId);
  if (spec == null) {
    throw new NotFoundException(appId);
  }
  for (  WorkflowSpecification workflowSpec : spec.getWorkflows().values()) {
    Id.Program workflowProgramId=Id.Program.from(appId,ProgramType.WORKFLOW,workflowSpec.getName());
    scheduler.deleteSchedules(workflowProgramId,SchedulableProgramType.WORKFLOW);
  }
  deleteMetrics(appId.getNamespaceId(),appId.getId());
  deletePreferences(appId);
  for (  FlowSpecification flowSpecification : spec.getFlows().values()) {
    Id.Program flowProgramId=Id.Program.from(appId,ProgramType.FLOW,flowSpecification.getName());
    Multimap<String,Long> streamGroups=HashMultimap.create();
    for (    FlowletConnection connection : flowSpecification.getConnections()) {
      if (connection.getSourceType() == FlowletConnection.Type.STREAM) {
        long groupId=FlowUtils.generateConsumerGroupId(flowProgramId,connection.getTargetName());
        streamGroups.put(connection.getSourceName(),groupId);
      }
    }
    String namespace=String.format("String_Node_Str",flowProgramId.getApplicationId(),flowProgramId.getId());
    for (    Map.Entry<String,Collection<Long>> entry : streamGroups.asMap().entrySet()) {
      streamConsumerFactory.dropAll(Id.Stream.from(appId.getNamespaceId(),entry.getKey()),namespace,entry.getValue());
    }
    queueAdmin.dropAllForFlow(appId.getNamespaceId(),appId.getId(),flowSpecification.getName());
  }
  deleteProgramLocations(appId);
  Location appArchive=store.getApplicationArchiveLocation(appId);
  Preconditions.checkNotNull(appArchive,"String_Node_Str",appId.getId());
  if (!appArchive.delete()) {
    LOG.debug("String_Node_Str");
  }
  store.removeApplication(appId);
  try {
    usageRegistry.unregister(appId);
  }
 catch (  Exception e) {
    LOG.warn("String_Node_Str",appId,e);
  }
}