nus-yam/ex-repair huggingface dataset:
Program: 74171
Project: 74171
Buggy source:
/** 
 * Generate variable initialization for the referenced parameters.
 * @return code The generated code.
 * @exception IllegalActionException If the adapter class for the modeldirector cannot be found.
 */
public String generateVariableInitialization() throws IllegalActionException {
  StringBuffer code=new StringBuffer();
  Iterator<?> actors=((CompositeActor)_director.getContainer()).deepEntityList().iterator();
  while (actors.hasNext()) {
    Actor actor=(Actor)actors.next();
    CodeGeneratorAdapter adapterObject=getCodeGenerator().getAdapter((NamedObj)actor);
    code.append(adapterObject.generateVariableInitialization());
  }
  return code.toString();
}

Fixed version (ground truth):
/** 
 * Generate variable initialization for the referenced parameters.
 * @return code The generated code.
 * @exception IllegalActionException If the adapter class for the modeldirector cannot be found.
 */
@Override public String generateVariableInitialization() throws IllegalActionException {
  StringBuffer code=new StringBuffer();
  CompositeActor container=(CompositeActor)_director.getContainer();
  GenericCodeGenerator codeGenerator=getCodeGenerator();
{
    CodeGeneratorAdapter adapterObject=codeGenerator.getAdapter(container);
    code.append(_generateVariableInitialization(adapterObject));
  }
  Iterator<?> actors=container.deepEntityList().iterator();
  while (actors.hasNext()) {
    Actor actor=(Actor)actors.next();
    CodeGeneratorAdapter adapterObject=codeGenerator.getAdapter((NamedObj)actor);
    code.append(_generateVariableInitialization(adapterObject));
  }
  return code.toString();
}
Program: 74172
Project: 74172
Buggy source:
public String generateCodeForGet(String channel) throws IllegalActionException {
  ptolemy.cg.adapter.generic.adapters.ptolemy.actor.Director directorAdapter=_getDirectorAdapter();
  ptolemy.actor.IOPort port=(ptolemy.actor.IOPort)getComponent();
  int channelNumber=Integer.valueOf(channel);
  return directorAdapter.generateCodeForGet(port,channelNumber);
}

Fixed version (ground truth):
/** 
 * Generate the get code.
 * @param channel The channel for which the get code is generated.
 * @return The code that gets data from the channel.
 */
public String generateCodeForGet(String channel) throws IllegalActionException {
  ptolemy.cg.adapter.generic.adapters.ptolemy.actor.Director directorAdapter=_getDirectorAdapter();
  ptolemy.actor.IOPort port=(ptolemy.actor.IOPort)getComponent();
  int channelNumber=Integer.valueOf(channel);
  return directorAdapter.generateCodeForGet(port,channelNumber);
}
Program: 74173
Project: 74173
Buggy source:
public String generateCodeForSend(String channel,String dataToken) throws IllegalActionException {
  ptolemy.cg.adapter.generic.adapters.ptolemy.actor.Director directorAdapter=_getDirectorAdapter();
  ptolemy.actor.IOPort port=(ptolemy.actor.IOPort)getComponent();
  int channelNumber=Integer.valueOf(channel);
  return directorAdapter.generateCodeForSend(port,channelNumber,dataToken);
}

Fixed version (ground truth):
/** 
 * Generate the send code.
 * @param channel The channel for which the send code is generated.
 * @param dataToken The token to be sent
 * @return The code that sends the dataToken on the channel.
 */
public String generateCodeForSend(String channel,String dataToken) throws IllegalActionException {
  ptolemy.cg.adapter.generic.adapters.ptolemy.actor.Director directorAdapter=_getDirectorAdapter();
  ptolemy.actor.IOPort port=(ptolemy.actor.IOPort)getComponent();
  int channelNumber=Integer.valueOf(channel);
  return directorAdapter.generateCodeForSend(port,channelNumber,dataToken);
}
Program: 74174
Project: 74174
Buggy source:
/** 
 * Generate variable declarations for input ports, output ports and parameters if necessary, as well as for the director and the contained actors.
 * @return code The generated code.
 * @exception IllegalActionException If the adapter associated withan actor throws it while generating variable declarations for the actor.
 */
@Override public String generateVariableDeclaration() throws IllegalActionException {
  StringBuffer code=new StringBuffer();
  code.append(super.generateVariableDeclaration());
  Director directorAdapter=(Director)getCodeGenerator().getAdapter(((ptolemy.actor.CompositeActor)getComponent()).getDirector());
  code.append(directorAdapter.generateVariableDeclaration());
  return processCode(code.toString());
}

Fixed version (ground truth):
/** 
 * Generate variable declarations for input ports, output ports and parameters if necessary, as well as for the director and the contained actors.
 * @return code The generated code.
 * @exception IllegalActionException If the adapter associated withan actor throws it while generating variable declarations for the actor.
 */
@Override final public String generateVariableDeclaration() throws IllegalActionException {
  StringBuffer code=new StringBuffer();
  Director directorAdapter=(Director)getCodeGenerator().getAdapter(((ptolemy.actor.CompositeActor)getComponent()).getDirector());
  code.append(directorAdapter.generateVariableDeclaration());
  return processCode(code.toString());
}
Program: 74175
Project: 74175
Buggy source:
/** 
 * Generate variable initialization for the referenced parameters.
 * @return code The generated code.
 * @exception IllegalActionException If the adapter associated withan actor throws it while generating variable declarations for the actor.
 */
@Override public String generateVariableInitialization() throws IllegalActionException {
  StringBuffer code=new StringBuffer();
  code.append(super.generateVariableInitialization());
  Director directorAdapter=(Director)getCodeGenerator().getAdapter(((ptolemy.actor.CompositeActor)getComponent()).getDirector());
  code.append(directorAdapter.generateVariableInitialization());
  return processCode(code.toString());
}

Fixed version (ground truth):
/** 
 * Generate variable initialization for the referenced parameters.
 * @return code The generated code.
 * @exception IllegalActionException If the adapter associated withan actor throws it while generating variable declarations for the actor.
 */
@Override final public String generateVariableInitialization() throws IllegalActionException {
  StringBuffer code=new StringBuffer();
  Director directorAdapter=(Director)getCodeGenerator().getAdapter(((ptolemy.actor.CompositeActor)getComponent()).getDirector());
  code.append(directorAdapter.generateVariableInitialization());
  return processCode(code.toString());
}
Program: 74179
Project: 74179
Buggy source:
/** 
 * Return a string representation of this event.
 * @return A user-readable string describing the event.
 */
public String toString(){
  StringBuffer buffer=new StringBuffer("String_Node_Str" + _port + "String_Node_Str");
  if (_vectorLength != SINGLETOKEN) {
    buffer.append(_vectorLength);
    buffer.append("String_Node_Str");
  }
 else {
    buffer.append(_token.toString());
  }
  if (_channel != ALLCHANNELS) {
    buffer.append("String_Node_Str" + _channel + "String_Node_Str");
  }
 else {
    buffer.append("String_Node_Str");
  }
  return buffer.toString();
}

Fixed version (ground truth):
/** 
 * Return a string representation of this event.
 * @return A user-readable string describing the event.
 */
public String toString(){
  StringBuilder buffer=new StringBuilder("String_Node_Str" + _port);
  if (_event == SEND) {
    buffer.append("String_Node_Str");
  }
 else   if (_event == GET_BEGIN) {
    buffer.append("String_Node_Str");
  }
 else   if (_event == GET_END) {
    buffer.append("String_Node_Str");
  }
  if (_vectorLength != SINGLETOKEN) {
    buffer.append(_vectorLength);
    buffer.append("String_Node_Str");
  }
 else {
    buffer.append(_token.toString());
  }
  if (_channel != ALLCHANNELS) {
    buffer.append("String_Node_Str" + _channel + "String_Node_Str");
  }
 else {
    buffer.append("String_Node_Str");
  }
  return buffer.toString();
}
Program: 74180
Project: 74180
Buggy source:
private void _setOrClearPatternObjectAttributes(NamedObj object,boolean isSet,Collection<?> filter){
  try {
    Collection<?> children;
    if (filter == null) {
      children=GTTools.getChildren(object,false,true,true,true);
    }
 else {
      children=filter;
    }
    for (    Object childObject : children) {
      NamedObj child=(NamedObj)childObject;
      PatternObjectAttribute patternObject=GTTools.getPatternObjectAttribute(child);
      if (isSet) {
        if (patternObject == null) {
          patternObject=new PatternObjectAttribute(child,"String_Node_Str");
        }
        String name=_getNameWithinContainer(child,getFrameController().getTransformationRule().getPattern());
        patternObject.setPersistent(true);
        patternObject.setExpression(name);
      }
 else       if (patternObject != null) {
        patternObject.setPersistent(false);
        patternObject.setExpression("String_Node_Str");
      }
      if (child instanceof CompositeEntity) {
        _setOrClearPatternObjectAttributes((CompositeEntity)child,isSet,null);
      }
    }
  }
 catch (  KernelException e) {
    throw new KernelRuntimeException(e,"String_Node_Str");
  }
}

Fixed version (ground truth):
private void _setOrClearPatternObjectAttributes(NamedObj object,boolean isSet,Collection<?> filter){
  try {
    Collection<?> children;
    if (filter == null) {
      children=GTTools.getChildren(object,false,true,true,true);
    }
 else {
      children=filter;
    }
    PatternObjectAttribute patternObject=GTTools.getPatternObjectAttribute(object);
    if (isSet) {
      if (patternObject == null) {
        patternObject=new PatternObjectAttribute(object,"String_Node_Str");
      }
      String name=_getNameWithinContainer(object,getFrameController().getTransformationRule().getPattern());
      patternObject.setPersistent(true);
      patternObject.setExpression(name);
    }
 else     if (patternObject != null) {
      patternObject.setPersistent(false);
      patternObject.setExpression("String_Node_Str");
    }
    for (    Object child : children) {
      _setOrClearPatternObjectAttributes((NamedObj)child,isSet,null);
    }
  }
 catch (  KernelException e) {
    throw new KernelRuntimeException(e,"String_Node_Str");
  }
}
Program: 74181
Project: 74181
Buggy source:
/** 
 * Return the next field, if there is any, or null if the end of the string has been reached.
 * @return The next field of the string.
 */
public String next(){
  int position=_values.indexOf(FIELD_SEPARATOR);
  String next;
  if (position < 0) {
    next=_values;
    _values=null;
  }
 else {
    next=_values.substring(0,position);
    _values=_values.substring(position + 1);
  }
  return next;
}

Fixed version (ground truth):
/** 
 * Return the next field, if there is any, or null if the end of the string has been reached.
 * @return The next field of the string.
 */
public String next(){
  int position=-1;
  boolean inDblQuote=false;
  boolean inSngQuote=false;
  boolean escaped=false;
  for (int i=0; i < _values.length(); i++) {
    char c=_values.charAt(i);
    if (c == '\\' && (inDblQuote || inSngQuote)) {
      escaped=!escaped;
    }
 else     if (c == '\"' && !escaped) {
      inDblQuote=!inDblQuote;
    }
 else     if (c == '\'' && !inDblQuote && !escaped) {
      inSngQuote=!inSngQuote;
    }
    if (!escaped && !inDblQuote && !inSngQuote&& c == FIELD_SEPARATOR) {
      position=i;
      break;
    }
    if (c != '\\') {
      escaped=false;
    }
  }
  String next;
  if (position < 0) {
    next=_values;
    _values=null;
  }
 else {
    next=_values.substring(0,position);
    _values=_values.substring(position + 1);
  }
  return next;
}
Program: 74182
Project: 74182
Buggy source:
/** 
 * Find the closing parenthesis that matches the the open parenthesis at startPos position in string s.
 * @param s The string.
 * @param startPos The position of the open parenthesis to be matched.
 * @return The position of the matching close parenthesis, or -1 if eitherthe character at position startPos is not an open parenthesis or it is an open parenthesis but is not matched.
 */
protected static int _findMatchingParen(String s,int startPos){
  if (s.charAt(startPos) == '(') {
    int parenNum=1;
    boolean inDblQuote=false;
    boolean inSngQuote=false;
    boolean escaped=false;
    for (int i=startPos + 1; i < s.length(); i++) {
      char c=s.charAt(i);
      if (c == '\\' && (inDblQuote || inSngQuote)) {
        escaped=!escaped;
      }
 else       if (c == '\"' && !escaped) {
        inDblQuote=!inDblQuote;
      }
 else       if (c == '\'' && !inDblQuote && !escaped) {
        inSngQuote=!inSngQuote;
      }
 else       if (c == ')' && !inDblQuote && !inSngQuote) {
        parenNum--;
      }
      if (c != '\\') {
        escaped=false;
      }
      if (parenNum == 0) {
        return i;
      }
    }
  }
  return -1;
}

Fixed version (ground truth):
/** 
 * Find the closing parenthesis that matches the the open parenthesis at startPos position in string s.
 * @param s The string.
 * @param startPos The position of the open parenthesis to be matched.
 * @return The position of the matching close parenthesis, or -1 if eitherthe character at position startPos is not an open parenthesis or it is an open parenthesis but is not matched.
 */
protected static int _findMatchingParen(String s,int startPos){
  if (s.charAt(startPos) == '(') {
    int parenNum=1;
    boolean inDblQuote=false;
    boolean inSngQuote=false;
    boolean escaped=false;
    for (int i=startPos + 1; i < s.length(); i++) {
      char c=s.charAt(i);
      if (c == '\\' && (inDblQuote || inSngQuote)) {
        escaped=!escaped;
      }
 else       if (c == '\"' && !escaped) {
        inDblQuote=!inDblQuote;
      }
 else       if (c == '\'' && !inDblQuote && !escaped) {
        inSngQuote=!inSngQuote;
      }
 else       if (c == '(' && !inDblQuote && !inSngQuote) {
        parenNum++;
      }
 else       if (c == ')' && !inDblQuote && !inSngQuote) {
        parenNum--;
      }
      if (c != '\\') {
        escaped=false;
      }
      if (parenNum == 0) {
        return i;
      }
    }
  }
  return -1;
}
Program: 74184
Project: 74184
Buggy source:
/** 
 * @param args Not used.
 */
public static void main(String[] args){
  try {
    File directory=new File(FileUtilities.nameToURL("String_Node_Str",null,null).getFile());
    for (    File file : directory.listFiles()) {
      String filename=file.getPath();
      CodeStream stream=new CodeStream(filename,null);
      TreeSet<Signature> sortedSet=new TreeSet<Signature>(stream.getAllCodeBlockSignatures());
      StringBuffer code=new StringBuffer();
      for (      Signature signature : sortedSet) {
        String templateCode=stream.getCodeBlockTemplate(signature);
        String[] fragments=templateCode.split(signature.functionName);
        if (fragments.length <= 2) {
          System.err.println("String_Node_Str" + signature + "String_Node_Str"+ "String_Node_Str"+ signature.functionName);
        }
        code.append(templateCode);
      }
      if (code.toString().trim().length() > 0) {
        FileWriter writer=new FileWriter(new File(filename));
        writer.write(code.toString().replaceAll("String_Node_Str","String_Node_Str").replaceAll("String_Node_Str","String_Node_Str"));
        writer.close();
      }
    }
  }
 catch (  Exception e) {
    e.printStackTrace();
  }
}

Fixed version (ground truth):
/** 
 * @param args Not used.
 */
public static void main(String[] args){
  try {
    File directory=new File(FileUtilities.nameToURL("String_Node_Str",null,null).getFile());
    for (    File file : directory.listFiles()) {
      String filename=file.getPath();
      CodeStream stream=new CodeStream(filename,null);
      TreeSet<Signature> sortedSet=new TreeSet<Signature>(stream.getAllCodeBlockSignatures());
      StringBuffer code=new StringBuffer();
      for (      Signature signature : sortedSet) {
        String templateCode=stream.getCodeBlockTemplate(signature);
        String functionHeader=templateCode.split("String_Node_Str")[1];
        String[] fragments=functionHeader.split(signature.functionName);
        if (fragments.length <= 1) {
          System.err.println("String_Node_Str" + signature + "String_Node_Str"+ "String_Node_Str"+ signature.functionName);
        }
        code.append(templateCode);
      }
      if (code.toString().trim().length() > 0) {
        FileWriter writer=new FileWriter(new File(filename));
        writer.write(code.toString().replaceAll("String_Node_Str","String_Node_Str").replaceAll("String_Node_Str","String_Node_Str"));
        writer.close();
      }
    }
  }
 catch (  Exception e) {
    e.printStackTrace();
  }
}
Program: 74186
Project: 74186
Buggy source:
@Override public boolean prefire() throws IllegalActionException {
  Director executiveDirector=((Actor)getContainer()).getExecutiveDirector();
  while (executiveDirector != null && !(executiveDirector instanceof PtidesDirector))   executiveDirector=((Actor)executiveDirector.getContainer()).getExecutiveDirector();
  _currentPhysicalTime=executiveDirector.getModelTime();
  executiveDirector=((Actor)getContainer()).getExecutiveDirector();
  _transferAllInputs();
  if (!(executiveDirector instanceof PtidesDirector)) {
    if (_eventsInExecution.size() > 0) {
      TimedEvent eventInExecution=_eventsInExecution.getFirst();
      Actor actorToFire=(Actor)eventInExecution.contents;
      Time time=getFinishingTime(actorToFire);
      if (time.equals(_currentPhysicalTime)) {
        return true;
      }
    }
    List eventsToFire=_getNextEventsToFire();
    Time nextRealTimeEventTime=_getNextRealTimeEventTime(eventsToFire,_eventsInExecution);
    TimedEvent event=_executionStrategy.getNextEventToFire(_eventsInExecution,eventsToFire,nextRealTimeEventTime,_currentPhysicalTime);
    if (event != null)     return true;
    if (!nextRealTimeEventTime.equals(Time.POSITIVE_INFINITY))     _fireContainerAt(nextRealTimeEventTime);
    return false;
  }
 else   return super.prefire();
}

Fixed version (ground truth):
@Override public boolean prefire() throws IllegalActionException {
  Director executiveDirector=((Actor)getContainer()).getExecutiveDirector();
  while (executiveDirector != null && (executiveDirector.getContainer() != executiveDirector.toplevel()))   executiveDirector=((Actor)executiveDirector.getContainer()).getExecutiveDirector();
  _currentPhysicalTime=executiveDirector.getModelTime();
  executiveDirector=((Actor)getContainer()).getExecutiveDirector();
  _transferAllInputs();
  if (!(executiveDirector instanceof PtidesDirector)) {
    if (_eventsInExecution.size() > 0) {
      TimedEvent eventInExecution=_eventsInExecution.getFirst();
      Actor actorToFire=(Actor)eventInExecution.contents;
      Time time=getFinishingTime(actorToFire);
      if (time.equals(_currentPhysicalTime)) {
        return true;
      }
    }
    List eventsToFire=_getNextEventsToFire();
    Time nextRealTimeEventTime=_getNextRealTimeEventTime(eventsToFire,_eventsInExecution);
    TimedEvent event=_executionStrategy.getNextEventToFire(_eventsInExecution,eventsToFire,nextRealTimeEventTime,_currentPhysicalTime);
    if (event != null)     return true;
    if (!nextRealTimeEventTime.equals(Time.POSITIVE_INFINITY))     _fireContainerAt(nextRealTimeEventTime);
    return false;
  }
 else   return super.prefire();
}
Program: 74195
Project: 74195
Buggy source:
/** 
 * Return the corresponding channel in this port for the given receiver. The given receiver may be contained by this port or a port that is connected to this port. 
 * @param receiver A receiver that is contained in this port or connected to another receiver contained in this port.
 * @return The corresponding channel for the receiver.
 * @exception IllegalActionException If the given receiver does not take part in any connections pertaining to this port.
 */
public int getChannelForReceiver(Receiver receiver) throws IllegalActionException {
  Receiver[][] receivers;
  if (isInput()) {
    receivers=getReceivers();
  }
 else {
    receivers=getRemoteReceivers();
  }
  for (int channel=0; channel < receivers.length; channel++) {
    if (receivers[channel] != null) {
      for (int copy=0; copy < receivers[channel].length; copy++) {
        if (receivers[channel][copy] == receiver) {
          return channel;
        }
      }
    }
  }
  throw new IllegalActionException(this,"String_Node_Str" + "String_Node_Str");
}

Fixed version (ground truth):
/** 
 * Return the corresponding channel in this port for the given receiver. The given receiver may be contained by this port or a port that is connected to this port. 
 * @param receiver A receiver that is contained in this port or connected to another receiver contained in this port.
 * @return The corresponding channel for the receiver.
 * @exception IllegalActionException If the given receiver does not take part in any connections pertaining to this port.
 */
public int getChannelForReceiver(Receiver receiver) throws IllegalActionException {
  Receiver[][] receivers;
  if (isInput()) {
    receivers=getReceivers();
  }
 else {
    receivers=getInsideReceivers();
  }
  for (int channel=0; channel < receivers.length; channel++) {
    if (receivers[channel] != null) {
      for (int copy=0; copy < receivers[channel].length; copy++) {
        if (receivers[channel][copy] == receiver) {
          return channel;
        }
      }
    }
  }
  if (!isInput()) {
    receivers=getRemoteReceivers();
    for (int channel=0; channel < receivers.length; channel++) {
      if (receivers[channel] != null) {
        for (int copy=0; copy < receivers[channel].length; copy++) {
          if (receivers[channel][copy] == receiver) {
            return channel;
          }
        }
      }
    }
  }
  throw new IllegalActionException(this,"String_Node_Str" + "String_Node_Str");
}
Program: 74197
Project: 74197
Buggy source:
/** 
 * Read an input string token and write it to the file. If there is no input, do nothing. If the file is not open for writing then open it. If the file does not exist, then create it.  If the file already exists, then query the user for overwrite, unless the <i>append</i> parameter has value <i>true</i>.
 * @exception IllegalActionException If the file cannot be openedor created, or if the user refuses to overwrite an existing file.
 */
public boolean postfire() throws IllegalActionException {
  fileName.update();
  if (input.hasToken(0)) {
    Token token=input.get(0);
    if (_writer == null) {
      boolean appendValue=((BooleanToken)append.getToken()).booleanValue();
      if (!fileName.stringValue().equals("String_Node_Str")) {
        File file=fileName.asFile();
        boolean confirmOverwriteValue=((BooleanToken)confirmOverwrite.getToken()).booleanValue();
        if (file.exists() && !appendValue && confirmOverwriteValue) {
          if (!MessageHandler.yesNoQuestion("String_Node_Str" + file + "String_Node_Str")) {
            throw new IllegalActionException(this,"String_Node_Str");
          }
        }
      }
      _writer=new PrintWriter(fileName.openForWriting(appendValue),true);
    }
    _writeToken(token);
  }
  return super.postfire();
}

Fixed version (ground truth):
/** 
 * Read an input string token and write it to the file. If there is no input, do nothing. If the file is not open for writing then open it. If the file does not exist, then create it.  If the file already exists, then query the user for overwrite, unless the <i>append</i> parameter has value <i>true</i>.
 * @exception IllegalActionException If the file cannot be openedor created, or if the user refuses to overwrite an existing file.
 */
public boolean postfire() throws IllegalActionException {
  fileName.update();
  if (input.hasToken(0)) {
    Token token=input.get(0);
    if (_writer == null) {
      boolean appendValue=((BooleanToken)append.getToken()).booleanValue();
      String fileNameValue=fileName.stringValue();
      if (_previousFileName == null) {
        _previousFileName=fileNameValue;
      }
      if (!fileNameValue.equals("String_Node_Str")) {
        File file=fileName.asFile();
        boolean confirmOverwriteValue=((BooleanToken)confirmOverwrite.getToken()).booleanValue();
        if (file.exists() && !appendValue && confirmOverwriteValue) {
          if (!MessageHandler.yesNoQuestion("String_Node_Str" + file + "String_Node_Str")) {
            throw new IllegalActionException(this,"String_Node_Str");
          }
        }
      }
      _writer=new PrintWriter(fileName.openForWriting(appendValue),true);
    }
    _writeToken(token);
  }
  return super.postfire();
}
Program: 74198
Project: 74198
Buggy source:
/** 
 * Clone the actor into the specified workspace. This calls the base class and then set the filename public member.
 * @param workspace The workspace for the new object.
 * @return A new actor.
 * @exception CloneNotSupportedException If a derived class containsan attribute that cannot be cloned.
 */
public Object clone(Workspace workspace) throws CloneNotSupportedException {
  Publisher newObject=(Publisher)super.clone(workspace);
  try {
    newObject._updatedLinks=false;
  }
 catch (  Throwable throwable) {
    CloneNotSupportedException exception=new CloneNotSupportedException();
    exception.initCause(throwable);
    throw exception;
  }
  return newObject;
}

Fixed version (ground truth):
/** 
 * Clone the actor into the specified workspace. This calls the base class and then set the filename public member.
 * @param workspace The workspace for the new object.
 * @return A new actor.
 * @exception CloneNotSupportedException If a derived class containsan attribute that cannot be cloned.
 */
public Object clone(Workspace workspace) throws CloneNotSupportedException {
  Publisher newObject=(Publisher)super.clone(workspace);
  try {
    newObject._updatedLinks=false;
  }
 catch (  Throwable throwable) {
    CloneNotSupportedException exception=new CloneNotSupportedException();
    exception.initCause(throwable);
    throw exception;
  }
  output.setWidthEquals(input);
  return newObject;
}
Program: 74199
Project: 74199
Buggy source:
/** 
 * Construct a publisher with the specified container and name.
 * @param container The container actor.
 * @param name The name of the actor.
 * @exception IllegalActionException If the actor is not of an acceptableclass for the container.
 * @exception NameDuplicationException If the name coincides withan actor already in the container.
 */
public Publisher(CompositeEntity container,String name) throws IllegalActionException, NameDuplicationException {
  super(container,name);
  channel=new StringParameter(this,"String_Node_Str");
  input=new TypedIOPort(this,"String_Node_Str",true,false);
  input.setMultiport(true);
  output=new TypedIOPort(this,"String_Node_Str",false,true);
  output.setMultiport(true);
  Parameter hide=new SingletonParameter(output,"String_Node_Str");
  hide.setToken(BooleanToken.TRUE);
}

Fixed version (ground truth):
/** 
 * Construct a publisher with the specified container and name.
 * @param container The container actor.
 * @param name The name of the actor.
 * @exception IllegalActionException If the actor is not of an acceptableclass for the container.
 * @exception NameDuplicationException If the name coincides withan actor already in the container.
 */
public Publisher(CompositeEntity container,String name) throws IllegalActionException, NameDuplicationException {
  super(container,name);
  channel=new StringParameter(this,"String_Node_Str");
  input=new TypedIOPort(this,"String_Node_Str",true,false);
  input.setMultiport(true);
  output=new TypedIOPort(this,"String_Node_Str",false,true);
  output.setMultiport(true);
  output.setWidthEquals(input);
  Parameter hide=new SingletonParameter(output,"String_Node_Str");
  hide.setToken(BooleanToken.TRUE);
}
Program: 74201
Project: 74201
Buggy source:
/** 
 * Construct a subscriber with the specified container and name.
 * @param container The container actor.
 * @param name The name of the actor.
 * @exception IllegalActionException If the actor is not of an acceptableclass for the container.
 * @exception NameDuplicationException If the name coincides withan actor already in the container.
 */
public Subscriber(CompositeEntity container,String name) throws IllegalActionException, NameDuplicationException {
  super(container,name);
  channel=new StringParameter(this,"String_Node_Str");
  channel.setExpression("String_Node_Str");
  input=new TypedIOPort(this,"String_Node_Str",true,false);
  input.setMultiport(true);
  output=new TypedIOPort(this,"String_Node_Str",false,true);
  output.setMultiport(true);
  new Parameter(input,"String_Node_Str",BooleanToken.TRUE);
}

Fixed version (ground truth):
/** 
 * Construct a subscriber with the specified container and name.
 * @param container The container actor.
 * @param name The name of the actor.
 * @exception IllegalActionException If the actor is not of an acceptableclass for the container.
 * @exception NameDuplicationException If the name coincides withan actor already in the container.
 */
public Subscriber(CompositeEntity container,String name) throws IllegalActionException, NameDuplicationException {
  super(container,name);
  channel=new StringParameter(this,"String_Node_Str");
  channel.setExpression("String_Node_Str");
  input=new TypedIOPort(this,"String_Node_Str",true,false);
  input.setMultiport(true);
  output=new TypedIOPort(this,"String_Node_Str",false,true);
  output.setMultiport(true);
  output.setWidthEquals(input);
  new Parameter(input,"String_Node_Str",BooleanToken.TRUE);
}
Program: 74202
Project: 74202
Buggy source:
/** 
 * Clone the actor into the specified workspace. This calls the base class and then set the filename public member.
 * @param workspace The workspace for the new object.
 * @return A new actor.
 * @exception CloneNotSupportedException If a derived class containsan attribute that cannot be cloned.
 */
public Object clone(Workspace workspace) throws CloneNotSupportedException {
  Subscriber newObject=(Subscriber)super.clone(workspace);
  try {
    newObject._updatedLinks=false;
  }
 catch (  Throwable throwable) {
    CloneNotSupportedException exception=new CloneNotSupportedException();
    exception.initCause(throwable);
    throw exception;
  }
  return newObject;
}

Fixed version (ground truth):
/** 
 * Clone the actor into the specified workspace. This calls the base class and then set the filename public member.
 * @param workspace The workspace for the new object.
 * @return A new actor.
 * @exception CloneNotSupportedException If a derived class containsan attribute that cannot be cloned.
 */
public Object clone(Workspace workspace) throws CloneNotSupportedException {
  Subscriber newObject=(Subscriber)super.clone(workspace);
  try {
    newObject._updatedLinks=false;
  }
 catch (  Throwable throwable) {
    CloneNotSupportedException exception=new CloneNotSupportedException();
    exception.initCause(throwable);
    throw exception;
  }
  newObject.output.setWidthEquals(newObject.input);
  return newObject;
}
Program: 74203
Project: 74203
Buggy source:
/** 
 * Update the connection to the publisher, if there is one. Note that this method is computationally intensive for large models as it traverses the model by searching up the hierarchy for the nearest opaque container or the top level and then traverses the contained entities. Thus, avoid calling this method except when the model is running.
 * @exception IllegalActionException If creating the linktriggers an exception.
 */
protected void _updateLinks() throws IllegalActionException {
  if (_channel == null) {
    return;
  }
  Publisher publisher=_findPublisher();
  if (_relation != null) {
    input.unlink(_relation);
    _relation=null;
  }
  if (publisher != null) {
    if (publisher._relation == null || !publisher._updatedLinks) {
      publisher._updateLinks();
    }
    _relation=publisher._relation;
    input.liberalLink(_relation);
  }
  Director director=getDirector();
  if (director != null) {
    director.invalidateSchedule();
    director.invalidateResolvedTypes();
  }
  _updatedLinks=true;
}

Fixed version (ground truth):
/** 
 * Update the connection to the publisher, if there is one. Note that this method is computationally intensive for large models as it traverses the model by searching up the hierarchy for the nearest opaque container or the top level and then traverses the contained entities. Thus, avoid calling this method except when the model is running.
 * @exception IllegalActionException If creating the linktriggers an exception.
 */
protected void _updateLinks() throws IllegalActionException {
  if (_channel == null) {
    return;
  }
  Publisher publisher=_findPublisher();
  if (_relation != null) {
    input.unlink(_relation);
    _relation=null;
  }
  if (publisher != null) {
    if (publisher._relation == null || !publisher._updatedLinks) {
      publisher._updateLinks();
    }
    _relation=publisher._relation;
  }
  Director director=getDirector();
  if (director != null) {
    director.invalidateSchedule();
    director.invalidateResolvedTypes();
  }
  _updatedLinks=true;
}
Program: 74204
Project: 74204
Buggy source:
public StatusType ChainTask(int taskId) throws NoRoomException, IllegalActionException {
  Actor task=_tasks.get(taskId);
  Actor currentTask=_taskNames.get(Thread.currentThread().getName());
  Actor newCurrentlyExecutingTask1=scheduleTask(TaskState.suspended,currentTask,null);
  Actor newCurrentlyExecutingTask2=scheduleTask(TaskState.ready_running,task,null);
  Actor newCurrentlyExecutingTask=newCurrentlyExecutingTask2 != null ? newCurrentlyExecutingTask2 : newCurrentlyExecutingTask1;
  reschedule(newCurrentlyExecutingTask);
  return StatusType.E_OK;
}

Fixed version (ground truth):
public StatusType ChainTask(int taskId) throws NoRoomException, IllegalActionException {
  Actor task=_tasks.get(taskId);
  Actor currentTask=_taskNames.get(Thread.currentThread().getName());
  Actor newCurrentlyExecutingTask1=scheduleTask(TaskState.suspended,currentTask,null);
  Actor newCurrentlyExecutingTask2=scheduleTask(TaskState.ready_running,task,null);
  Actor newCurrentlyExecutingTask=newCurrentlyExecutingTask2 != null ? newCurrentlyExecutingTask2 : newCurrentlyExecutingTask1;
  reschedule(newCurrentlyExecutingTask,(CTask)currentTask);
  return StatusType.E_OK;
}
Program: 74205
Project: 74205
Buggy source:
public void terminateTask() throws NoRoomException, IllegalActionException {
  Actor task=_taskNames.get(Thread.currentThread().getName());
  Actor newCurrentlyExecutingTask=scheduleTask(TaskState.suspended,task,null);
  reschedule(newCurrentlyExecutingTask);
}

Fixed version (ground truth):
public void terminateTask() throws NoRoomException, IllegalActionException {
  Actor task=_taskNames.get(Thread.currentThread().getName());
  Actor newCurrentlyExecutingTask=scheduleTask(TaskState.suspended,task,null);
  reschedule(newCurrentlyExecutingTask,(CTask)task);
}
Program: 74206
Project: 74206
Buggy source:
private void reschedule(Actor newTaskInExecution) throws IllegalActionException {
  if (newTaskInExecution != null) {
    output.send(newTaskInExecution,new BooleanToken(true));
    _tasksThatStartedExecuting.add(newTaskInExecution);
    _sendTaskExecutionEvent(newTaskInExecution,ScheduleEventType.START);
  }
  if (_tasksInExecution.size() > 0) {
    getDirector().fireAt(this,getDirector().getModelTime().add(_remainingExecutionTime.get(_tasksInExecution.peek())));
  }
}

Fixed version (ground truth):
private void reschedule(Actor newTaskInExecution,CTask callingTask) throws IllegalActionException {
  if (newTaskInExecution != null) {
    if (callingTask != null)     callingTask.bufferOutput(newTaskInExecution,new BooleanToken(true));
 else     output.send(newTaskInExecution,new BooleanToken(true));
    _tasksThatStartedExecuting.add(newTaskInExecution);
    _sendTaskExecutionEvent(newTaskInExecution,ScheduleEventType.START);
  }
  if (_tasksInExecution.size() > 0) {
    getDirector().fireAt(this,getDirector().getModelTime().add(_remainingExecutionTime.get(_tasksInExecution.peek())));
  }
}
Program: 74207
Project: 74207
Buggy source:
public int activateTask(int taskId) throws NoRoomException, IllegalActionException {
  Actor task=_tasks.get(taskId);
  if (task == null)   return 1;
  Actor newCurrentlyExecutingTask=scheduleTask(TaskState.ready_running,task,null);
  reschedule(newCurrentlyExecutingTask);
  return 0;
}

Fixed version (ground truth):
public int activateTask(int taskId) throws NoRoomException, IllegalActionException {
  Actor task=_tasks.get(taskId);
  Actor caller=_taskNames.get(Thread.currentThread().getName());
  if (task == null)   return 1;
  Actor newCurrentlyExecutingTask=scheduleTask(TaskState.ready_running,task,null);
  reschedule(newCurrentlyExecutingTask,(CTask)caller);
  return 0;
}
Program: 74208
Project: 74208
Buggy source:
/** 
 * release resources if higher priority task is ready
 * @return
 * @throws IllegalActionException 
 * @throws NoRoomException 
 */
public StatusType Schedule() throws NoRoomException, IllegalActionException {
  Actor task=_taskNames.get(Thread.currentThread().getName());
  if (_internalResources.get(task) != null) {
    for (    Actor actor : _taskStates.keySet()) {
      if (_tasksInExecution.size() > 0 && _taskPriorities.get(actor) > _taskPriorities.get(_tasksInExecution.peek()) && _internalResources.get(actor) == _internalResources.get(_tasksInExecution.peek())) {
        Actor newCurrentlyExecutingTask=scheduleTask(TaskState.suspended,task,null);
        reschedule(newCurrentlyExecutingTask);
      }
    }
  }
  getDirector().fireAt(this,getDirector().getModelTime());
  return StatusType.E_OK;
}

Fixed version (ground truth):
/** 
 * release resources if higher priority task is ready
 * @return
 * @throws IllegalActionException 
 * @throws NoRoomException 
 */
public StatusType Schedule() throws NoRoomException, IllegalActionException {
  Actor task=_taskNames.get(Thread.currentThread().getName());
  if (_internalResources.get(task) != null) {
    for (    Actor actor : _taskStates.keySet()) {
      if (_tasksInExecution.size() > 0 && _taskPriorities.get(actor) > _taskPriorities.get(_tasksInExecution.peek()) && _internalResources.get(actor) == _internalResources.get(_tasksInExecution.peek())) {
        Actor newCurrentlyExecutingTask=scheduleTask(TaskState.suspended,task,null);
        reschedule(newCurrentlyExecutingTask,(CTask)task);
      }
    }
  }
  getDirector().fireAt(this,getDirector().getModelTime());
  return StatusType.E_OK;
}
Program: 74209
Project: 74209
Buggy source:
public void fire() throws IllegalActionException {
  System.out.println(this.getName() + "String_Node_Str" + getDirector().getModelTime().toString());
  boolean readInputs=false;
  while (input.hasToken(0)) {
    input.get(0);
    readInputs=true;
  }
  for (  IOPort port : (List<IOPort>)inputPortList()) {
    if (port != input) {
      for (int i=0; i < port.getWidth(); i++) {
        while (port.hasToken(i)) {
          port.get(0);
        }
      }
    }
  }
  if (_waitForMinDelay && !readInputs) {
synchronized (this) {
      while (_inExecution) {
        try {
          this.wait();
        }
 catch (        InterruptedException e) {
          if (_stopRequested) {
            break;
          }
 else {
            e.printStackTrace();
          }
        }
      }
    }
    if (_buffer != null) {
      output.send("String_Node_Str",_buffer);
      _buffer=null;
    }
    _waitForMinDelay=false;
  }
 else   if (readInputs) {
synchronized (this) {
      if (_minDelay.getDoubleValue() >= 0) {
        getDirector().fireAt(this,getDirector().getModelTime().add(_minDelay));
        _waitForMinDelay=true;
      }
      _inExecution=true;
      this.notifyAll();
    }
  }
}

Fixed version (ground truth):
public void fire() throws IllegalActionException {
  System.out.println(this.getName() + "String_Node_Str" + getDirector().getModelTime().toString());
  boolean readInputs=false;
  while (input.hasToken(0)) {
    input.get(0);
    readInputs=true;
  }
  for (  IOPort port : (List<IOPort>)inputPortList()) {
    if (port != input) {
      for (int i=0; i < port.getWidth(); i++) {
        while (port.hasToken(i)) {
          port.get(0);
        }
      }
    }
  }
  if (_waitForMinDelay && !readInputs) {
synchronized (this) {
      while (_inExecution) {
        try {
          this.wait();
        }
 catch (        InterruptedException e) {
          if (_stopRequested) {
            break;
          }
 else {
            e.printStackTrace();
          }
        }
      }
    }
    if (_buffer != null) {
      output.send("String_Node_Str",_buffer);
      _buffer=null;
    }
    for (    Object[] entry : bufferedTokens) {
      CTask task=(CTask)entry[0];
      Token token=(Token)entry[1];
      output.send(task,token);
    }
    bufferedTokens.clear();
    for (    Object[] entry : _bufferOutputValue) {
      IOPort port=(IOPort)entry[0];
      Token token=(Token)entry[1];
      for (int i=0; i < port.getWidth(); i++) {
        port.send(i,token);
      }
    }
    bufferedTokens.clear();
    for (    ResourceToken token : bufferedResourceTokens) {
      output.send(token);
    }
    bufferedResourceTokens.clear();
    _waitForMinDelay=false;
  }
 else   if (readInputs) {
synchronized (this) {
      if (_minDelay.getDoubleValue() >= 0) {
        getDirector().fireAt(this,getDirector().getModelTime().add(_minDelay));
        _waitForMinDelay=true;
      }
      _inExecution=true;
      this.notifyAll();
    }
  }
}
Program: 74210
Project: 74210
Buggy source:
public void setOutputValue(String varName,double value) throws NoRoomException, IllegalActionException {
  for (  IOPort port : (List<IOPort>)outputPortList()) {
    if (port != output) {
      if (port.getName().equals(varName)) {
        for (int i=0; i < port.getWidth(); i++)         port.send(i,new DoubleToken(value));
      }
    }
  }
}

Fixed version (ground truth):
public void setOutputValue(String varName,double value) throws NoRoomException, IllegalActionException {
  for (  IOPort port : (List<IOPort>)outputPortList()) {
    if (port != output) {
      if (port.getName().equals(varName)) {
        _bufferOutputValue.add(new Object[]{port,new DoubleToken(value)});
      }
    }
  }
}
Program: 74211
Project: 74211
Buggy source:
public int waitEvent(int eventMask) throws NoRoomException, IllegalActionException {
  Actor currentTask=_taskNames.get(Thread.currentThread().getName());
  if ((_actorsWithEvents.get(currentTask) != null) && ((_actorsWithEvents.get(currentTask).intValue() & eventMask) != 0)) {
    return 0;
  }
  _actorsWaitingForEvents.put(currentTask,eventMask);
  output.send(new ResourceToken(currentTask,null,TaskState.waiting));
  return 0;
}

Fixed version (ground truth):
public int waitEvent(int eventMask) throws NoRoomException, IllegalActionException {
  Actor currentTask=_taskNames.get(Thread.currentThread().getName());
  if ((_actorsWithEvents.get(currentTask) != null) && ((_actorsWithEvents.get(currentTask).intValue() & eventMask) != 0)) {
    return 0;
  }
  _actorsWaitingForEvents.put(currentTask,eventMask);
  ((CTask)currentTask).bufferOutput(new ResourceToken(currentTask,null,TaskState.waiting));
  return 0;
}
Program: 74212
Project: 74212
Buggy source:
public int setEvent(int taskId,int newEvents) throws NoRoomException, IllegalActionException {
  Actor task=_tasks.get(taskId);
  if (_actorsWithEvents.get(task) == null) {
    _actorsWithEvents.put(task,newEvents);
  }
 else {
    _actorsWithEvents.put(task,_actorsWithEvents.get(task).intValue() | newEvents);
  }
  if ((_actorsWaitingForEvents.get(task) != null) && ((_actorsWaitingForEvents.get(task).intValue() & newEvents) != 0)) {
    output.send(new ResourceToken(task,null,TaskState.ready_running));
  }
  return 0;
}

Fixed version (ground truth):
public int setEvent(int taskId,int newEvents) throws NoRoomException, IllegalActionException {
  Actor task=_tasks.get(taskId);
  Actor currentTask=_taskNames.get(Thread.currentThread().getName());
  if (_actorsWithEvents.get(task) == null) {
    _actorsWithEvents.put(task,newEvents);
  }
 else {
    _actorsWithEvents.put(task,_actorsWithEvents.get(task).intValue() | newEvents);
  }
  if ((_actorsWaitingForEvents.get(task) != null) && ((_actorsWaitingForEvents.get(task).intValue() & newEvents) != 0)) {
    ((CTask)currentTask).bufferOutput(new ResourceToken(task,null,TaskState.ready_running));
  }
  return 0;
}
Program: 74213
Project: 74213
Buggy source:
public void initialize() throws IllegalActionException {
  super.initialize();
  Effigy parentEffigy=Configuration.findEffigy(toplevel());
  try {
    _wrapperEffigy=new PtolemyEffigy(parentEffigy,parentEffigy.uniqueName("String_Node_Str"));
  }
 catch (  NameDuplicationException e) {
    throw new IllegalActionException(this,e,"String_Node_Str" + "String_Node_Str");
  }
}

Fixed version (ground truth):
public void initialize() throws IllegalActionException {
  super.initialize();
  Effigy parentEffigy=GTEntityUtils.findToplevelEffigy(this);
  try {
    _wrapperEffigy=new PtolemyEffigy(parentEffigy,parentEffigy.uniqueName("String_Node_Str"));
  }
 catch (  NameDuplicationException e) {
    throw new IllegalActionException(this,e,"String_Node_Str" + "String_Node_Str");
  }
}
Program: 74215
Project: 74215
Buggy source:
private Tableau _createTableau() throws IllegalActionException {
  NamedObj toplevel=toplevel();
  Effigy effigy=null;
  if (toplevel instanceof Configurer) {
    Configurer configurer=(Configurer)toplevel;
    List<?> list=configurer.entityList();
    if (list.size() == 1) {
      effigy=Configuration.findEffigy((NamedObj)list.get(0));
    }
  }
  if (effigy == null) {
    effigy=Configuration.findEffigy(toplevel);
  }
  if (effigy == null) {
    return null;
  }
  TextEffigy textEffigy;
  try {
    textEffigy=TextEffigy.newTextEffigy(effigy,"String_Node_Str");
  }
 catch (  Exception e) {
    throw new IllegalActionException(this,e,"String_Node_Str" + "String_Node_Str");
  }
  Tableau tableau;
  try {
    tableau=new Tableau(textEffigy,"String_Node_Str");
  }
 catch (  NameDuplicationException e) {
    throw new IllegalActionException(this,e,"String_Node_Str" + "String_Node_Str");
  }
  TextEditor frame=new TextEditor(tableau.getTitle(),textEffigy.getDocument());
  frame.text.setColumns(((IntToken)columnsDisplayed.getToken()).intValue());
  frame.text.setRows(((IntToken)rowsDisplayed.getToken()).intValue());
  tableau.setFrame(frame);
  frame.setTableau(tableau);
  setToken(new ObjectToken(tableau,Tableau.class));
  frame.pack();
  frame.setVisible(true);
  return tableau;
}

Fixed version (ground truth):
private Tableau _createTableau() throws IllegalActionException {
  Effigy effigy=GTEntityUtils.findToplevelEffigy(this);
  TextEffigy textEffigy;
  try {
    textEffigy=TextEffigy.newTextEffigy(effigy,"String_Node_Str");
  }
 catch (  Exception e) {
    throw new IllegalActionException(this,e,"String_Node_Str" + "String_Node_Str");
  }
  Tableau tableau;
  try {
    tableau=new Tableau(textEffigy,"String_Node_Str");
  }
 catch (  NameDuplicationException e) {
    throw new IllegalActionException(this,e,"String_Node_Str" + "String_Node_Str");
  }
  TextEditor frame=new TextEditor(tableau.getTitle(),textEffigy.getDocument());
  frame.text.setColumns(((IntToken)columnsDisplayed.getToken()).intValue());
  frame.text.setRows(((IntToken)rowsDisplayed.getToken()).intValue());
  tableau.setFrame(frame);
  frame.setTableau(tableau);
  setToken(new ObjectToken(tableau,Tableau.class));
  frame.pack();
  frame.setVisible(true);
  return tableau;
}