Program: 8159
Project: 8159
Buggy source:
/** 
 * FIXME: This was done in hurry and can be written in a much better way.
 * @param accountId
 * @return
 */
@Override public List<FlowState> getFlows(String accountId){
  Map<String,Integer> started=Maps.newHashMap();
  Map<String,Integer> stopped=Maps.newHashMap();
  Map<String,Integer> runs=Maps.newHashMap();
  Map<String,Integer> deployed=Maps.newHashMap();
  Map<String,Integer> states=Maps.newHashMap();
  List<FlowState> result=Lists.newArrayList();
  String sql="String_Node_Str" + "String_Node_Str";
  try {
    PreparedStatement stmt=connection.prepareStatement(sql);
    stmt.setString(1,accountId);
    ResultSet rs=stmt.executeQuery();
    while (rs.next()) {
      String app=rs.getString("String_Node_Str");
      String flow=rs.getString("String_Node_Str");
      String appFlow=String.format("String_Node_Str",app,flow);
      Integer timestamp=rs.getInt("String_Node_Str");
      int state=rs.getInt("String_Node_Str");
      if (!deployed.containsKey(appFlow)) {
        deployed.put(appFlow,1);
        FlowState status=new FlowState();
        status.setApplicationId(rs.getString("String_Node_Str"));
        status.setFlowId(rs.getString("String_Node_Str"));
        status.setCurrentState(StateChangeType.DEPLOYED.name());
        status.setLastStarted(-1);
        status.setLastStopped(-1);
        status.setRuns(0);
        result.add(status);
      }
      if (state == StateChangeType.STARTING.getType() || state == StateChangeType.STARTED.getType()) {
        started.put(appFlow,timestamp);
      }
 else       if (state == StateChangeType.STOPPING.getType() || state == StateChangeType.STOPPED.getType() || state == StateChangeType.FAILED.getType()) {
        stopped.put(appFlow,timestamp);
        if (runs.containsKey(flow)) {
          int run=runs.get(flow).intValue();
          runs.put(appFlow,run + 1);
        }
 else {
          runs.put(appFlow,1);
        }
      }
      states.put(appFlow,state);
    }
  }
 catch (  SQLException e) {
    Log.error("String_Node_Str",accountId,e.getMessage());
  }
  for (  FlowState state : result) {
    String flow=state.getFlowId();
    String app=state.getApplicationId();
    String appFlow=String.format("String_Node_Str",app,flow);
    if (started.containsKey(appFlow)) {
      state.setLastStarted(started.get(appFlow));
    }
    if (stopped.containsKey(appFlow)) {
      state.setLastStopped(stopped.get(appFlow));
    }
    if (runs.containsKey(appFlow)) {
      state.setRuns(runs.get(appFlow));
    }
    if (states.containsKey(appFlow)) {
      int i=states.get(appFlow);
      state.setCurrentState(StateChangeType.value(i).name());
    }
  }
  return result;
}

Fixed version (ground truth):
/** 
 * FIXME: This was done in hurry and can be written in a much better way.
 * @param accountId
 * @return
 */
@Override public List<FlowState> getFlows(String accountId){
  Map<String,Integer> started=Maps.newHashMap();
  Map<String,Integer> stopped=Maps.newHashMap();
  Map<String,Integer> runs=Maps.newHashMap();
  Map<String,Integer> deployed=Maps.newHashMap();
  Map<String,Integer> states=Maps.newHashMap();
  List<FlowState> result=Lists.newArrayList();
  String sql="String_Node_Str" + "String_Node_Str";
  try {
    PreparedStatement stmt=connection.prepareStatement(sql);
    stmt.setString(1,accountId);
    ResultSet rs=stmt.executeQuery();
    while (rs.next()) {
      String app=rs.getString("String_Node_Str");
      String flow=rs.getString("String_Node_Str");
      String appFlow=String.format("String_Node_Str",app,flow);
      Integer timestamp=rs.getInt("String_Node_Str");
      int state=rs.getInt("String_Node_Str");
      if (!deployed.containsKey(appFlow)) {
        deployed.put(appFlow,1);
        FlowState status=new FlowState();
        status.setApplicationId(rs.getString("String_Node_Str"));
        status.setFlowId(rs.getString("String_Node_Str"));
        status.setCurrentState(StateChangeType.DEPLOYED.name());
        status.setLastStarted(-1);
        status.setLastStopped(-1);
        status.setRuns(0);
        result.add(status);
      }
      if (state == StateChangeType.STARTING.getType() || state == StateChangeType.RUNNING.getType()) {
        started.put(appFlow,timestamp);
      }
 else       if (state == StateChangeType.STOPPING.getType() || state == StateChangeType.STOPPED.getType() || state == StateChangeType.FAILED.getType()) {
        stopped.put(appFlow,timestamp);
        if (runs.containsKey(flow)) {
          int run=runs.get(flow).intValue();
          runs.put(appFlow,run + 1);
        }
 else {
          runs.put(appFlow,1);
        }
      }
      states.put(appFlow,state);
    }
  }
 catch (  SQLException e) {
    Log.error("String_Node_Str",accountId,e.getMessage());
  }
  for (  FlowState state : result) {
    String flow=state.getFlowId();
    String app=state.getApplicationId();
    String appFlow=String.format("String_Node_Str",app,flow);
    if (started.containsKey(appFlow)) {
      state.setLastStarted(started.get(appFlow));
    }
    if (stopped.containsKey(appFlow)) {
      state.setLastStopped(stopped.get(appFlow));
    }
    if (runs.containsKey(appFlow)) {
      state.setRuns(runs.get(appFlow));
    }
    if (states.containsKey(appFlow)) {
      int i=states.get(appFlow);
      state.setCurrentState(StateChangeType.value(i).name());
    }
  }
  return result;
}