Program: 73242
Project: 73242
Buggy source:
/** 
 * Return an enabled transition among the given list of transitions for which both the guard expression and the output actions can be evaluated (the inputs referred by these are known). If there is only one transition enabled, return that transition. In case there are multiple enabled transitions, if any of them is not marked nondeterministic, throw an exception. Otherwise, randomly choose one from the enabled transitions and return it if the output actions can be evaluated. Execute the output actions contained by the returned transition before returning. Also, fire the transition refinements, if any. <p> After calling this method, you can call foundUnknown() to determine whether any guard expressions or output value expressions on a transition whose guard evaluates to true were found in the specified transition list that referred to input ports that are not currently known.
 * @param currentState The state from which transitions are examined.
 * @param transitionList A list of transitions.
 * @param immediateOnly True to consider only immediate transitions.
 * @return An enabled transition, or null if none is enabled.
 * @exception IllegalActionException If there is more than onetransition enabled and not all of them are nondeterministic.
 */
protected Transition _chooseTransition(State currentState,List transitionList,boolean immediateOnly) throws IllegalActionException {
  List<Transition> enabledTransitions=enabledTransitions(transitionList,immediateOnly);
  int numberOfEnabledTransitions=enabledTransitions.size();
  Transition chosenTransition=null;
  if (numberOfEnabledTransitions == 1) {
    chosenTransition=(Transition)enabledTransitions.get(0);
  }
 else   if (numberOfEnabledTransitions > 1) {
    for (    Transition enabledTransition : enabledTransitions) {
      if (!enabledTransition.isNondeterministic()) {
        throw new MultipleEnabledTransitionsException(currentState,"String_Node_Str" + "String_Node_Str" + "String_Node_Str" + enabledTransition.getName() + "String_Node_Str");
      }
    }
    if (_transitionsPreviouslyChosenInIteration.size() > 0) {
      for (      Transition previouslyChosenTransition : _transitionsPreviouslyChosenInIteration) {
        if (enabledTransitions.contains(previouslyChosenTransition)) {
          chosenTransition=previouslyChosenTransition;
        }
      }
    }
    if (chosenTransition == null) {
      while (enabledTransitions.size() > 0) {
        int randomChoice=(int)Math.floor(Math.random() * numberOfEnabledTransitions);
        if (randomChoice == numberOfEnabledTransitions) {
          randomChoice--;
        }
        chosenTransition=(Transition)enabledTransitions.get(randomChoice);
        if (_referencedInputPortsByOutputKnown(chosenTransition)) {
          _foundUnknown=true;
          break;
        }
 else {
          enabledTransitions.remove(chosenTransition);
          chosenTransition=null;
        }
      }
      _transitionsPreviouslyChosenInIteration.add(chosenTransition);
    }
  }
  if (chosenTransition != null) {
    if (_debugging) {
      _debug("String_Node_Str",chosenTransition.getFullName());
    }
    Iterator actions=chosenTransition.choiceActionList().iterator();
    while (actions.hasNext()) {
      Action action=(Action)actions.next();
      action.execute();
    }
    Actor[] transitionRefinements=chosenTransition.getRefinement();
    if (transitionRefinements != null) {
      for (int i=0; i < transitionRefinements.length; ++i) {
        if (_stopRequested || _disabledRefinements.contains(transitionRefinements[i])) {
          break;
        }
        if (_debugging) {
          _debug("String_Node_Str",transitionRefinements[i].getName());
        }
        if (transitionRefinements[i].prefire()) {
          transitionRefinements[i].fire();
          _transitionRefinementsToPostfire.add(transitionRefinements[i]);
        }
      }
    }
    if (_areAllImmediateTransitionsDisabled(chosenTransition.destinationState()) && currentState.getRefinement() == null) {
      List<IOPort> outputs=outputPortList();
      for (      IOPort port : outputs) {
        for (int channel=0; channel < port.getWidth(); channel++) {
          if (!port.isKnown(channel)) {
            port.send(channel,null);
          }
        }
      }
    }
    _lastChosenTransitions.put(currentState,chosenTransition);
  }
  return chosenTransition;
}

Fixed version (ground truth):
/** 
 * Return an enabled transition among the given list of transitions for which both the guard expression and the output actions can be evaluated (the inputs referred by these are known). If there is only one transition enabled, return that transition. In case there are multiple enabled transitions, if any of them is not marked nondeterministic, throw an exception. Otherwise, randomly choose one from the enabled transitions and return it if the output actions can be evaluated. Execute the output actions contained by the returned transition before returning. Also, fire the transition refinements, if any. <p> After calling this method, you can call foundUnknown() to determine whether any guard expressions or output value expressions on a transition whose guard evaluates to true were found in the specified transition list that referred to input ports that are not currently known.
 * @param currentState The state from which transitions are examined.
 * @param transitionList A list of transitions.
 * @param immediateOnly True to consider only immediate transitions.
 * @return An enabled transition, or null if none is enabled.
 * @exception IllegalActionException If there is more than onetransition enabled and not all of them are nondeterministic.
 */
protected Transition _chooseTransition(State currentState,List transitionList,boolean immediateOnly) throws IllegalActionException {
  List<Transition> enabledTransitions=enabledTransitions(transitionList,immediateOnly);
  int numberOfEnabledTransitions=enabledTransitions.size();
  Transition chosenTransition=null;
  if (numberOfEnabledTransitions == 1) {
    chosenTransition=(Transition)enabledTransitions.get(0);
    _transitionsPreviouslyChosenInIteration.add(chosenTransition);
  }
 else   if (numberOfEnabledTransitions > 1) {
    for (    Transition enabledTransition : enabledTransitions) {
      if (!enabledTransition.isNondeterministic()) {
        throw new MultipleEnabledTransitionsException(currentState,"String_Node_Str" + "String_Node_Str" + "String_Node_Str" + enabledTransition.getName() + "String_Node_Str");
      }
    }
    if (_transitionsPreviouslyChosenInIteration.size() > 0) {
      for (      Transition previouslyChosenTransition : _transitionsPreviouslyChosenInIteration) {
        if (enabledTransitions.contains(previouslyChosenTransition)) {
          chosenTransition=previouslyChosenTransition;
        }
      }
    }
    if (chosenTransition == null) {
      while (enabledTransitions.size() > 0) {
        int randomChoice=(int)Math.floor(Math.random() * numberOfEnabledTransitions);
        if (randomChoice == numberOfEnabledTransitions) {
          randomChoice--;
        }
        chosenTransition=(Transition)enabledTransitions.get(randomChoice);
        if (_referencedInputPortsByOutputKnown(chosenTransition)) {
          _foundUnknown=true;
          break;
        }
 else {
          enabledTransitions.remove(chosenTransition);
          chosenTransition=null;
        }
      }
      _transitionsPreviouslyChosenInIteration.add(chosenTransition);
    }
  }
  if (chosenTransition != null) {
    if (_debugging) {
      _debug("String_Node_Str",chosenTransition.getFullName());
    }
    Iterator actions=chosenTransition.choiceActionList().iterator();
    while (actions.hasNext()) {
      Action action=(Action)actions.next();
      action.execute();
    }
    Actor[] transitionRefinements=chosenTransition.getRefinement();
    if (transitionRefinements != null) {
      for (int i=0; i < transitionRefinements.length; ++i) {
        if (_stopRequested || _disabledRefinements.contains(transitionRefinements[i])) {
          break;
        }
        if (_debugging) {
          _debug("String_Node_Str",transitionRefinements[i].getName());
        }
        if (transitionRefinements[i].prefire()) {
          transitionRefinements[i].fire();
          _transitionRefinementsToPostfire.add(transitionRefinements[i]);
        }
      }
    }
    if (_areAllImmediateTransitionsDisabled(chosenTransition.destinationState()) && currentState.getRefinement() == null) {
      List<IOPort> outputs=outputPortList();
      for (      IOPort port : outputs) {
        for (int channel=0; channel < port.getWidth(); channel++) {
          if (!port.isKnown(channel)) {
            port.send(channel,null);
          }
        }
      }
    }
    _lastChosenTransitions.put(currentState,chosenTransition);
  }
  return chosenTransition;
}