Program: 92507
Project: 92507
Buggy source:
/** 
 * Parse a scenario file with the format: <SCENARIO> ScenarioName <COMMAND_INPUT> Command </COMAND_INPUT> <COMMAND_RESULT> CommandResult </COMMAND_RESULT> <COMMAND_OUTPUT> CommandOutput </COMMAND_OUTPUT> </SCENARIO> Where: ScenarioName - is the scenario name Command - the command line string CommandResult - the result integer of the command (0 for success, 1 for failure) ComandOutput - the command output string (multi-line possible) Note: 1) There can be many scenarios per file 2) There can be many (Command-CommandResult-CommandOutput) triples per scenario 3) Lines starting with # will be ignored (comments)
 * @param scenariofile - path to scenario file
 * @throws Exception
 */
public void loadScenarioFile(String scenariofile) throws Exception {
  fScenariofile=scenariofile;
  Collection<Map<String,ICommandResult>> values=fScenarioMap.values();
  for (Iterator<Map<String,ICommandResult>> iterator=values.iterator(); iterator.hasNext(); ) {
    Map<String,ICommandResult> map=(Map<String,ICommandResult>)iterator.next();
    map.clear();
  }
  fScenarioMap.clear();
  FileInputStream fstream=new FileInputStream(fScenariofile);
  DataInputStream in=new DataInputStream(fstream);
  BufferedReader br=new BufferedReader(new InputStreamReader(in));
  String strLine;
  Map<String,Integer> tmpSessionNameMap=new HashMap<String,Integer>();
  while ((strLine=br.readLine()) != null) {
    if (isComment(strLine)) {
      continue;
    }
    if (SCENARIO_KEY.equals(strLine)) {
      strLine=br.readLine();
      while (isComment(strLine)) {
        strLine=br.readLine();
      }
      String scenario=strLine;
      Map<String,ICommandResult> commandMap=new HashMap<String,ICommandResult>();
      fScenarioMap.put(scenario,commandMap);
      List<String> output=null;
      String input=null;
      boolean inOutput=false;
      int result=0;
      tmpSessionNameMap.clear();
      while ((strLine=br.readLine()) != null) {
        if (isComment(strLine)) {
          continue;
        }
        if (SCENARIO_END_KEY.equals(strLine)) {
          break;
        }
        if (INPUT_KEY.equals(strLine)) {
          strLine=br.readLine();
          while (isComment(strLine)) {
            strLine=br.readLine();
          }
          input=strLine;
          Matcher matcher=LTTNG_LIST_SESSION_PATTERN.matcher(strLine);
          if (matcher.matches() && !input.matches(LTTNG_LIST_PROVIDER_PATTERN)) {
            String sessionName=matcher.group(1).trim();
            Integer i=tmpSessionNameMap.get(sessionName);
            if (i != null) {
              i++;
            }
 else {
              i=0;
            }
            tmpSessionNameMap.put(sessionName,i);
            input+=String.valueOf(i);
          }
        }
 else         if (INPUT_END_KEY.equals(strLine)) {
          output=new ArrayList<String>();
        }
 else         if (RESULT_KEY.equals(strLine)) {
          strLine=br.readLine();
          while (isComment(strLine)) {
            strLine=br.readLine();
          }
          result=Integer.parseInt(strLine);
        }
 else         if (OUTPUT_END_KEY.equals(strLine)) {
          commandMap.put(input,new CommandResult(result,output.toArray(new String[output.size()])));
          inOutput=false;
        }
 else         if (OUTPUT_KEY.equals(strLine)) {
          inOutput=true;
          strLine=br.readLine();
          while (isComment(strLine)) {
            strLine=br.readLine();
          }
          output.add(strLine);
        }
 else         if (inOutput) {
          output.add(strLine);
        }
      }
    }
  }
  in.close();
}

Fixed version (ground truth):
/** 
 * Parse a scenario file with the format: <SCENARIO> ScenarioName <COMMAND_INPUT> Command </COMAND_INPUT> <COMMAND_RESULT> CommandResult </COMMAND_RESULT> <COMMAND_OUTPUT> CommandOutput </COMMAND_OUTPUT> </SCENARIO> Where: ScenarioName - is the scenario name Command - the command line string CommandResult - the result integer of the command (0 for success, 1 for failure) ComandOutput - the command output string (multi-line possible) Note: 1) There can be many scenarios per file 2) There can be many (Command-CommandResult-CommandOutput) triples per scenario 3) Lines starting with # will be ignored (comments)
 * @param scenariofile - path to scenario file
 * @throws Exception
 */
public synchronized void loadScenarioFile(String scenariofile) throws Exception {
  fScenariofile=scenariofile;
  Collection<Map<String,ICommandResult>> values=fScenarioMap.values();
  for (Iterator<Map<String,ICommandResult>> iterator=values.iterator(); iterator.hasNext(); ) {
    Map<String,ICommandResult> map=(Map<String,ICommandResult>)iterator.next();
    map.clear();
  }
  fScenarioMap.clear();
  FileInputStream fstream=new FileInputStream(fScenariofile);
  DataInputStream in=new DataInputStream(fstream);
  BufferedReader br=new BufferedReader(new InputStreamReader(in));
  String strLine;
  Map<String,Integer> tmpSessionNameMap=new HashMap<String,Integer>();
  while ((strLine=br.readLine()) != null) {
    if (isComment(strLine)) {
      continue;
    }
    if (SCENARIO_KEY.equals(strLine)) {
      strLine=br.readLine();
      while (isComment(strLine)) {
        strLine=br.readLine();
      }
      String scenario=strLine;
      Map<String,ICommandResult> commandMap=new HashMap<String,ICommandResult>();
      fScenarioMap.put(scenario,commandMap);
      List<String> output=null;
      String input=null;
      boolean inOutput=false;
      int result=0;
      tmpSessionNameMap.clear();
      while ((strLine=br.readLine()) != null) {
        if (isComment(strLine)) {
          continue;
        }
        if (SCENARIO_END_KEY.equals(strLine)) {
          break;
        }
        if (INPUT_KEY.equals(strLine)) {
          strLine=br.readLine();
          while (isComment(strLine)) {
            strLine=br.readLine();
          }
          input=strLine;
          Matcher matcher=LTTNG_LIST_SESSION_PATTERN.matcher(strLine);
          if (matcher.matches() && !input.matches(LTTNG_LIST_PROVIDER_PATTERN)) {
            String sessionName=matcher.group(1).trim();
            Integer i=tmpSessionNameMap.get(sessionName);
            if (i != null) {
              i++;
            }
 else {
              i=0;
            }
            tmpSessionNameMap.put(sessionName,i);
            input+=String.valueOf(i);
          }
        }
 else         if (INPUT_END_KEY.equals(strLine)) {
          output=new ArrayList<String>();
        }
 else         if (RESULT_KEY.equals(strLine)) {
          strLine=br.readLine();
          while (isComment(strLine)) {
            strLine=br.readLine();
          }
          result=Integer.parseInt(strLine);
        }
 else         if (OUTPUT_END_KEY.equals(strLine)) {
          commandMap.put(input,new CommandResult(result,output.toArray(new String[output.size()])));
          inOutput=false;
        }
 else         if (OUTPUT_KEY.equals(strLine)) {
          inOutput=true;
          strLine=br.readLine();
          while (isComment(strLine)) {
            strLine=br.readLine();
          }
          output.add(strLine);
        }
 else         if (inOutput) {
          output.add(strLine);
        }
      }
    }
  }
  in.close();
}