Program: 72478
Project: 72478
Buggy source:
/** 
 * Produce any pending outputs specified by send() since the last firing, invoke any timer tasks that match the current time, and invoke the fire function. Specifically: <ol> <li> First, if there is a new token on the script input port, then evaluate the script specified on that port. Any previously defined methods such as fire() will be replaced if the new script has a replacement, and preserved otherwise.  If the new script has an initialize() method, that method will not be invoked until the next time this actor is initialized.</li> <li> Next, send any outputs that have been queued to be sent by calling send() from outside any firing of this JavaScript actor.</li> <li> Next, read all available inputs, recording their values for subsequent calls to get().</li> <li> Next, invoke any pending timer tasks whose timing matches the current time.</li> <li> After updating all the inputs, for each input port that had a new token on any channel and for which there is a handler function bound to that port via the addInputHandler() method, invoke that function.  Such a function will be invoked in the following order: First, invoke the functions for each PortParameter, in the order in which the PortParameters were created.  Then invoke the functions for the ordinary input ports.</li> <li> Next, if the current script has a fire() function, then invoke it.</li> </ol>
 * @exception IllegalActionException If calling send() or super.fire()throws it.
 */
@Override public void fire() throws IllegalActionException {
  super.fire();
  if (_debugging) {
    _engine.put("String_Node_Str",true);
  }
 else {
    _engine.put("String_Node_Str",false);
  }
  ParameterPort scriptPort=script.getPort();
  if (scriptPort.getWidth() > 0 && scriptPort.hasToken(0)) {
    script.update();
    String scriptValue=((StringToken)script.getToken()).stringValue();
    try {
      _engine.eval(scriptValue);
      _exports=_engine.eval("String_Node_Str");
    }
 catch (    ScriptException ex) {
      if (error.getWidth() > 0) {
        error.send(0,new StringToken(ex.getMessage()));
      }
 else {
        throw new IllegalActionException(this,ex,"String_Node_Str");
      }
    }
    if (_debugging) {
      _debug("String_Node_Str" + scriptValue);
    }
  }
synchronized (this) {
    if (_outputTokens != null) {
      for (      IOPort port : _outputTokens.keySet()) {
        HashMap<Integer,List<Token>> tokens=_outputTokens.get(port);
        for (        Map.Entry<Integer,List<Token>> entry : tokens.entrySet()) {
          List<Token> queue=entry.getValue();
          if (queue != null) {
            for (            Token token : queue) {
              port.send(entry.getKey(),token);
              if (_debugging) {
                _debug("String_Node_Str" + port.getName() + "String_Node_Str"+ token);
              }
            }
          }
        }
      }
      _outputTokens.clear();
    }
  }
  boolean foundNewInput=false;
  for (  PortParameter portParameter : attributeList(PortParameter.class)) {
    if (portParameter == script) {
      continue;
    }
    PortOrParameterProxy proxy=_proxies.get(portParameter.getPort());
    if (portParameter.update()) {
      proxy._hasNewInput(true);
      foundNewInput=true;
      if (_debugging) {
        _debug("String_Node_Str" + portParameter.getName() + "String_Node_Str"+ portParameter.getToken());
      }
    }
 else     if (proxy._localInputTokens != null && proxy._localInputTokens.size() > 0) {
      portParameter.setCurrentValue(proxy._localInputTokens.remove(0));
      proxy._hasNewInput(true);
      foundNewInput=true;
    }
 else {
      proxy._hasNewInput(false);
    }
  }
  _inputTokens.clear();
  for (  IOPort input : inputPortList()) {
    if (input == script.getPort()) {
      continue;
    }
    if (input instanceof ParameterPort) {
      continue;
    }
    HashMap<Integer,Token> tokens=new HashMap<Integer,Token>();
    boolean hasInput=false;
    PortOrParameterProxy proxy=_proxies.get(input);
    for (int i=0; i < input.getWidth(); i++) {
      if (input.hasToken(i)) {
        hasInput=true;
        tokens.put(i,input.get(i));
        if (_debugging) {
          _debug("String_Node_Str" + input.getName() + "String_Node_Str"+ tokens.get(i));
        }
      }
 else {
        if (proxy._localInputTokens != null && proxy._localInputTokens.size() > 0) {
          tokens.put(i,proxy._localInputTokens.remove(0));
          hasInput=true;
        }
      }
    }
    if (input.getWidth() == 0 && proxy._localInputTokens != null && proxy._localInputTokens.size() > 0) {
      tokens.put(0,proxy._localInputTokens.remove(0));
      hasInput=true;
    }
    _inputTokens.put(input,tokens);
    if (hasInput) {
      proxy._hasNewInput(true);
      foundNewInput=true;
    }
 else {
      proxy._hasNewInput(false);
    }
  }
synchronized (this) {
    _inFire=true;
    try {
      if (_pendingTimeoutIDs != null) {
        Time currentTime=getDirector().getModelTime();
        List<Integer> ids=_pendingTimeoutIDs.get(currentTime);
        if (ids != null) {
          List<Integer> copy=new LinkedList<Integer>(ids);
          if (ids != null) {
            for (            Integer id : copy) {
              Runnable function=_pendingTimeoutFunctions.get(id);
              if (function != null) {
                _pendingTimeoutFunctions.remove(id);
                function.run();
                if (_debugging) {
                  _debug("String_Node_Str");
                }
              }
            }
            _pendingTimeoutIDs.remove(currentTime);
          }
        }
      }
      for (      IOPort input : inputPortList()) {
        if (input == script.getPort()) {
          continue;
        }
        _proxies.get(input).invokeHandlers();
      }
      if (foundNewInput && _genericInputHandlers != null && _genericInputHandlers.size() > 0) {
        for (        Runnable function : _genericInputHandlers) {
          if (function != null) {
            function.run();
            if (_debugging) {
              _debug("String_Node_Str");
            }
          }
        }
      }
      _invokeMethodInContext("String_Node_Str");
      if (_debugging) {
        _debug("String_Node_Str");
      }
    }
  finally {
      _inFire=false;
    }
  }
}

Fixed version (ground truth):
/** 
 * Produce any pending outputs specified by send() since the last firing, invoke any timer tasks that match the current time, and invoke the fire function. Specifically: <ol> <li> First, if there is a new token on the script input port, then evaluate the script specified on that port. Any previously defined methods such as fire() will be replaced if the new script has a replacement, and preserved otherwise.  If the new script has an initialize() method, that method will not be invoked until the next time this actor is initialized.</li> <li> Next, send any outputs that have been queued to be sent by calling send() from outside any firing of this JavaScript actor.</li> <li> Next, read all available inputs, recording their values for subsequent calls to get().</li> <li> Next, invoke any pending timer tasks whose timing matches the current time.</li> <li> After updating all the inputs, for each input port that had a new token on any channel and for which there is a handler function bound to that port via the addInputHandler() method, invoke that function.  Such a function will be invoked in the following order: First, invoke the functions for each PortParameter, in the order in which the PortParameters were created.  Then invoke the functions for the ordinary input ports.</li> <li> Next, if the current script has a fire() function, then invoke it.</li> </ol>
 * @exception IllegalActionException If calling send() or super.fire()throws it.
 */
@Override public void fire() throws IllegalActionException {
  super.fire();
  if (_debugging) {
    _engine.put("String_Node_Str",true);
  }
 else {
    _engine.put("String_Node_Str",false);
  }
  ParameterPort scriptPort=script.getPort();
  if (scriptPort.getWidth() > 0 && scriptPort.hasToken(0)) {
    script.update();
    String scriptValue=((StringToken)script.getToken()).stringValue();
    try {
      _engine.eval(scriptValue);
      _exports=_engine.eval("String_Node_Str");
    }
 catch (    ScriptException ex) {
      if (error.getWidth() > 0) {
        error.send(0,new StringToken(ex.getMessage()));
      }
 else {
        throw new IllegalActionException(this,ex,"String_Node_Str");
      }
    }
    if (_debugging) {
      _debug("String_Node_Str" + scriptValue);
    }
  }
synchronized (this) {
    if (_outputTokens != null) {
      for (      IOPort port : _outputTokens.keySet()) {
        HashMap<Integer,List<Token>> tokens=_outputTokens.get(port);
        for (        Map.Entry<Integer,List<Token>> entry : tokens.entrySet()) {
          List<Token> queue=entry.getValue();
          if (queue != null) {
            for (            Token token : queue) {
              port.send(entry.getKey(),token);
              if (_debugging) {
                _debug("String_Node_Str" + port.getName() + "String_Node_Str"+ token);
              }
            }
          }
        }
      }
      _outputTokens.clear();
    }
  }
  boolean foundNewInput=false;
  for (  PortParameter portParameter : attributeList(PortParameter.class)) {
    if (portParameter == script) {
      continue;
    }
    PortOrParameterProxy proxy=_proxies.get(portParameter.getPort());
    if (portParameter.update()) {
      proxy._hasNewInput(true);
      foundNewInput=true;
      if (_debugging) {
        _debug("String_Node_Str" + portParameter.getName() + "String_Node_Str"+ portParameter.getToken());
      }
    }
 else     if (proxy._localInputTokens != null && proxy._localInputTokens.size() > 0) {
      portParameter.setCurrentValue(proxy._localInputTokens.remove(0));
      proxy._hasNewInput(true);
      foundNewInput=true;
    }
 else {
      proxy._hasNewInput(false);
    }
  }
  _inputTokens.clear();
  for (  IOPort input : inputPortList()) {
    if (input == script.getPort()) {
      continue;
    }
    if (input instanceof ParameterPort) {
      continue;
    }
    HashMap<Integer,Token> tokens=new HashMap<Integer,Token>();
    boolean hasInput=false;
    PortOrParameterProxy proxy=_proxies.get(input);
    for (int i=0; i < input.getWidth(); i++) {
      if (input.hasToken(i)) {
        hasInput=true;
        tokens.put(i,input.get(i));
        if (_debugging) {
          _debug("String_Node_Str" + input.getName() + "String_Node_Str"+ tokens.get(i));
        }
      }
 else {
        if (proxy._localInputTokens != null && proxy._localInputTokens.size() > 0) {
          tokens.put(i,proxy._localInputTokens.remove(0));
          hasInput=true;
        }
      }
    }
    if (input.getWidth() == 0 && proxy._localInputTokens != null && proxy._localInputTokens.size() > 0) {
      tokens.put(0,proxy._localInputTokens.remove(0));
      hasInput=true;
    }
    _inputTokens.put(input,tokens);
    if (hasInput) {
      proxy._hasNewInput(true);
      foundNewInput=true;
    }
 else {
      proxy._hasNewInput(false);
    }
  }
synchronized (this) {
    _inFire=true;
    try {
      if (_pendingTimeoutIDs != null) {
        Time currentTime=getDirector().getModelTime();
        List<Integer> ids=_pendingTimeoutIDs.get(currentTime);
        if (ids != null) {
          List<Integer> copy=new LinkedList<Integer>(ids);
          if (ids != null) {
            for (            Integer id : copy) {
              Runnable function=_pendingTimeoutFunctions.get(id);
              if (function != null) {
                function.run();
                if (_debugging) {
                  _debug("String_Node_Str");
                }
              }
            }
            _pendingTimeoutIDs.remove(currentTime);
          }
        }
      }
      for (      IOPort input : inputPortList()) {
        if (input == script.getPort()) {
          continue;
        }
        _proxies.get(input).invokeHandlers();
      }
      if (foundNewInput && _genericInputHandlers != null && _genericInputHandlers.size() > 0) {
        for (        Runnable function : _genericInputHandlers) {
          if (function != null) {
            function.run();
            if (_debugging) {
              _debug("String_Node_Str");
            }
          }
        }
      }
      _invokeMethodInContext("String_Node_Str");
      if (_debugging) {
        _debug("String_Node_Str");
      }
    }
  finally {
      _inFire=false;
    }
  }
}