Program: 50769
Project: 50769
Buggy source:
/** 
 * This method processes the supplied activity unit to create a set of trace nodes.
 * @param state The state
 * @param startau The activity unit being processed
 * @param toplevel The top level activity units
 */
protected static void processAU(CTState state,ActivityUnit startau,java.util.List<ActivityUnit> topLevel){
  ActivityType cur=null;
  Call call=(state.getCallStack().size() > 0 ? state.getCallStack().peek() : null);
  java.util.List<TraceNode> tasks=state.getTasksStack().peek();
  ActivityType prev=null;
  if (LOG.isLoggable(Level.FINEST)) {
    LOG.finest("String_Node_Str" + startau);
  }
  java.util.List<ActivityUnit> aus=state.getActivityUnits();
  int aupos=aus.indexOf(startau);
  if (aupos == -1) {
    LOG.severe("String_Node_Str" + startau);
    return;
  }
  boolean f_end=false;
  boolean f_scopeFinalized=false;
  for (int i=aupos; !f_end && i < aus.size(); i++) {
    ActivityUnit au=aus.get(i);
    if (i != aupos && topLevel.contains(au)) {
      continue;
    }
    if (LOG.isLoggable(Level.FINEST)) {
      LOG.finest("String_Node_Str" + aus.get(i));
    }
    ActivityUnitCursor cursor=state.getCursor(au);
    while ((cur=cursor.next()) != null) {
      if (LOG.isLoggable(Level.FINEST)) {
        LOG.finest("String_Node_Str" + cur);
      }
      if (shouldPostpone(state,au,topLevel,cur)) {
        if (LOG.isLoggable(Level.FINEST)) {
          LOG.finest("String_Node_Str" + au + "String_Node_Str"+ cur);
        }
        break;
      }
      if (cur instanceof RPCActivityType) {
        if (cur instanceof RequestSent || (cur instanceof RequestReceived && call == null)) {
          call=createCall((RPCActivityType)cur);
          if (LOG.isLoggable(Level.FINEST)) {
            LOG.finest("String_Node_Str" + call);
          }
          tasks.add(call);
          tasks=call.getTasks();
          if (LOG.isLoggable(Level.FINEST)) {
            LOG.finest("String_Node_Str" + call);
            LOG.finest("String_Node_Str" + tasks);
          }
          state.getCallStack().push(call);
          state.getTasksStack().push(tasks);
          state.getTriggerActivities().put(call,(RPCActivityType)cur);
        }
        if (cur instanceof RequestSent) {
          RPCActivityType rr=state.getSOAActivity(RequestReceived.class,((RequestSent)cur).getServiceType(),((RequestSent)cur).getOperation());
          if (rr != null) {
            call.setRequestLatency(rr.getTimestamp() - cur.getTimestamp());
            ActivityUnit subAU=state.getActivityUnit(rr.getUnitId());
            if (subAU != null) {
              processAU(state,subAU,topLevel);
              call=state.getCallStack().peek();
              tasks=state.getTasksStack().peek();
            }
          }
        }
 else         if (cur instanceof RequestReceived) {
          call.setRequest(((RequestReceived)cur).getContent());
        }
 else         if (cur instanceof ResponseSent) {
          ResponseSent rs=(ResponseSent)cur;
          call.setResponse(rs.getContent());
          call.getProperties().putAll(cur.getProperties());
          RPCActivityType rr=state.getSOAActivity(ResponseReceived.class,rs.getServiceType(),rs.getOperation());
          if (rr != null) {
            call.setResponseLatency(rr.getTimestamp() - rs.getTimestamp());
          }
          if (state.getTriggerActivities().get(call) instanceof RequestReceived) {
            call.setDuration(cur.getTimestamp() - state.getTriggerActivities().get(call).getTimestamp());
          }
          if (rs.getFault() != null && rs.getFault().trim().length() > 0) {
            call.setFault(rs.getFault());
            call.setStatus(Status.Fail);
          }
          state.finalizeScope();
          f_scopeFinalized=true;
          call=(state.getCallStack().size() > 0 ? state.getCallStack().peek() : null);
          tasks=state.getTasksStack().peek();
          if (state.getCallStack().size() > 0) {
            if (LOG.isLoggable(Level.FINEST)) {
              LOG.finest("String_Node_Str");
            }
            f_end=true;
            break;
          }
        }
 else         if (cur instanceof ResponseReceived) {
          ResponseReceived rr=(ResponseReceived)cur;
          for (int j=state.getCompletedCallStack().size() - 1; j >= 0; j--) {
            Call c=state.getCompletedCallStack().get(j);
            if (state.getTriggerActivities().get(c) instanceof RequestSent) {
              RequestSent rs=(RequestSent)state.getTriggerActivities().get(c);
              if (rs.getOperation().equals(rr.getOperation()) && rs.getServiceType().equals(rr.getServiceType())) {
                c.setDuration(rr.getTimestamp() - rs.getTimestamp());
                break;
              }
            }
          }
          f_end=true;
        }
      }
 else {
        Task task=createTask(cur);
        tasks.add(task);
        if (prev != null) {
          task.setDuration(cur.getTimestamp() - prev.getTimestamp());
        }
      }
      prev=cur;
    }
  }
  if (!f_scopeFinalized) {
    state.finalizeScope();
  }
  if (LOG.isLoggable(Level.FINEST)) {
    LOG.finest("String_Node_Str" + startau);
  }
}

Fixed version (ground truth):
/** 
 * This method processes the supplied activity unit to create a set of trace nodes.
 * @param state The state
 * @param startau The activity unit being processed
 * @param topLevel The top level activity units
 */
protected static void processAU(CTState state,ActivityUnit startau,java.util.List<ActivityUnit> topLevel){
  ActivityType cur=null;
  Call call=(state.getCallStack().size() > 0 ? state.getCallStack().peek() : null);
  java.util.List<TraceNode> tasks=state.getTasksStack().peek();
  ActivityType prev=null;
  if (LOG.isLoggable(Level.FINEST)) {
    LOG.finest("String_Node_Str" + startau);
  }
  java.util.List<ActivityUnit> aus=state.getActivityUnits();
  int aupos=aus.indexOf(startau);
  if (aupos == -1) {
    LOG.severe("String_Node_Str" + startau);
    return;
  }
  boolean f_end=false;
  boolean f_scopeFinalized=false;
  for (int i=aupos; !f_end && i < aus.size(); i++) {
    ActivityUnit au=aus.get(i);
    if (i != aupos && topLevel.contains(au)) {
      continue;
    }
    if (LOG.isLoggable(Level.FINEST)) {
      LOG.finest("String_Node_Str" + aus.get(i));
    }
    ActivityUnitCursor cursor=state.getCursor(au);
    while ((cur=cursor.next()) != null) {
      if (LOG.isLoggable(Level.FINEST)) {
        LOG.finest("String_Node_Str" + cur);
      }
      if (shouldPostpone(state,au,topLevel,cur)) {
        break;
      }
      if (cur instanceof RPCActivityType) {
        if (cur instanceof RequestSent || (cur instanceof RequestReceived && call == null)) {
          call=createCall((RPCActivityType)cur);
          tasks.add(call);
          tasks=call.getTasks();
          if (LOG.isLoggable(Level.FINEST)) {
            LOG.finest("String_Node_Str" + call);
            LOG.finest("String_Node_Str" + tasks);
          }
          state.getCallStack().push(call);
          state.getTasksStack().push(tasks);
          state.getTriggerActivities().put(call,(RPCActivityType)cur);
        }
        if (cur instanceof RequestSent) {
          RPCActivityType rr=state.getSOAActivity(RequestReceived.class,((RequestSent)cur).getServiceType(),((RequestSent)cur).getOperation());
          if (rr != null) {
            call.setRequestLatency(rr.getTimestamp() - cur.getTimestamp());
            ActivityUnit subAU=state.getActivityUnit(rr.getUnitId());
            if (subAU != null) {
              processAU(state,subAU,topLevel);
              call=state.getCallStack().peek();
              tasks=state.getTasksStack().peek();
            }
          }
        }
 else         if (cur instanceof RequestReceived) {
          call.setRequest(((RequestReceived)cur).getContent());
        }
 else         if (cur instanceof ResponseSent) {
          initializeResponseSent(state,(ResponseSent)cur,call);
          state.finalizeScope();
          f_scopeFinalized=true;
          call=(state.getCallStack().size() > 0 ? state.getCallStack().peek() : null);
          tasks=state.getTasksStack().peek();
          if (state.getCallStack().size() > 0) {
            if (LOG.isLoggable(Level.FINEST)) {
              LOG.finest("String_Node_Str");
            }
            f_end=true;
            break;
          }
        }
 else         if (cur instanceof ResponseReceived) {
          initializeResponseReceived(state,(ResponseReceived)cur);
          f_end=true;
        }
      }
 else {
        Task task=createTask(cur);
        tasks.add(task);
        if (prev != null) {
          task.setDuration(cur.getTimestamp() - prev.getTimestamp());
        }
      }
      prev=cur;
    }
  }
  if (!f_scopeFinalized) {
    state.finalizeScope();
  }
  if (LOG.isLoggable(Level.FINEST)) {
    LOG.finest("String_Node_Str" + startau);
  }
}