Program: 8158
Project: 8158
Buggy source:
/** 
 * FIXME : I am probably most duplicate of getFlows - Refactor me.
 * @param accountId for which the flows belong to.
 * @param appId  to which the flows belong to.
 * @param flowId is the id of the flow runs to be returned.
 * @return
 */
@Override public List<FlowRun> getFlowHistory(String accountId,String appId,String flowId){
  Map<String,Integer> started=Maps.newHashMap();
  Map<String,Integer> stopped=Maps.newHashMap();
  Map<String,Integer> states=Maps.newHashMap();
  String sql="String_Node_Str" + "String_Node_Str";
  List<FlowRun> runs=Lists.newArrayList();
  try {
    PreparedStatement stmt=connection.prepareStatement(sql);
    stmt.setString(1,accountId);
    stmt.setString(2,appId);
    stmt.setString(3,flowId);
    ResultSet rs=stmt.executeQuery();
    while (rs.next()) {
      String rid=rs.getString("String_Node_Str");
      if (rid == null) {
        continue;
      }
      int state=rs.getInt("String_Node_Str");
      int timestamp=rs.getInt("String_Node_Str");
      if (!started.containsKey(rid)) {
        FlowRun run=new FlowRun();
        run.setStartTime(-1);
        run.setEndTime(-1);
        run.setRunId(rid);
        run.setEndStatus("String_Node_Str");
        runs.add(run);
      }
      if (state == StateChangeType.STARTING.getType() || state == StateChangeType.STARTED.getType()) {
        started.put(rid,timestamp);
      }
      if (state == StateChangeType.STOPPING.getType() || state == StateChangeType.STOPPED.getType() || state == StateChangeType.FAILED.getType()) {
        stopped.put(rid,timestamp);
      }
      states.put(rid,state);
    }
    for (    FlowRun run : runs) {
      String runId=run.getRunId();
      if (started.containsKey(runId)) {
        run.setStartTime(started.get(runId));
      }
      if (stopped.containsKey(runId)) {
        run.setEndTime(stopped.get(runId));
      }
      if (states.containsKey(runId)) {
        run.setEndStatus(StateChangeType.value(states.get(runId)).name());
      }
    }
  }
 catch (  SQLException e) {
    Log.error("String_Node_Str",new Object[]{accountId,appId,flowId,e.getMessage()});
  }
  return runs;
}

Fixed version (ground truth):
/** 
 * FIXME : I am probably most duplicate of getFlows - Refactor me.
 * @param accountId for which the flows belong to.
 * @param appId  to which the flows belong to.
 * @param flowId is the id of the flow runs to be returned.
 * @return
 */
@Override public List<FlowRun> getFlowHistory(String accountId,String appId,String flowId){
  Map<String,Integer> started=Maps.newHashMap();
  Map<String,Integer> stopped=Maps.newHashMap();
  Map<String,Integer> states=Maps.newHashMap();
  String sql="String_Node_Str" + "String_Node_Str";
  List<FlowRun> runs=Lists.newArrayList();
  try {
    PreparedStatement stmt=connection.prepareStatement(sql);
    stmt.setString(1,accountId);
    stmt.setString(2,appId);
    stmt.setString(3,flowId);
    ResultSet rs=stmt.executeQuery();
    while (rs.next()) {
      String rid=rs.getString("String_Node_Str");
      if (rid == null) {
        continue;
      }
      int state=rs.getInt("String_Node_Str");
      if (state == StateChangeType.DEPLOYED.getType()) {
        continue;
      }
      int timestamp=rs.getInt("String_Node_Str");
      if (!started.containsKey(rid)) {
        FlowRun run=new FlowRun();
        run.setStartTime(-1);
        run.setEndTime(-1);
        run.setRunId(rid);
        run.setEndStatus("String_Node_Str");
        runs.add(run);
      }
      if (state == StateChangeType.STARTING.getType() || state == StateChangeType.RUNNING.getType()) {
        started.put(rid,timestamp);
      }
      if (state == StateChangeType.STOPPING.getType() || state == StateChangeType.STOPPED.getType() || state == StateChangeType.FAILED.getType()) {
        stopped.put(rid,timestamp);
      }
      states.put(rid,state);
    }
    for (    FlowRun run : runs) {
      String runId=run.getRunId();
      if (started.containsKey(runId)) {
        run.setStartTime(started.get(runId));
      }
      if (stopped.containsKey(runId)) {
        run.setEndTime(stopped.get(runId));
      }
      if (states.containsKey(runId)) {
        run.setEndStatus(StateChangeType.value(states.get(runId)).name());
      }
    }
  }
 catch (  SQLException e) {
    Log.error("String_Node_Str",new Object[]{accountId,appId,flowId,e.getMessage()});
  }
  return runs;
}