Program: 135937
Project: 135937
Buggy source:
/** 
 * Performs processing for the error and the error trace produced after a run of the trace explorer. This method does the following to a trace: 1.) Changes the names of the variables corresponding to trace explorer expressions to the actual expressions. 2.) It also shifts the values of expressions of level 2. For an expressions of level 2 (expression with primed variables), the value in state x becomes the original value in state x+1. The value in the final state of such expressions is equal to "--". 3.) Changes the state labels "<Action ... in module TE> State (num = 3)" to the state labels of the original trace. The goal is to have no reference to module TE. 4.) Puts the variables representing the trace explorer expressions before the actual variables in each state. 5.) Removes any extra states produced by the trace explorer. This can sometimes occur when evaluating expressions for a looping ("Back to state") trace and for a stuttering trace. This can be illustrated by an example. Consider the following trace: <Initial predicate> <State num 1> x=0 <Action ...> <State num 2> x=1 <Back to state 1> The user wants to evaluate the following expression: x' >= x The toolbox uses the following as init and next: Init == /\ x=0 /\ __trace_var_213123 = "--" Next == \/ /\ x=0 /\ x'=1 /\ __trace_var_213123' = (x'>=x) \/ /\ x=1 /\ x'=0 /\ __trace_var_213123' = (x'>=x) We check the following property: prop_23432 == ~([]<>(x=1)/\[]<>(x=0)) This produces the following trace: <Initial predicate> <State num 1> x=0 __trace_var_213123 = "--" <Action ...> <State num 2> x=1 __trace_var_213123 = TRUE <Action ...> <State num 3> x=0 __trace_var_213123 = FALSE <Back to state 2> Note the additional state with x=0 and __trace_var_213123 = FALSE. We shift the values for expressions with primed variables up by one state, so this extra state is necessary for producing the value for the expression "x' >= x" in the second state of the trace (In non-looping traces, there is no value for the expression in the final state, so we simply assign it the value "--".) The processing by this method eliminates this extra state but uses the value for __trace_var_213123, so that the following trace can be displayed to the user: <Initial predicate> <State num 1> x=0 (x' >= x)    =     TRUE <Action ...> <State num 2> x=1 (x' >= x)    =    FALSE <Back to state 1> 6.) If the trace explorer ran successfully, this method replaces the error message associated with the trace produced by the trace explorer with the error message produced by the last run of model checking on the model for which the trace explorer was run.
 */
private void processTraceForTraceExplorer(){
  TLCError originalErrorWithTrace=TraceExplorerHelper.getErrorOfOriginalTrace(getConfig());
  if (originalErrorWithTrace == null) {
    getErrors().clear();
    return;
  }
  List originalTrace=originalErrorWithTrace.getStates();
  Assert.isNotNull(originalTrace,"String_Node_Str");
  Iterator it=getErrors().iterator();
  while (it.hasNext()) {
    TLCError error=(TLCError)it.next();
    if (error.hasTrace()) {
      int errorCode=error.getErrorCode();
      if (errorCode == EC.TLC_DEADLOCK_REACHED || errorCode == EC.TLC_TEMPORAL_PROPERTY_VIOLATED || errorCode == EC.TLC_INVARIANT_VIOLATED_BEHAVIOR || errorCode == EC.TLC_INVARIANT_VIOLATED_INITIAL) {
        error.setErrorCode(originalErrorWithTrace.getErrorCode());
        error.setMessage(originalErrorWithTrace.getMessage());
        error.setCause(originalErrorWithTrace.getCause());
      }
 else {
        error.setMessage(TE_ERROR_HEADER + error.getMessage());
      }
      Comparator varComparator=new Comparator(){
        public int compare(        Object arg0,        Object arg1){
          TLCVariable var0=(TLCVariable)arg0;
          TLCVariable var1=(TLCVariable)arg1;
          if ((var0.isTraceExplorerVar() && var1.isTraceExplorerVar()) || (!var0.isTraceExplorerVar() && !var1.isTraceExplorerVar())) {
            return var0.getName().compareTo(var1.getName());
          }
 else           if (var0.isTraceExplorerVar()) {
            return -1;
          }
 else {
            return 1;
          }
        }
      }
;
      List newTrace=error.getStates();
      Iterator newTraceIt=newTrace.iterator();
      Iterator originalTraceIt=originalTrace.iterator();
      TLCState currentStateNewTrace=(TLCState)newTraceIt.next();
      TLCState nextStateNewTrace=null;
      TLCState currentStateOriginalTrace=(TLCState)originalTraceIt.next();
      while (newTraceIt.hasNext() && originalTraceIt.hasNext()) {
        currentStateNewTrace.setLabel(currentStateOriginalTrace.getLabel());
        currentStateNewTrace.setLocation(currentStateOriginalTrace.getModuleLocation());
        nextStateNewTrace=(TLCState)newTraceIt.next();
        TLCVariable[] currentStateNewTraceVariables=currentStateNewTrace.getVariables();
        TLCVariable[] nextStateNewTraceVariables=nextStateNewTrace.getVariables();
        for (int i=0; i < currentStateNewTraceVariables.length; i++) {
          String variableName=currentStateNewTraceVariables[i].getName();
          if (!nextStateNewTrace.isBackToState() && !nextStateNewTrace.isStuttering()) {
            Assert.isTrue(variableName.equals(nextStateNewTraceVariables[i].getName()),"String_Node_Str");
          }
          TraceExpressionInformationHolder traceExpressionData=(TraceExpressionInformationHolder)traceExpressionDataTable.get(variableName.trim());
          if (traceExpressionData != null) {
            if (!nextStateNewTrace.isBackToState() && !nextStateNewTrace.isStuttering() && traceExpressionData.getLevel() == 2) {
              currentStateNewTraceVariables[i].setValue(nextStateNewTraceVariables[i].getValue());
            }
            currentStateNewTraceVariables[i].setName(traceExpressionData.getExpression());
            currentStateNewTraceVariables[i].setTraceExplorerVar(true);
          }
        }
        Arrays.sort(currentStateNewTraceVariables,varComparator);
        currentStateNewTrace=nextStateNewTrace;
        currentStateOriginalTrace=(TLCState)originalTraceIt.next();
      }
      if ((currentStateOriginalTrace.isBackToState() || currentStateOriginalTrace.isStuttering()) && newTrace.size() >= originalTrace.size()) {
        newTrace.subList(originalTrace.size() - 1,newTrace.size()).clear();
      }
      Assert.isTrue(newTrace.size() <= originalTrace.size(),"String_Node_Str");
      TLCState finalStateOriginalTrace=(TLCState)originalTrace.get(originalTrace.size() - 1);
      if (newTrace.size() < originalTrace.size() - 1 || (!finalStateOriginalTrace.isStuttering() && !finalStateOriginalTrace.isBackToState())) {
        TLCState finalStateNewTrace=(TLCState)newTrace.get(newTrace.size() - 1);
        TLCState samePositionOriginalTrace=(TLCState)originalTrace.get(newTrace.size() - 1);
        finalStateNewTrace.setLabel(samePositionOriginalTrace.getLabel());
        finalStateNewTrace.setLocation(samePositionOriginalTrace.getModuleLocation());
        TLCVariable[] finalStateNewTraceVariables=finalStateNewTrace.getVariables();
        for (int i=0; i < finalStateNewTraceVariables.length; i++) {
          TraceExpressionInformationHolder traceExpressionData=(TraceExpressionInformationHolder)traceExpressionDataTable.get(finalStateNewTraceVariables[i].getName().trim());
          if (traceExpressionData != null) {
            if (traceExpressionData.getLevel() == 2) {
              finalStateNewTraceVariables[i].setValue(TLCVariableValue.parseValue("String_Node_Str"));
            }
            finalStateNewTraceVariables[i].setName(traceExpressionData.getExpression());
            finalStateNewTraceVariables[i].setTraceExplorerVar(true);
          }
        }
        Arrays.sort(finalStateNewTraceVariables,varComparator);
      }
 else       if (finalStateOriginalTrace.isBackToState()) {
        error.addState(TLCState.BACK_TO_STATE(finalStateOriginalTrace.getStateNumber(),ModelHelper.getModelName(getConfig().getFile())));
      }
 else {
        error.addState(TLCState.STUTTERING_STATE(finalStateOriginalTrace.getStateNumber(),ModelHelper.getModelName(getConfig().getFile())));
      }
    }
 else {
      error.setMessage(TE_ERROR_HEADER + error.getMessage());
    }
  }
}

Fixed version (ground truth):
/** 
 * Performs processing for the error and the error trace produced after a run of the trace explorer. This method does the following to a trace: 1.) Changes the names of the variables corresponding to trace explorer expressions to the actual expressions. 2.) It also shifts the values of expressions of level 2. For an expressions of level 2 (expression with primed variables), the value in state x becomes the original value in state x+1. The value in the final state of such expressions is equal to "--". 3.) Changes the state labels "<Action ... in module TE> State (num = 3)" to the state labels of the original trace. The goal is to have no reference to module TE. 4.) Puts the variables representing the trace explorer expressions before the actual variables in each state. 5.) Removes any extra states produced by the trace explorer. This can sometimes occur when evaluating expressions for a looping ("Back to state") trace and for a stuttering trace. This can be illustrated by an example. Consider the following trace: <Initial predicate> <State num 1> x=0 <Action ...> <State num 2> x=1 <Back to state 1> The user wants to evaluate the following expression: x' >= x The toolbox uses the following as init and next: Init == /\ x=0 /\ __trace_var_213123 = "--" Next == \/ /\ x=0 /\ x'=1 /\ __trace_var_213123' = (x'>=x) \/ /\ x=1 /\ x'=0 /\ __trace_var_213123' = (x'>=x) We check the following property: prop_23432 == ~([]<>(x=1)/\[]<>(x=0)) This produces the following trace: <Initial predicate> <State num 1> x=0 __trace_var_213123 = "--" <Action ...> <State num 2> x=1 __trace_var_213123 = TRUE <Action ...> <State num 3> x=0 __trace_var_213123 = FALSE <Back to state 2> Note the additional state with x=0 and __trace_var_213123 = FALSE. We shift the values for expressions with primed variables up by one state, so this extra state is necessary for producing the value for the expression "x' >= x" in the second state of the trace (In non-looping traces, there is no value for the expression in the final state, so we simply assign it the value "--".) The processing by this method eliminates this extra state but uses the value for __trace_var_213123, so that the following trace can be displayed to the user: <Initial predicate> <State num 1> x=0 (x' >= x)    =     TRUE <Action ...> <State num 2> x=1 (x' >= x)    =    FALSE <Back to state 1> 6.) If the trace explorer ran successfully, this method changes several attributes of the error trace produced by the trace explorer. It changes the following three attributes: - error message - error code - cause It sets these attributes equal to those attributes for the error trace produced by the last run of model checking on the model for which the trace explorer was run. 7.) If the run of the trace explorer was successful, then we set the list of errors for this data provider in the following way : - Copy the list of errors from the original run of TLC. - In the copied list, replace the original trace error with the new trace error created by the successful run of the trace explorer.
 */
private void processTraceForTraceExplorer(){
  TLCError originalErrorWithTrace=TraceExplorerHelper.getErrorOfOriginalTrace(getConfig());
  if (originalErrorWithTrace == null) {
    getErrors().clear();
    return;
  }
  TLCError successfulTEError=null;
  List originalTrace=originalErrorWithTrace.getStates();
  Assert.isNotNull(originalTrace,"String_Node_Str");
  Iterator it=getErrors().iterator();
  while (it.hasNext()) {
    TLCError error=(TLCError)it.next();
    if (error.hasTrace()) {
      int errorCode=error.getErrorCode();
      if (errorCode == EC.TLC_DEADLOCK_REACHED || errorCode == EC.TLC_TEMPORAL_PROPERTY_VIOLATED || errorCode == EC.TLC_INVARIANT_VIOLATED_BEHAVIOR || errorCode == EC.TLC_INVARIANT_VIOLATED_INITIAL) {
        error.setErrorCode(originalErrorWithTrace.getErrorCode());
        error.setMessage(originalErrorWithTrace.getMessage());
        error.setCause(originalErrorWithTrace.getCause());
        successfulTEError=error;
      }
 else {
        error.setMessage(TE_ERROR_HEADER + error.getMessage());
      }
      Comparator varComparator=new Comparator(){
        public int compare(        Object arg0,        Object arg1){
          TLCVariable var0=(TLCVariable)arg0;
          TLCVariable var1=(TLCVariable)arg1;
          if ((var0.isTraceExplorerVar() && var1.isTraceExplorerVar()) || (!var0.isTraceExplorerVar() && !var1.isTraceExplorerVar())) {
            return var0.getName().compareTo(var1.getName());
          }
 else           if (var0.isTraceExplorerVar()) {
            return -1;
          }
 else {
            return 1;
          }
        }
      }
;
      List newTrace=error.getStates();
      Iterator newTraceIt=newTrace.iterator();
      Iterator originalTraceIt=originalTrace.iterator();
      TLCState currentStateNewTrace=(TLCState)newTraceIt.next();
      TLCState nextStateNewTrace=null;
      TLCState currentStateOriginalTrace=(TLCState)originalTraceIt.next();
      while (newTraceIt.hasNext() && originalTraceIt.hasNext()) {
        currentStateNewTrace.setLabel(currentStateOriginalTrace.getLabel());
        currentStateNewTrace.setLocation(currentStateOriginalTrace.getModuleLocation());
        nextStateNewTrace=(TLCState)newTraceIt.next();
        TLCVariable[] currentStateNewTraceVariables=currentStateNewTrace.getVariables();
        TLCVariable[] nextStateNewTraceVariables=nextStateNewTrace.getVariables();
        for (int i=0; i < currentStateNewTraceVariables.length; i++) {
          String variableName=currentStateNewTraceVariables[i].getName();
          if (!nextStateNewTrace.isBackToState() && !nextStateNewTrace.isStuttering()) {
            Assert.isTrue(variableName.equals(nextStateNewTraceVariables[i].getName()),"String_Node_Str");
          }
          TraceExpressionInformationHolder traceExpressionData=(TraceExpressionInformationHolder)traceExpressionDataTable.get(variableName.trim());
          if (traceExpressionData != null) {
            if (!nextStateNewTrace.isBackToState() && !nextStateNewTrace.isStuttering() && traceExpressionData.getLevel() == 2) {
              currentStateNewTraceVariables[i].setValue(nextStateNewTraceVariables[i].getValue());
            }
            currentStateNewTraceVariables[i].setName(traceExpressionData.getExpression());
            currentStateNewTraceVariables[i].setTraceExplorerVar(true);
          }
        }
        Arrays.sort(currentStateNewTraceVariables,varComparator);
        currentStateNewTrace=nextStateNewTrace;
        currentStateOriginalTrace=(TLCState)originalTraceIt.next();
      }
      if ((currentStateOriginalTrace.isBackToState() || currentStateOriginalTrace.isStuttering()) && newTrace.size() >= originalTrace.size()) {
        newTrace.subList(originalTrace.size() - 1,newTrace.size()).clear();
      }
      Assert.isTrue(newTrace.size() <= originalTrace.size(),"String_Node_Str");
      TLCState finalStateOriginalTrace=(TLCState)originalTrace.get(originalTrace.size() - 1);
      if (newTrace.size() < originalTrace.size() - 1 || (!finalStateOriginalTrace.isStuttering() && !finalStateOriginalTrace.isBackToState())) {
        TLCState finalStateNewTrace=(TLCState)newTrace.get(newTrace.size() - 1);
        TLCState samePositionOriginalTrace=(TLCState)originalTrace.get(newTrace.size() - 1);
        finalStateNewTrace.setLabel(samePositionOriginalTrace.getLabel());
        finalStateNewTrace.setLocation(samePositionOriginalTrace.getModuleLocation());
        TLCVariable[] finalStateNewTraceVariables=finalStateNewTrace.getVariables();
        for (int i=0; i < finalStateNewTraceVariables.length; i++) {
          TraceExpressionInformationHolder traceExpressionData=(TraceExpressionInformationHolder)traceExpressionDataTable.get(finalStateNewTraceVariables[i].getName().trim());
          if (traceExpressionData != null) {
            if (traceExpressionData.getLevel() == 2) {
              finalStateNewTraceVariables[i].setValue(TLCVariableValue.parseValue("String_Node_Str"));
            }
            finalStateNewTraceVariables[i].setName(traceExpressionData.getExpression());
            finalStateNewTraceVariables[i].setTraceExplorerVar(true);
          }
        }
        Arrays.sort(finalStateNewTraceVariables,varComparator);
      }
 else       if (finalStateOriginalTrace.isBackToState()) {
        error.addState(TLCState.BACK_TO_STATE(finalStateOriginalTrace.getStateNumber(),ModelHelper.getModelName(getConfig().getFile())));
      }
 else {
        error.addState(TLCState.STUTTERING_STATE(finalStateOriginalTrace.getStateNumber(),ModelHelper.getModelName(getConfig().getFile())));
      }
    }
 else {
      error.setMessage(TE_ERROR_HEADER + error.getMessage());
    }
  }
  if (successfulTEError != null) {
    List originalErrors=TLCOutputSourceRegistry.getModelCheckSourceRegistry().getProvider(getConfig()).getErrors();
    List newErrors=new LinkedList();
    Iterator iterator=originalErrors.iterator();
    while (iterator.hasNext()) {
      Object next=iterator.next();
      if (next == originalErrorWithTrace) {
        newErrors.add(successfulTEError);
      }
 else {
        newErrors.add(next);
      }
    }
    setErrors(newErrors);
  }
}