nus-yam/ex-repair huggingface dataset:
Program: 72363
Project: 72363
Buggy source:
/** 
 * Publish an MQTT message to subscribers listening to the topic.
 * @param topic The topic to which to publish.
 * @param message The message sent to subscribers.
 * @param qos The QoS level of the message. (0: At most once, 1: At least once, 2: Exactly once)
 * @param retain Whether the sever should hold on the message after it has been delivered tocurrent subscribers so that a newly incoming subscriber can receive the message later.
 * @exception MqttException If the publish fails.
 * @exception IllegalActionException
 */
public void publish(String topic,Object message,Integer qos,boolean retain) throws MqttException, IllegalActionException {
  byte[] payload;
  if (_rawBytes) {
    payload=_toJavaBytes(message);
  }
 else {
    payload=((String)message).getBytes();
  }
  MqttMessage mqttMessage=new MqttMessage(payload);
  mqttMessage.setQos(qos);
  mqttMessage.setRetained(retain);
  _mqttClient.publish(topic,mqttMessage);
}

Fixed version (ground truth):
/** 
 * Publish an MQTT message to subscribers listening to the topic.
 * @param topic The topic to which to publish.
 * @param message The message sent to subscribers.
 * @param qos The QoS level of the message. (0: At most once, 1: At least once, 2: Exactly once)
 * @param retain Whether the sever should hold on the message after it has been delivered tocurrent subscribers so that a newly incoming subscriber can receive the message later.
 * @exception MqttException If the publish fails.
 * @exception IllegalActionException
 */
public void publish(String topic,Object message,Integer qos,boolean retain) throws MqttException, IllegalActionException {
  byte[] payload;
  if (_rawBytes) {
    payload=_toJavaBytes(message);
  }
 else {
    payload=((String)message).getBytes(StandardCharsets.UTF_8);
  }
  MqttMessage mqttMessage=new MqttMessage(payload);
  mqttMessage.setQos(qos);
  mqttMessage.setRetained(retain);
  _mqttClient.publish(topic,mqttMessage);
}
Program: 72364
Project: 72364
Buggy source:
/** 
 * Builds and starts the command in a process.
 * @return Returns true, if the process has started and the pipesare initialized.
 */
private boolean startProcess(){
  processBuilder=new ProcessBuilder("String_Node_Str","String_Node_Str",command);
  processBuilder.redirectErrorStream(true);
  processBuilder.redirectOutput(Redirect.PIPE);
  processBuilder.redirectInput(Redirect.PIPE);
  try {
    process=processBuilder.start();
  }
 catch (  IOException e) {
    e.printStackTrace();
    return false;
  }
  out=new BufferedWriter(new OutputStreamWriter(process.getOutputStream()));
  in=new BufferedReader(new InputStreamReader(process.getInputStream()));
  return true;
}

Fixed version (ground truth):
/** 
 * Builds and starts the command in a process.
 * @return Returns true, if the process has started and the pipesare initialized.
 */
private boolean startProcess(){
  processBuilder=new ProcessBuilder("String_Node_Str","String_Node_Str",command);
  processBuilder.redirectErrorStream(true);
  processBuilder.redirectOutput(Redirect.PIPE);
  processBuilder.redirectInput(Redirect.PIPE);
  try {
    process=processBuilder.start();
  }
 catch (  IOException e) {
    e.printStackTrace();
    return false;
  }
  out=new BufferedWriter(new OutputStreamWriter(process.getOutputStream()));
  in=new BufferedReader(new InputStreamReader(process.getInputStream(),StandardCharsets.UTF_8));
  return true;
}
Program: 72366
Project: 72366
Buggy source:
/** 
 * Unsubscribe the associated JavaScript object as a subscriber to the specified address on the event bus.
 * @param address The address on the bus to unsubscribe to, or null tounsubscribe to all addresses.
 * @see #subscribe(String)
 */
public void unsubscribe(final String address){
  if (_subscriptions != null) {
    if (address == null) {
      for (      String toUnsubscribe : _subscriptions.keySet()) {
        MessageConsumer<String> messageConsumer=_subscriptions.get(toUnsubscribe);
        messageConsumer.unregister();
      }
      _subscriptions.clear();
    }
 else {
      MessageConsumer<String> messageConsumer=_subscriptions.get(address);
      if (messageConsumer != null) {
        messageConsumer.unregister();
        _subscriptions.remove(address);
      }
    }
  }
}

Fixed version (ground truth):
/** 
 * Unsubscribe the associated JavaScript object as a subscriber to the specified address on the event bus.
 * @param address The address on the bus to unsubscribe to, or null tounsubscribe to all addresses.
 * @see #subscribe(String)
 */
public void unsubscribe(final String address){
  if (_subscriptions != null) {
    if (address == null) {
      for (      Entry<String,MessageConsumer<String>> entry : _subscriptions.entrySet()) {
        MessageConsumer<String> messageConsumer=entry.getValue();
        messageConsumer.unregister();
      }
      _subscriptions.clear();
    }
 else {
      MessageConsumer<String> messageConsumer=_subscriptions.get(address);
      if (messageConsumer != null) {
        messageConsumer.unregister();
        _subscriptions.remove(address);
      }
    }
  }
}
Program: 72369
Project: 72369
Buggy source:
/** 
 * Invoke the specified function after the specified amount of time and again at multiples of that time. The time will be added to the current time of the director, and fireAt() request will be made of the director. If the director cannot fulfill the request, this method will throw an exception. Note that if you want real-time behavior, then the director's synchronizeToRealTime parameter needs to be set to true.
 * @param function The function to invoke.
 * @param milliseconds The number of milliseconds in the future to invoke it.
 * @return A unique ID for this callback.
 * @exception IllegalActionException If the director cannot respect the request.
 * @see #clearTimeout(Object)
 */
@Override public synchronized Object setInterval(final Runnable function,final int milliseconds) throws IllegalActionException {
  final Integer id=Integer.valueOf(_timeoutCount++);
  final Runnable reschedulingFunction=new Runnable(){
    @Override public void run(){
      _runThenReschedule(function,milliseconds,id);
    }
  }
;
  _setTimeout(reschedulingFunction,milliseconds,id);
  return new Integer(id);
}

Fixed version (ground truth):
/** 
 * Invoke the specified function after the specified amount of time and again at multiples of that time. The time will be added to the current time of the director, and fireAt() request will be made of the director. If the director cannot fulfill the request, this method will throw an exception. Note that if you want real-time behavior, then the director's synchronizeToRealTime parameter needs to be set to true.
 * @param function The function to invoke.
 * @param milliseconds The number of milliseconds in the future to invoke it.
 * @return A unique ID for this callback.
 * @exception IllegalActionException If the director cannot respect the request.
 * @see #clearTimeout(Object)
 */
@Override public synchronized Object setInterval(final Runnable function,final int milliseconds) throws IllegalActionException {
  final Integer id=Integer.valueOf(_timeoutCount++);
  final Runnable reschedulingFunction=new Runnable(){
    @Override public void run(){
      _runThenReschedule(function,milliseconds,id);
    }
  }
;
  _setTimeout(reschedulingFunction,milliseconds,id);
  return Integer.valueOf(id);
}
Program: 72370
Project: 72370
Buggy source:
/** 
 * Invoke the specified function after the specified amount of time. The time will be added to the current time of the director, and fireAt() request will be made of the director. If the director cannot fulfill the request, this method will throw an exception. Note that if you want real-time behavior, then the director's synchronizeToRealTime parameter needs to be set to true.
 * @param function The function to invoke.
 * @param milliseconds The number of milliseconds in the future to invoke it.
 * @return A unique ID for this callback.
 * @exception IllegalActionException If the director cannot respect the request.
 * @see #clearTimeout(Object)
 */
@Override public synchronized Object setTimeout(final Runnable function,final int milliseconds) throws IllegalActionException {
  final Integer id=Integer.valueOf(_timeoutCount++);
  _setTimeout(function,milliseconds,id);
  return new Integer(id);
}

Fixed version (ground truth):
/** 
 * Invoke the specified function after the specified amount of time. The time will be added to the current time of the director, and fireAt() request will be made of the director. If the director cannot fulfill the request, this method will throw an exception. Note that if you want real-time behavior, then the director's synchronizeToRealTime parameter needs to be set to true.
 * @param function The function to invoke.
 * @param milliseconds The number of milliseconds in the future to invoke it.
 * @return A unique ID for this callback.
 * @exception IllegalActionException If the director cannot respect the request.
 * @see #clearTimeout(Object)
 */
@Override public synchronized Object setTimeout(final Runnable function,final int milliseconds) throws IllegalActionException {
  final Integer id=Integer.valueOf(_timeoutCount++);
  _setTimeout(function,milliseconds,id);
  return Integer.valueOf(id);
}
Program: 72372
Project: 72372
Buggy source:
@Override public void dataReceived(XBeeMessage message){
  if (_receiveType == DATA_TYPE.STRING) {
    _currentObj.callMember("String_Node_Str","String_Node_Str",message.getDataString());
  }
 else {
    Buffer buffer=Buffer.buffer(message.getData());
    int size=_sizeOfType(_receiveType);
    int length=buffer.length();
    int numberOfElements=0;
    if (size > 0) {
      numberOfElements=length / size;
    }
    if (numberOfElements == 1) {
      _currentObj.callMember("String_Node_Str","String_Node_Str",_extractFromBuffer(buffer,_receiveType,0));
    }
 else     if (numberOfElements > 1) {
      Object[] result=new Object[numberOfElements];
      int position=0;
      for (int i=0; i < result.length; i++) {
        result[i]=_extractFromBuffer(buffer,_receiveType,position);
        position+=size;
      }
      try {
        _currentObj.callMember("String_Node_Str","String_Node_Str",_actor.toJSArray(result));
      }
 catch (      Exception e) {
        _error("String_Node_Str" + e);
        _currentObj.callMember("String_Node_Str","String_Node_Str",result);
      }
    }
 else     if (numberOfElements <= 0) {
      _error("String_Node_Str" + _receiveType + "String_Node_Str"+ size+ "String_Node_Str"+ buffer.length());
    }
  }
}

Fixed version (ground truth):
@Override public void dataReceived(XBeeMessage message){
  if (_receiveType == DATA_TYPE.STRING) {
    _currentObj.callMember("String_Node_Str","String_Node_Str",message.getDataString());
  }
 else {
    Buffer buffer=Buffer.buffer(message.getData());
    int size=_sizeOfType(_receiveType);
    int length=buffer.length();
    int numberOfElements=0;
    if (size > 0) {
      numberOfElements=length / size;
    }
    if (numberOfElements == 1) {
      _currentObj.callMember("String_Node_Str","String_Node_Str",_extractFromBuffer(buffer,_receiveType,0));
    }
 else     if (numberOfElements > 1) {
      Object[] result=new Object[numberOfElements];
      int position=0;
      for (int i=0; i < result.length; i++) {
        result[i]=_extractFromBuffer(buffer,_receiveType,position);
        position+=size;
      }
      try {
        _currentObj.callMember("String_Node_Str","String_Node_Str",_actor.toJSArray(result));
      }
 catch (      Exception e) {
        _error("String_Node_Str" + e);
        _currentObj.callMember("String_Node_Str","String_Node_Str",result);
      }
    }
 else {
      _error("String_Node_Str" + _receiveType + "String_Node_Str"+ size+ "String_Node_Str"+ buffer.length());
    }
  }
}
Program: 72373
Project: 72373
Buggy source:
/** 
 * Write the RAV information. 
 */
public void writeRAVsInformations(){
  if (_numberOfRAVs > 0) {
    StringBuffer header=new StringBuffer("String_Node_Str");
    int count=_RAVsValues[0].toString().split("String_Node_Str").length;
    for (int i=0; i < count; i++) {
      header.append("String_Node_Str" + i + "String_Node_Str");
    }
    StringBuffer info=new StringBuffer(_date.toString() + "String_Node_Str" + header+ "String_Node_Str"+ _hlaLookAHead+ "String_Node_Str"+ _hlaTimeStep+ "String_Node_Str"+ _stopTime+ "String_Node_Str"+ "String_Node_Str"+ _pRAVsTimes+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ _folRAVsTimes+ "String_Node_Str");
    for (int i=0; i < _numberOfAttributesSubscribedTo; i++) {
      info.append("String_Node_Str" + _nameOfTheAttributesSubscribedTo[i] + "String_Node_Str"+ _RAVsValues[i]+ "String_Node_Str");
    }
    _RAVsValuesFile=_createTextFile("String_Node_Str" + getDisplayName() + "String_Node_Str");
    writeInTextFile(_RAVsValuesFile,String.valueOf(info));
  }
}

Fixed version (ground truth):
/** 
 * Write the RAV information. 
 */
public void writeRAVsInformations(){
  if (_numberOfRAVs > 0) {
    StringBuffer header=new StringBuffer("String_Node_Str");
    int count=_RAVsValues[0].toString().split("String_Node_Str").length;
    for (int i=0; i < count; i++) {
      header.append("String_Node_Str" + i + "String_Node_Str");
    }
    StringBuffer info=new StringBuffer(_date.toString() + "String_Node_Str" + header+ "String_Node_Str"+ _hlaLookAHead+ "String_Node_Str"+ _hlaTimeStep+ "String_Node_Str"+ _stopTime+ "String_Node_Str"+ "String_Node_Str"+ _pRAVsTimes+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ _folRAVsTimes+ "String_Node_Str");
    for (int i=0; i < _numberOfAttributesSubscribedTo; i++) {
      info.append("String_Node_Str" + _nameOfTheAttributesSubscribedTo[i] + "String_Node_Str"+ _RAVsValues[i]+ "String_Node_Str");
    }
    _RAVsValuesFile=_createTextFile("String_Node_Str" + _federateName + "String_Node_Str");
    writeInTextFile(_RAVsValuesFile,String.valueOf(info));
  }
}
Program: 72374
Project: 72374
Buggy source:
/** 
 * Write the UAV information. 
 */
public void writeUAVsInformations(){
  if (_numberOfUAVs > 0) {
    StringBuffer header=new StringBuffer("String_Node_Str");
    int count=String.valueOf(_UAVsValues[0]).split("String_Node_Str").length;
    for (int i=0; i < count; i++) {
      header.append("String_Node_Str" + i + "String_Node_Str");
    }
    StringBuffer info=new StringBuffer(_date.toString() + "String_Node_Str" + header+ "String_Node_Str"+ _hlaLookAHead+ "String_Node_Str"+ _hlaTimeStep+ "String_Node_Str"+ _stopTime+ "String_Node_Str"+ "String_Node_Str"+ _preUAVsTimes+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ _pUAVsTimes+ "String_Node_Str");
    for (int i=0; i < _numberOfAttributesToPublish; i++) {
      info.append("String_Node_Str" + _nameOfTheAttributesToPublish[i] + "String_Node_Str"+ _UAVsValues[i]+ "String_Node_Str");
    }
    _UAVsValuesFile=_createTextFile("String_Node_Str" + getDisplayName() + "String_Node_Str");
    writeInTextFile(_UAVsValuesFile,String.valueOf(info));
  }
}

Fixed version (ground truth):
/** 
 * Write the UAV information. 
 */
public void writeUAVsInformations(){
  if (_numberOfUAVs > 0) {
    StringBuffer header=new StringBuffer("String_Node_Str");
    int count=String.valueOf(_UAVsValues[0]).split("String_Node_Str").length;
    for (int i=0; i < count; i++) {
      header.append("String_Node_Str" + i + "String_Node_Str");
    }
    StringBuffer info=new StringBuffer(_date.toString() + "String_Node_Str" + header+ "String_Node_Str"+ _hlaLookAHead+ "String_Node_Str"+ _hlaTimeStep+ "String_Node_Str"+ _stopTime+ "String_Node_Str"+ "String_Node_Str"+ _preUAVsTimes+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ _pUAVsTimes+ "String_Node_Str");
    for (int i=0; i < _numberOfAttributesToPublish; i++) {
      info.append("String_Node_Str" + _nameOfTheAttributesToPublish[i] + "String_Node_Str"+ _UAVsValues[i]+ "String_Node_Str");
    }
    _UAVsValuesFile=_createTextFile("String_Node_Str" + _federateName + "String_Node_Str");
    writeInTextFile(_UAVsValuesFile,String.valueOf(info));
  }
}
Program: 72375
Project: 72375
Buggy source:
/** 
 * Write information in a txt file.
 * @param data The information you want to write.
 * @param file The file in which you want to write.
 * @return Return true if the information was successfully written in the file.
 */
public boolean writeInTextFile(File file,String data){
  boolean noExceptionOccured=true;
  BufferedWriter writer=null;
  try {
    writer=new BufferedWriter(new FileWriter(file));
    writer.write(data);
    writer.newLine();
    writer.flush();
  }
 catch (  Exception e) {
    noExceptionOccured=false;
  }
 finally {
    if (writer != null) {
      try {
        writer.close();
      }
 catch (      IOException e) {
        System.out.println("String_Node_Str");
      }
    }
  }
  return noExceptionOccured;
}

Fixed version (ground truth):
/** 
 * Write information in a txt file.
 * @param data The information you want to write.
 * @param file The file in which you want to write.
 * @return Return true if the information was successfully written in the file.
 */
public boolean writeInTextFile(File file,String data){
  boolean noExceptionOccured=true;
  BufferedWriter writer=null;
  try {
    writer=new BufferedWriter(new FileWriter(file,true));
    writer.write(data);
    writer.newLine();
    writer.flush();
  }
 catch (  Exception e) {
    noExceptionOccured=false;
  }
 finally {
    if (writer != null) {
      try {
        writer.close();
      }
 catch (      IOException e) {
        System.out.println("String_Node_Str");
      }
    }
  }
  return noExceptionOccured;
}
Program: 72376
Project: 72376
Buggy source:
/** 
 * Get the MAC (Media Access Control) address of the first non-loopback, non-multicast address.
 * @return the MAC address
 * @exception SocketException If thrown while finding the address.
 */
public String getMacAddress() throws SocketException {
  InetAddress address=_getUsefulAddress();
  NetworkInterface networkInterface=NetworkInterface.getByInetAddress(address);
  byte[] macAddress=networkInterface.getHardwareAddress();
  StringBuffer buffer=new StringBuffer();
  for (int i=0; i < macAddress.length; i++) {
    buffer.append(String.format("String_Node_Str",macAddress[i],(i < macAddress.length - 1) ? "String_Node_Str" : "String_Node_Str"));
  }
  return macAddress.toString();
}

Fixed version (ground truth):
/** 
 * Get the MAC (Media Access Control) address of the first non-loopback, non-multicast address.
 * @return the MAC address
 * @exception SocketException If thrown while finding the address.
 */
public String getMacAddress() throws SocketException {
  InetAddress address=_getUsefulAddress();
  NetworkInterface networkInterface=NetworkInterface.getByInetAddress(address);
  byte[] macAddress=networkInterface.getHardwareAddress();
  StringBuffer buffer=new StringBuffer();
  for (int i=0; i < macAddress.length; i++) {
    buffer.append(String.format("String_Node_Str",macAddress[i],(i < macAddress.length - 1) ? "String_Node_Str" : "String_Node_Str"));
  }
  return buffer.toString();
}
Program: 72377
Project: 72377
Buggy source:
/** 
 * Execute the nmap command.  Nmap finds IP addresses, names and MAC addresses on the local area network.  The nmap program requires separate installation on Mac and Windows; please see: https://nmap.org/
 * @param baseIP The IP address of the host minus the subnet portion.
 */
private void _nmap(String baseIP){
  try {
    String command=_nmapCommand + baseIP + "String_Node_Str";
    if (_debugging) {
      System.out.println("String_Node_Str" + command);
    }
    Process process=Runtime.getRuntime().exec(command);
    BufferedReader stdOut=null;
    try {
      stdOut=new BufferedReader(new InputStreamReader(process.getInputStream()));
      String line;
      while ((line=stdOut.readLine()) != null) {
        if (line.startsWith("String_Node_Str")) {
          _readDeviceNmap(line,stdOut);
        }
      }
    }
  finally {
      if (stdOut != null) {
        stdOut.close();
      }
    }
  }
 catch (  IOException e) {
    System.err.println("String_Node_Str" + _nmapCommand);
  }
}

Fixed version (ground truth):
/** 
 * Execute the nmap command.  Nmap finds IP addresses, names and MAC addresses on the local area network.  The nmap program requires separate installation on Mac and Windows; please see: https://nmap.org/
 * @param baseIP The IP address of the host minus the subnet portion.
 */
private void _nmap(String baseIP){
  try {
    String command=_nmapCommand + baseIP + "String_Node_Str";
    if (_debugging) {
      System.out.println("String_Node_Str" + command);
    }
    Process process=Runtime.getRuntime().exec(command);
    BufferedReader stdOut=null;
    try {
      stdOut=new BufferedReader(new InputStreamReader(process.getInputStream(),"String_Node_Str"));
      String line;
      while ((line=stdOut.readLine()) != null) {
        if (line.startsWith("String_Node_Str")) {
          _readDeviceNmap(line,stdOut);
        }
      }
    }
  finally {
      if (stdOut != null) {
        stdOut.close();
      }
    }
  }
 catch (  IOException e) {
    System.err.println("String_Node_Str" + _nmapCommand);
  }
}
Program: 72378
Project: 72378
Buggy source:
/** 
 * Execute the arp command on a Windows platform.  The arp command finds MAC addresses for devices on the local area network. The arp command should follow a ping sweep to get the most up-to-date information and to screen out devices that are not accessible at the moment (which may be cached in the arp cache).
 */
private void _arpWindows(){
  if (_ipMap.size() == 0) {
    System.err.println("String_Node_Str" + _pingWindowsCommand + "String_Node_Str");
  }
  try {
    Process process=Runtime.getRuntime().exec(_arpCommand);
    BufferedReader stdOut=null;
    try {
      stdOut=new BufferedReader(new InputStreamReader(process.getInputStream()));
      String line;
      int index;
      JSONObject object;
      while ((line=stdOut.readLine()) != null) {
        for (        String key : _ipMap.keySet()) {
          object=_ipMap.get(key);
          index=line.indexOf(object.getString("String_Node_Str"));
          if (index != -1) {
            if (index != 2) {
              object.put("String_Node_Str","String_Node_Str");
            }
 else {
              object.put("String_Node_Str",line.substring(index + 22,index + 39));
            }
            _ipMap.put(key,object);
          }
        }
      }
    }
  finally {
      if (stdOut != null) {
        stdOut.close();
      }
    }
  }
 catch (  IOException e) {
    System.err.println("String_Node_Str" + _arpCommand);
  }
catch (  JSONException e2) {
    System.err.println("String_Node_Str");
  }
}

Fixed version (ground truth):
/** 
 * Execute the arp command on a Windows platform.  The arp command finds MAC addresses for devices on the local area network. The arp command should follow a ping sweep to get the most up-to-date information and to screen out devices that are not accessible at the moment (which may be cached in the arp cache).
 */
private void _arpWindows(){
  if (_ipMap.size() == 0) {
    System.err.println("String_Node_Str" + _pingWindowsCommand + "String_Node_Str");
  }
  try {
    Process process=Runtime.getRuntime().exec(_arpCommand);
    BufferedReader stdOut=null;
    try {
      stdOut=new BufferedReader(new InputStreamReader(process.getInputStream(),"String_Node_Str"));
      String line;
      int index;
      JSONObject object;
      while ((line=stdOut.readLine()) != null) {
        for (        String key : _ipMap.keySet()) {
          object=_ipMap.get(key);
          index=line.indexOf(object.getString("String_Node_Str"));
          if (index != -1) {
            if (index != 2) {
              object.put("String_Node_Str","String_Node_Str");
            }
 else {
              object.put("String_Node_Str",line.substring(index + 22,index + 39));
            }
            _ipMap.put(key,object);
          }
        }
      }
    }
  finally {
      if (stdOut != null) {
        stdOut.close();
      }
    }
  }
 catch (  IOException e) {
    System.err.println("String_Node_Str" + _arpCommand);
  }
catch (  JSONException e2) {
    System.err.println("String_Node_Str");
  }
}
Program: 72382
Project: 72382
Buggy source:
/** 
 * Write some information in a file.
 * @param file The file were the information is going to be written.
 * @param data The information that is going to be written.
 */
private static void _writeInFile(File file,String data){
  try {
    BufferedWriter writer=new BufferedWriter(new FileWriter(file));
    writer.write(data);
    writer.flush();
    writer.close();
  }
 catch (  Exception e) {
    System.out.println("String_Node_Str");
  }
}

Fixed version (ground truth):
/** 
 * Write some information in a file.
 * @param file The file were the information is going to be written.
 * @param data The information that is going to be written.
 */
private static void _writeInFile(File file,String data){
  try {
    FileWriter fWriter=new FileWriter(file);
    BufferedWriter writer=new BufferedWriter(fWriter);
    writer.write(data);
    writer.flush();
    writer.close();
    fWriter.close();
  }
 catch (  Exception e) {
    System.out.println("String_Node_Str");
  }
}
Program: 72384
Project: 72384
Buggy source:
/** 
 * Find a parameter value from a file.
 * @param file The file to be read
 * @param propertyLine The property line to be found
 * @param type The type of the data. 0 for String, 1 for int, 2 for float.
 * @return The parameter value.
 */
public static String findParameterValue(File file,String propertyLine,int type) throws IllegalActionException {
  try {
    ArrayList<String> fileContent=convertFileToString(file);
    String value="String_Node_Str";
    for (    String s : fileContent) {
      if (s.contains(propertyLine)) {
        try {
          value=s.substring(s.lastIndexOf("String_Node_Str") + 7,s.lastIndexOf("String_Node_Str"));
          if (type == 1) {
            Integer.parseInt(value);
          }
 else           if (type == 2) {
            Float.parseFloat(value);
          }
          break;
        }
 catch (        Exception e) {
          value="String_Node_Str";
        }
      }
    }
    return value;
  }
 catch (  IOException ex) {
    throw new IllegalActionException(null,ex,"String_Node_Str" + file + "String_Node_Str"+ propertyLine);
  }
}

Fixed version (ground truth):
/** 
 * Find a parameter value from a file.
 * @param file The file to be read
 * @param propertyLine The property line to be found
 * @return The parameter value.
 */
public static String findParameterValue(File file,String propertyLine) throws IllegalActionException {
  try {
    ArrayList<String> fileContent=convertFileToString(file);
    String value="String_Node_Str";
    for (    String s : fileContent) {
      if (s.contains(propertyLine)) {
        try {
          value=s.substring(s.lastIndexOf("String_Node_Str") + 7,s.lastIndexOf("String_Node_Str"));
        }
 catch (        Exception e) {
          value="String_Node_Str";
        }
      }
    }
    return value;
  }
 catch (  IOException ex) {
    throw new IllegalActionException(null,ex,"String_Node_Str" + file + "String_Node_Str"+ propertyLine);
  }
}
Program: 72385
Project: 72385
Buggy source:
/** 
 * Associate the object file with a file in the computer, creating it, if it doesn't already exist.
 * @param name the name to of the file
 */
private File _createTextFile(String name,String header){
  if (_testsFolder != null) {
    name=_testsFolder + "String_Node_Str" + name;
    if (name.equals(null) || name.length() < 3) {
      System.out.println("String_Node_Str");
      return null;
    }
 else {
      if (!(name.endsWith("String_Node_Str") || name.endsWith("String_Node_Str"))) {
        name=name.concat("String_Node_Str");
      }
      try {
        File file=new File(name);
        boolean verify=false;
        if (!file.exists()) {
          verify=file.createNewFile();
          writeInTextFile(file,header);
        }
 else {
          verify=true;
        }
        if (!verify) {
          throw new Exception();
        }
        System.out.println(name);
        return file;
      }
 catch (      Exception e) {
        System.out.println("String_Node_Str");
        return null;
      }
    }
  }
 else {
    return null;
  }
}

Fixed version (ground truth):
/** 
 * Associate the object file with a file in the computer, creating it, if it doesn't already exist.
 * @param name the name to of the file
 */
private File _createTextFile(String name,String header){
  if (_testsFolder != null) {
    name=_testsFolder + "String_Node_Str" + name;
    if (name == null || name.length() < 3) {
      System.out.println("String_Node_Str");
      return null;
    }
 else {
      if (!(name.endsWith("String_Node_Str") || name.endsWith("String_Node_Str"))) {
        name=name.concat("String_Node_Str");
      }
      try {
        File file=new File(name);
        boolean verify=false;
        if (!file.exists()) {
          verify=file.createNewFile();
          writeInTextFile(file,header);
        }
 else {
          verify=true;
        }
        if (!verify) {
          throw new Exception();
        }
        System.out.println(name);
        return file;
      }
 catch (      Exception e) {
        System.out.println("String_Node_Str");
        return null;
      }
    }
  }
 else {
    return null;
  }
}
Program: 72389
Project: 72389
Buggy source:
/** 
 * Write information in a txt file.
 * @param data The information you want to write.
 * @param file The file in which you want to write.
 * @return Return true if the information was successfully written in the file.
 */
public boolean writeInTextFile(File file,String data){
  try {
    BufferedWriter writer=new BufferedWriter(new FileWriter(file,true));
    writer.write(data);
    writer.newLine();
    writer.flush();
    writer.close();
    return true;
  }
 catch (  Exception e) {
    return false;
  }
}

Fixed version (ground truth):
/** 
 * Write information in a txt file.
 * @param data The information you want to write.
 * @param file The file in which you want to write.
 * @return Return true if the information was successfully written in the file.
 */
public boolean writeInTextFile(File file,String data){
  try {
    FileWriter fWriter=new FileWriter(file);
    BufferedWriter writer=new BufferedWriter(fWriter);
    writer.write(data);
    writer.newLine();
    writer.flush();
    writer.close();
    fWriter.close();
    return true;
  }
 catch (  Exception e) {
    return false;
  }
}
Program: 72391
Project: 72391
Buggy source:
/** 
 * Each tokens, received in the input port, are transmitted to the  {@link HlaManager} for a publication to the HLA/CERTI Federation.
 */
@Override public void fire() throws IllegalActionException {
  for (int i=0; i < input.getWidth(); ++i) {
    if (input.hasToken(i)) {
      Token in=input.get(i);
      _hlaManager.updateHlaAttribute(this,in,input.sourcePortList().get(i).getContainer().getName());
      if (_debugging) {
        _debug(this.getDisplayName() + "String_Node_Str" + in.toString()+ "String_Node_Str"+ this.getName()+ "String_Node_Str"+ _hlaManager.getDisplayName()+ "String_Node_Str");
      }
    }
  }
}

Fixed version (ground truth):
/** 
 * Each tokens, received in the input port, are transmitted to the  {@link HlaManager} for a publication to the HLA/CERTI Federation.
 */
@Override public void fire() throws IllegalActionException {
  super.fire();
  for (int i=0; i < input.getWidth(); ++i) {
    if (input.hasToken(i)) {
      Token in=input.get(i);
      _hlaManager.updateHlaAttribute(this,in,input.sourcePortList().get(i).getContainer().getName());
      if (_debugging) {
        _debug(this.getDisplayName() + "String_Node_Str" + in.toString()+ "String_Node_Str"+ this.getName()+ "String_Node_Str"+ _hlaManager.getDisplayName()+ "String_Node_Str");
      }
    }
  }
}
Program: 72392
Project: 72392
Buggy source:
/** 
 * Check if there is one and only one   {@link HlaManager} deployed in thePtolemy model.
 * @exception IllegalActionException If there is zero or more than one{@link HlaManager} per Ptolemy model.
 */
@Override public void initialize() throws IllegalActionException {
  super.initialize();
  CompositeActor ca=(CompositeActor)this.getContainer();
  List<HlaManager> hlaManagers=null;
  while (ca != null) {
    hlaManagers=ca.attributeList(HlaManager.class);
    if (hlaManagers.size() < 1) {
      ca=(CompositeActor)ca.getContainer();
    }
 else {
      break;
    }
  }
  if (hlaManagers.size() > 1) {
    throw new IllegalActionException(this,"String_Node_Str");
  }
 else   if (hlaManagers.size() < 1) {
    throw new IllegalActionException(this,"String_Node_Str");
  }
}

Fixed version (ground truth):
/** 
 * Check if there is one and only one   {@link HlaManager} deployed in thePtolemy model.
 * @exception IllegalActionException If there is zero or more than one{@link HlaManager} per Ptolemy model.
 */
@Override public void initialize() throws IllegalActionException {
  super.initialize();
  CompositeActor ca=(CompositeActor)this.getContainer();
  List<HlaManager> hlaManagers=null;
  while (ca != null) {
    hlaManagers=ca.attributeList(HlaManager.class);
    if (hlaManagers.size() < 1) {
      ca=(CompositeActor)ca.getContainer();
    }
 else {
      break;
    }
  }
  if (hlaManagers == null || hlaManagers.size() < 1) {
    throw new IllegalActionException(this,"String_Node_Str");
  }
 else {
    if (hlaManagers.size() > 1)     throw new IllegalActionException(this,"String_Node_Str");
  }
}
Program: 72394
Project: 72394
Buggy source:
/** 
 * Override the base class to not delegate to the container.
 * @return True if change requests are being deferred.
 * @see #setDeferringChangeRequests(boolean)
 * @see Changeable
 */
@Override public boolean isDeferringChangeRequests(){
  return _deferChangeRequests;
}

Fixed version (ground truth):
/** 
 * Override the base class to not delegate up the hierarchy and to indicate only whether this composite is locally deferring change requests. Note that even if this returns false, change requests may be deferred because the container is deferring change requests.
 * @return True if change requests are being deferred.
 * @see #setDeferringChangeRequests(boolean)
 * @see Changeable
 */
@Override public boolean isDeferringChangeRequests(){
  return _deferChangeRequests;
}
Program: 72395
Project: 72395
Buggy source:
/** 
 * Override the base class to not delegate up the hierarchy.
 * @param change The requested change.
 * @see #executeChangeRequests()
 * @see #setDeferringChangeRequests(boolean)
 * @see Changeable
 */
@Override public void requestChange(ChangeRequest change){
  List<ChangeRequest> copy=null;
synchronized (_changeLock) {
    if (_changeRequests == null) {
      _changeRequests=new LinkedList<ChangeRequest>();
    }
    _changeRequests.add(change);
    if (!_deferChangeRequests) {
      copy=_copyChangeRequestList();
    }
  }
  if (copy != null) {
    _executeChangeRequests(copy);
  }
}

Fixed version (ground truth):
/** 
 * Override the base class to delegate up the hierarchy only if this composite is not deferring change requests, but the the container is. Otherwise, if this composite is deferring change requests, the defer the change, regardless of what the container is doing. Otherwise, execute the change.
 * @param change The requested change.
 * @see #executeChangeRequests()
 * @see #setDeferringChangeRequests(boolean)
 * @see Changeable
 */
@Override public void requestChange(ChangeRequest change){
  NamedObj container=getContainer();
  if (container != null && !_deferChangeRequests && container.isDeferringChangeRequests()) {
    super.requestChange(change);
    return;
  }
  List<ChangeRequest> copy=null;
synchronized (_changeLock) {
    if (_changeRequests == null) {
      _changeRequests=new LinkedList<ChangeRequest>();
    }
    _changeRequests.add(change);
    if (!_deferChangeRequests) {
      copy=_copyChangeRequestList();
    }
  }
  if (copy != null) {
    _executeChangeRequests(copy);
  }
}
Program: 72397
Project: 72397
Buggy source:
/** 
 * Run all the models opened in different threads, waiting for the initialization of the current one to start executing a following one.
 * @throws KernelException
 */
private void _runModels() throws KernelException {
  Iterator<NamedObj> models=super.models().iterator();
  NamedObj model=null;
  Manager manager;
  _wait=false;
  while (models.hasNext()) {
    if (!_wait) {
      model=(NamedObj)models.next();
      if (model instanceof CompositeActor) {
        CompositeActor actor=(CompositeActor)model;
        if (_statistics) {
          System.out.println("String_Node_Str" + model.getFullName());
          System.out.println(((CompositeEntity)model).statistics(null));
        }
        manager=actor.getManager();
        if (manager == null) {
          manager=new Manager(actor.workspace(),"String_Node_Str");
          actor.setManager(manager);
        }
        manager.addExecutionListener(this);
        this.setActiveCount(this.getActiveCount() + 1);
        _wait=true;
        manager.startRun();
        System.out.println("String_Node_Str" + model.getDisplayName() + "String_Node_Str");
      }
    }
 else {
      System.out.println("String_Node_Str" + model.getDisplayName() + "String_Node_Str");
      _sleep(50);
    }
  }
}

Fixed version (ground truth):
/** 
 * Run all the models opened in different threads, waiting for the initialization of the current one to start executing a following one.
 * @exception KernelException
 */
private void _runModels() throws KernelException {
  Iterator<NamedObj> models=super.models().iterator();
  NamedObj model=null;
  Manager manager;
  _wait=false;
  while (models.hasNext()) {
    if (!_wait) {
      model=(NamedObj)models.next();
      if (model instanceof CompositeActor) {
        CompositeActor actor=(CompositeActor)model;
        if (_statistics) {
          System.out.println("String_Node_Str" + model.getFullName());
          System.out.println(((CompositeEntity)model).statistics(null));
        }
        manager=actor.getManager();
        if (manager == null) {
          manager=new Manager(actor.workspace(),"String_Node_Str");
          actor.setManager(manager);
        }
        manager.addExecutionListener(this);
        this.setActiveCount(this.getActiveCount() + 1);
        _wait=true;
        manager.startRun();
        System.out.println("String_Node_Str" + model.getDisplayName() + "String_Node_Str");
      }
    }
 else {
      System.out.println("String_Node_Str" + model.getDisplayName() + "String_Node_Str");
      _sleep(50);
    }
  }
}
Program: 72398
Project: 72398
Buggy source:
/** 
 * Get hlaNextPointInTime in HLA to advance to when TAR is used. hlaNextPointInTime = hlaCurrentTime + Ts.
 * @return next point in time to advance to.
 * @throws IllegalActionException if hlaTimeStep is NULL.
 */
private Time _getHlaNextPointInTime() throws IllegalActionException {
  Double time=_getHlaCurrentTime().add(_hlaTimeStep).getDoubleValue();
  time=_roundDoubles(time);
  return _convertToPtolemyTime(new CertiLogicalTime(time));
}

Fixed version (ground truth):
/** 
 * Get hlaNextPointInTime in HLA to advance to when TAR is used. hlaNextPointInTime = hlaCurrentTime + Ts.
 * @return next point in time to advance to.
 * @exception IllegalActionException if hlaTimeStep is NULL.
 */
private Time _getHlaNextPointInTime() throws IllegalActionException {
  Double time=_getHlaCurrentTime().add(_hlaTimeStep).getDoubleValue();
  time=_roundDoubles(time);
  return _convertToPtolemyTime(new CertiLogicalTime(time));
}
Program: 72399
Project: 72399
Buggy source:
/** 
 * Make a conversion from certi logical time to ptolemy time
 * @param ct certi logical time
 * @return ptolemy time
 * @throws IllegalActionException
 */
private Time _convertToPtolemyTime(CertiLogicalTime ct) throws IllegalActionException {
  return new Time(_director,_roundDoubles(ct.getTime() / _hlaTimeUnitValue));
}

Fixed version (ground truth):
/** 
 * Make a conversion from certi logical time to ptolemy time
 * @param ct certi logical time
 * @return ptolemy time
 * @exception IllegalActionException
 */
private Time _convertToPtolemyTime(CertiLogicalTime ct) throws IllegalActionException {
  return new Time(_director,_roundDoubles(ct.getTime() / _hlaTimeUnitValue));
}
Program: 72400
Project: 72400
Buggy source:
/** 
 * Initialize Federate's timing properties provided by the user.
 * @param startTime The start time of the Federate logical clock.
 * @param timeStep The time step of the Federate.
 * @param lookAHead The contract value used by HLA/CERTI to synchronizethe Federates and to order TSO events.
 * @throws IllegalActionException
 */
public void initializeTimeValues(Double startTime,Double lookAHead) throws IllegalActionException {
  if (lookAHead <= 0) {
    throw new IllegalActionException(null,null,null,"String_Node_Str");
  }
  logicalTimeHLA=new CertiLogicalTime(startTime);
  effectiveLookAHead=new CertiLogicalTimeInterval(lookAHead * _hlaTimeUnitValue);
  if (_debugging) {
    _debug("String_Node_Str" + effectiveLookAHead.toString());
  }
  timeAdvanceGrant=false;
}

Fixed version (ground truth):
/** 
 * Initialize Federate's timing properties provided by the user.
 * @param startTime The start time of the Federate logical clock.
 * @param timeStep The time step of the Federate.
 * @param lookAHead The contract value used by HLA/CERTI to synchronizethe Federates and to order TSO events.
 * @exception IllegalActionException
 */
public void initializeTimeValues(Double startTime,Double lookAHead) throws IllegalActionException {
  if (lookAHead <= 0) {
    throw new IllegalActionException(null,null,null,"String_Node_Str");
  }
  logicalTimeHLA=new CertiLogicalTime(startTime);
  effectiveLookAHead=new CertiLogicalTimeInterval(lookAHead * _hlaTimeUnitValue);
  if (_debugging) {
    _debug("String_Node_Str" + effectiveLookAHead.toString());
  }
  timeAdvanceGrant=false;
}
Program: 72402
Project: 72402
Buggy source:
/** 
 * Indicate if the HLA publisher actor uses the CERTI message buffer API.
 * @return true if the HLA publisher actor uses the CERTI message and false ifit doesn't.
 * @throws IllegalActionException
 */
public boolean useCertiMessageBuffer() throws IllegalActionException {
  return _useCertiMessageBuffer;
}

Fixed version (ground truth):
/** 
 * Indicate if the HLA publisher actor uses the CERTI message buffer API.
 * @return true if the HLA publisher actor uses the CERTI message and false ifit doesn't.
 * @exception IllegalActionException
 */
public boolean useCertiMessageBuffer() throws IllegalActionException {
  return _useCertiMessageBuffer;
}
Program: 72403
Project: 72403
Buggy source:
/** 
 * Indicate if the HLA subscriber actor uses the CERTI message buffer API.
 * @return true if the HLA publisher actor uses the CERTI message and false ifit doesn't.
 * @throws IllegalActionException
 */
public boolean useCertiMessageBuffer() throws IllegalActionException {
  return _useCertiMessageBuffer;
}

Fixed version (ground truth):
/** 
 * Indicate if the HLA subscriber actor uses the CERTI message buffer API.
 * @return true if the HLA publisher actor uses the CERTI message and false ifit doesn't.
 * @exception IllegalActionException
 */
public boolean useCertiMessageBuffer() throws IllegalActionException {
  return _useCertiMessageBuffer;
}
Program: 72404
Project: 72404
Buggy source:
/** 
 * Pick k random cluster centers given the range of input data. This implementation uses the Random Partition method for initialization, that is, it assigns a cluster at random to each data point, and computes initial cluster centers.
 * @throws IllegalActionException
 */
private void _initializeClusterCenters() throws IllegalActionException {
  Random clusterIndex=new Random();
  _clusterAssignment=new int[_trainingData.length];
  for (int k=0; k < _trainingData.length; k++) {
    _clusterAssignment[k]=clusterIndex.nextInt(_numClusters);
  }
  _updateClusterCenters();
}

Fixed version (ground truth):
/** 
 * Pick k random cluster centers given the range of input data. This implementation uses the Random Partition method for initialization, that is, it assigns a cluster at random to each data point, and computes initial cluster centers.
 * @exception IllegalActionException
 */
private void _initializeClusterCenters() throws IllegalActionException {
  Random clusterIndex=new Random();
  _clusterAssignment=new int[_trainingData.length];
  for (int k=0; k < _trainingData.length; k++) {
    _clusterAssignment[k]=clusterIndex.nextInt(_numClusters);
  }
  _updateClusterCenters();
}
Program: 72405
Project: 72405
Buggy source:
/** 
 * Compute the new cluster centers, that is, the centroid of the data points that belong to this cluster. For the Euclidean distance measure, this is simply the average of the points in the cluster.
 * @throws IllegalActionException
 */
private void _updateClusterCenters() throws IllegalActionException {
  _clusterCenters.clear();
switch (_distanceMeasure) {
case EUCLIDEAN:
    double[][] newClusterCenters=new double[_numClusters][_featureLength];
  int[] samplesInCluster=new int[_numClusters];
for (int i=0; i < _trainingData.length; i++) {
  for (int j=0; j < _featureLength; j++) {
    newClusterCenters[_clusterAssignment[i]][j]+=_trainingData[i][j];
  }
  samplesInCluster[_clusterAssignment[i]]++;
}
for (int i=0; i < _numClusters; i++) {
for (int j=0; j < _featureLength; j++) {
  if (samplesInCluster[i] > 0) {
    newClusterCenters[i][j]/=samplesInCluster[i];
  }
}
}
for (int i=0; i < _numClusters; i++) {
if (_featureLength > 1) {
_clusterCenters.add(newClusterCenters[i]);
}
 else {
_clusterCenters.add(newClusterCenters[i][0]);
}
}
break;
default :
throw new IllegalActionException(this,"String_Node_Str");
}
}

Fixed version (ground truth):
/** 
 * Compute the new cluster centers, that is, the centroid of the data points that belong to this cluster. For the Euclidean distance measure, this is simply the average of the points in the cluster.
 * @exception IllegalActionException
 */
private void _updateClusterCenters() throws IllegalActionException {
  _clusterCenters.clear();
switch (_distanceMeasure) {
case EUCLIDEAN:
    double[][] newClusterCenters=new double[_numClusters][_featureLength];
  int[] samplesInCluster=new int[_numClusters];
for (int i=0; i < _trainingData.length; i++) {
  for (int j=0; j < _featureLength; j++) {
    newClusterCenters[_clusterAssignment[i]][j]+=_trainingData[i][j];
  }
  samplesInCluster[_clusterAssignment[i]]++;
}
for (int i=0; i < _numClusters; i++) {
for (int j=0; j < _featureLength; j++) {
  if (samplesInCluster[i] > 0) {
    newClusterCenters[i][j]/=samplesInCluster[i];
  }
}
}
for (int i=0; i < _numClusters; i++) {
if (_featureLength > 1) {
_clusterCenters.add(newClusterCenters[i]);
}
 else {
_clusterCenters.add(newClusterCenters[i][0]);
}
}
break;
default :
throw new IllegalActionException(this,"String_Node_Str");
}
}
Program: 72406
Project: 72406
Buggy source:
/** 
 * <<<<<<< .mine Do FFTs on all channels for this block and save to the array
 * @param startIndex Chunk Index
 * @throws IllegalActionException ======= Convert to Equivalent Rectangular Bandwidth (ERB) scale from Hz.
 * @param frequencyInHz Frequency in Hz
 * @return frequency in ERB scale>>>>>>> .r73083
 */
private void doBlockFFT(int startIndex) throws IllegalActionException {
  ExecutorService executor=Executors.newFixedThreadPool(_numChannels);
  for (int i=0; i < _numChannels; i++) {
    executor.execute(new FFTWorker(i,startIndex));
  }
  executor.shutdown();
  try {
    executor.awaitTermination(1,TimeUnit.SECONDS);
  }
 catch (  InterruptedException e) {
    throw new IllegalActionException(this,"String_Node_Str");
  }
}

Fixed version (ground truth):
/** 
 * <<<<<<< .mine Do FFTs on all channels for this block and save to the array
 * @param startIndex Chunk Index
 * @exception IllegalActionException ======= Convert to Equivalent Rectangular Bandwidth (ERB) scale from Hz.
 * @param frequencyInHz Frequency in Hz
 * @return frequency in ERB scale>>>>>>> .r73083
 */
private void doBlockFFT(int startIndex) throws IllegalActionException {
  ExecutorService executor=Executors.newFixedThreadPool(_numChannels);
  for (int i=0; i < _numChannels; i++) {
    executor.execute(new FFTWorker(i,startIndex));
  }
  executor.shutdown();
  try {
    executor.awaitTermination(1,TimeUnit.SECONDS);
  }
 catch (  InterruptedException e) {
    throw new IllegalActionException(this,"String_Node_Str");
  }
}