Program: 6944
Project: 6944
Buggy source:
/** 
 * Helper method to get   {@link co.cask.cdap.proto.Id.Program} for a RunRecord for type of program
 * @param programType Type of program to search
 * @param runId The target id of the {@link RunRecord} to find
 * @return the program id of the run record or {@code null} if does not exist.
 */
@Nullable private Id.Program retrieveProgramIdForRunRecord(ProgramType programType,String runId){
  List<NamespaceMeta> namespaceMetas=store.listNamespaces();
  Id.Program targetProgramId=null;
  for (  NamespaceMeta nm : namespaceMetas) {
    Id.Namespace accId=Id.Namespace.from(nm.getName());
    Collection<ApplicationSpecification> appSpecs=store.getAllApplications(accId);
    for (    ApplicationSpecification appSpec : appSpecs) {
switch (programType) {
case FLOW:
        for (        String programName : appSpec.getFlows().keySet()) {
          Id.Program programId=validateProgramForRunRecord(store,nm.getName(),appSpec.getName(),programType,programName,runId);
          if (programId != null) {
            targetProgramId=programId;
            break;
          }
        }
      break;
case MAPREDUCE:
    for (    String programName : appSpec.getMapReduce().keySet()) {
      Id.Program programId=validateProgramForRunRecord(store,nm.getName(),appSpec.getName(),programType,programName,runId);
      if (programId != null) {
        targetProgramId=programId;
        break;
      }
    }
  break;
case SPARK:
for (String programName : appSpec.getSpark().keySet()) {
  Id.Program programId=validateProgramForRunRecord(store,nm.getName(),appSpec.getName(),programType,programName,runId);
  if (programId != null) {
    targetProgramId=programId;
    break;
  }
}
break;
case SERVICE:
for (String programName : appSpec.getServices().keySet()) {
Id.Program programId=validateProgramForRunRecord(store,nm.getName(),appSpec.getName(),programType,programName,runId);
if (programId != null) {
targetProgramId=programId;
break;
}
}
break;
case WORKER:
for (String programName : appSpec.getWorkers().keySet()) {
Id.Program programId=validateProgramForRunRecord(store,nm.getName(),appSpec.getName(),programType,programName,runId);
if (programId != null) {
targetProgramId=programId;
break;
}
}
break;
case WORKFLOW:
for (String programName : appSpec.getWorkflows().keySet()) {
Id.Program programId=validateProgramForRunRecord(store,nm.getName(),appSpec.getName(),programType,programName,runId);
if (programId != null) {
targetProgramId=programId;
break;
}
}
break;
default :
LOG.debug("String_Node_Str" + programType.name());
break;
}
if (targetProgramId != null) {
break;
}
}
if (targetProgramId != null) {
break;
}
}
return targetProgramId;
}

Fixed version (ground truth):
/** 
 * Helper method to get   {@link co.cask.cdap.proto.Id.Program} for a RunRecord for type of program
 * @param programType Type of program to search
 * @param runId The target id of the {@link RunRecord} to find
 * @return the program id of the run record or {@code null} if does not exist.
 */
@Nullable private Id.Program retrieveProgramIdForRunRecord(ProgramType programType,String runId){
  List<NamespaceMeta> namespaceMetas=store.listNamespaces();
  Id.Program targetProgramId=null;
  for (  NamespaceMeta nm : namespaceMetas) {
    Id.Namespace accId=Id.Namespace.from(nm.getName());
    Collection<ApplicationSpecification> appSpecs=store.getAllApplications(accId);
    for (    ApplicationSpecification appSpec : appSpecs) {
switch (programType) {
case FLOW:
        for (        String programName : appSpec.getFlows().keySet()) {
          Id.Program programId=validateProgramForRunRecord(nm.getName(),appSpec.getName(),programType,programName,runId);
          if (programId != null) {
            targetProgramId=programId;
            break;
          }
        }
      break;
case MAPREDUCE:
    for (    String programName : appSpec.getMapReduce().keySet()) {
      Id.Program programId=validateProgramForRunRecord(nm.getName(),appSpec.getName(),programType,programName,runId);
      if (programId != null) {
        targetProgramId=programId;
        break;
      }
    }
  break;
case SPARK:
for (String programName : appSpec.getSpark().keySet()) {
  Id.Program programId=validateProgramForRunRecord(nm.getName(),appSpec.getName(),programType,programName,runId);
  if (programId != null) {
    targetProgramId=programId;
    break;
  }
}
break;
case SERVICE:
for (String programName : appSpec.getServices().keySet()) {
Id.Program programId=validateProgramForRunRecord(nm.getName(),appSpec.getName(),programType,programName,runId);
if (programId != null) {
targetProgramId=programId;
break;
}
}
break;
case WORKER:
for (String programName : appSpec.getWorkers().keySet()) {
Id.Program programId=validateProgramForRunRecord(nm.getName(),appSpec.getName(),programType,programName,runId);
if (programId != null) {
targetProgramId=programId;
break;
}
}
break;
case WORKFLOW:
for (String programName : appSpec.getWorkflows().keySet()) {
Id.Program programId=validateProgramForRunRecord(nm.getName(),appSpec.getName(),programType,programName,runId);
if (programId != null) {
targetProgramId=programId;
break;
}
}
break;
default :
LOG.debug("String_Node_Str" + programType.name());
break;
}
if (targetProgramId != null) {
break;
}
}
if (targetProgramId != null) {
break;
}
}
return targetProgramId;
}