Program: 73982
Project: 73982
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 nondeterministic, throw an exception. See   {@link Transition}for the explanation of "nondeterministic". 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.
 * @param transitionList A list of 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.
 */
public Transition chooseTransition(List transitionList) throws IllegalActionException {
  List<Transition> enabledTransitions=enabledTransitions(transitionList);
  int length=enabledTransitions.size();
  if (length > 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 (_lastChosenTransition != null) {
    if (!enabledTransitions.contains(_lastChosenTransition)) {
      throw new IllegalActionException(this,_lastChosenTransition,"String_Node_Str" + "String_Node_Str");
    }
    return _lastChosenTransition;
  }
  Transition result=null;
  if (length == 1) {
    result=(Transition)enabledTransitions.get(0);
  }
 else   if (length > 1) {
    while (enabledTransitions.size() > 0) {
      int randomChoice=(int)Math.floor(Math.random() * length);
      if (randomChoice == length) {
        randomChoice--;
      }
      result=(Transition)enabledTransitions.get(randomChoice);
      if (_referencedInputPortsByOutputKnown(result)) {
        break;
      }
 else {
        enabledTransitions.remove(result);
        result=null;
      }
    }
  }
  if (result != null) {
    if (_debugging) {
      _debug("String_Node_Str",result.getFullName());
    }
    Iterator actions=result.choiceActionList().iterator();
    while (actions.hasNext()) {
      Action action=(Action)actions.next();
      action.execute();
    }
    if (_currentState.getRefinement() == null) {
      List<IOPort> outputs=outputPortList();
      for (      IOPort port : outputs) {
        for (int channel=0; channel < port.getWidth(); channel++) {
          if (!port.isKnown(channel)) {
            port.sendClear(channel);
          }
        }
      }
    }
  }
  _lastChosenTransition=result;
  return result;
}

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 nondeterministic, throw an exception. See   {@link Transition}for the explanation of "nondeterministic". 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. <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 transitionList A list of 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.
 */
public Transition chooseTransition(List transitionList) throws IllegalActionException {
  List<Transition> enabledTransitions=enabledTransitions(transitionList);
  int length=enabledTransitions.size();
  if (length > 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 (_lastChosenTransition != null) {
    if (!enabledTransitions.contains(_lastChosenTransition)) {
      throw new IllegalActionException(this,_lastChosenTransition,"String_Node_Str" + "String_Node_Str");
    }
    return _lastChosenTransition;
  }
  Transition result=null;
  if (length == 1) {
    result=(Transition)enabledTransitions.get(0);
  }
 else   if (length > 1) {
    while (enabledTransitions.size() > 0) {
      int randomChoice=(int)Math.floor(Math.random() * length);
      if (randomChoice == length) {
        randomChoice--;
      }
      result=(Transition)enabledTransitions.get(randomChoice);
      if (_referencedInputPortsByOutputKnown(result)) {
        _foundUnknown=true;
        break;
      }
 else {
        enabledTransitions.remove(result);
        result=null;
      }
    }
  }
  if (result != null) {
    if (_debugging) {
      _debug("String_Node_Str",result.getFullName());
    }
    Iterator actions=result.choiceActionList().iterator();
    while (actions.hasNext()) {
      Action action=(Action)actions.next();
      action.execute();
    }
    if (_currentState.getRefinement() == null) {
      List<IOPort> outputs=outputPortList();
      for (      IOPort port : outputs) {
        for (int channel=0; channel < port.getWidth(); channel++) {
          if (!port.isKnown(channel)) {
            port.sendClear(channel);
          }
        }
      }
    }
  }
  _lastChosenTransition=result;
  return result;
}