nus-yam/ex-repair huggingface dataset:
Program: 20931
Project: 20931
Buggy source:
public String getUUID(){
  return this.UUID;
}

Fixed version (ground truth):
public String getUUID(){
  if (this.UUID == null)   this.UUID=java.util.UUID.randomUUID().toString();
  return this.UUID;
}
Program: 20932
Project: 20932
Buggy source:
public JSONObject toJSONObject(){
  JSONObject deviceObject=new JSONObject();
  try {
    deviceObject.put("String_Node_Str",getIpAddress());
    deviceObject.put("String_Node_Str",getFriendlyName());
    deviceObject.put("String_Node_Str",getModelName());
    deviceObject.put("String_Node_Str",getModelNumber());
    deviceObject.put("String_Node_Str",getLastSeenOnWifi());
    deviceObject.put("String_Node_Str",getLastConnected());
    deviceObject.put("String_Node_Str",getLastDetection());
    JSONObject jsonServices=new JSONObject();
    for (    DeviceService service : services.values()) {
      JSONObject serviceObject=service.toJSONObject();
      jsonServices.put(service.getServiceConfig().getServiceUUID(),serviceObject);
    }
    deviceObject.put("String_Node_Str",jsonServices);
  }
 catch (  JSONException e) {
    e.printStackTrace();
  }
  return deviceObject;
}

Fixed version (ground truth):
public JSONObject toJSONObject(){
  JSONObject deviceObject=new JSONObject();
  try {
    deviceObject.put(KEY_ID,getUUID());
    deviceObject.put(KEY_LAST_IP,getIpAddress());
    deviceObject.put(KEY_FRIENDLY,getFriendlyName());
    deviceObject.put(KEY_MODEL_NAME,getModelName());
    deviceObject.put(KEY_MODEL_NUMBER,getModelNumber());
    deviceObject.put(KEY_LAST_SEEN,getLastSeenOnWifi());
    deviceObject.put(KEY_LAST_CONNECTED,getLastConnected());
    deviceObject.put(KEY_LAST_DETECTED,getLastDetection());
    JSONObject jsonServices=new JSONObject();
    for (    DeviceService service : services.values()) {
      JSONObject serviceObject=service.toJSONObject();
      jsonServices.put(service.getServiceConfig().getServiceUUID(),serviceObject);
    }
    deviceObject.put(KEY_SERVICES,jsonServices);
  }
 catch (  JSONException e) {
    e.printStackTrace();
  }
  return deviceObject;
}
Program: 20933
Project: 20933
Buggy source:
public ConnectableDevice(String ipAddress,String friendlyName,String modelName,String modelNumber){
  this.ipAddress=ipAddress;
  this.friendlyName=friendlyName;
  this.modelName=modelName;
  this.modelNumber=modelNumber;
  services=new ConcurrentHashMap<String,DeviceService>();
  deviceListeners=new CopyOnWriteArrayList<ConnectableDeviceListenerPair>();
}

Fixed version (ground truth):
public ConnectableDevice(JSONObject json,ConnectableDeviceStore deviceStore){
  setUUID(json.optString(KEY_ID,null));
  setLastKnownIPAddress(json.optString(KEY_LAST_IP,null));
  setFriendlyName(json.optString(KEY_FRIENDLY,null));
  setModelName(json.optString(KEY_MODEL_NAME,null));
  setModelNumber(json.optString(KEY_MODEL_NUMBER,null));
  setLastSeenOnWifi(json.optString(KEY_LAST_SEEN,null));
  setLastConnected(json.optLong(KEY_LAST_CONNECTED,0));
  setLastDetection(json.optLong(KEY_LAST_DETECTED,0));
  JSONObject jsonServices=json.optJSONObject(KEY_SERVICES);
  if (jsonServices != null) {
    @SuppressWarnings("String_Node_Str") Iterator<String> iter=jsonServices.keys();
    while (iter.hasNext()) {
      String key=iter.next();
      JSONObject jsonService=jsonServices.optJSONObject(key);
      if (jsonService != null) {
        DeviceService newService=DeviceService.getService(jsonService,deviceStore);
        if (newService != null)         addService(newService);
      }
    }
  }
}
Program: 20934
Project: 20934
Buggy source:
/** 
 * A List of all ConnectableDevices in the ConnectableDeviceStore. These ConnectableDevice objects are for informational use only, and should not be interacted with. DiscoveryManager uses these ConnectableDevice objects to populate discovered ConnectableDevices with relevant data (last connected, pairing info, etc).
 */
public List<ConnectableDevice> getStoredDevices();

Fixed version (ground truth):
/** 
 * A JSONObject of all ConnectableDevices in the ConnectableDeviceStore. To gt a strongly-typed ConnectableDevice object, use the `getDevice(String);` method.
 */
public JSONObject getStoredDevices();
Program: 20935
Project: 20935
Buggy source:
@Override public void getAppList(final AppListListener listener){
  getTotalNumberOfApplications(2,new AppCountListener(){
    @Override public void onSuccess(    final Integer count){
      getApplications(2,count,new AppListListener(){
        @Override public void onSuccess(        List<AppInfo> apps){
          applications=apps;
          getTotalNumberOfApplications(3,new AppCountListener(){
            @Override public void onSuccess(            final Integer count){
              getApplications(3,count,new AppListListener(){
                @Override public void onSuccess(                List<AppInfo> apps){
                  applications=apps;
                  Util.postSuccess(listener,apps);
                }
                @Override public void onError(                ServiceCommandError error){
                  Util.postError(listener,error);
                }
              }
);
            }
            @Override public void onError(            ServiceCommandError error){
              Util.postError(listener,error);
            }
          }
);
        }
        @Override public void onError(        ServiceCommandError error){
          Util.postError(listener,error);
        }
      }
);
    }
    @Override public void onError(    ServiceCommandError error){
      Util.postError(listener,error);
    }
  }
);
}

Fixed version (ground truth):
@Override public void getAppList(final AppListListener listener){
  applications.clear();
  getTotalNumberOfApplications(2,new AppCountListener(){
    @Override public void onSuccess(    final Integer count){
      getApplications(2,count,new AppListListener(){
        @Override public void onSuccess(        List<AppInfo> apps){
          applications.addAll(apps);
          getTotalNumberOfApplications(3,new AppCountListener(){
            @Override public void onSuccess(            final Integer count){
              getApplications(3,count,new AppListListener(){
                @Override public void onSuccess(                List<AppInfo> apps){
                  applications.addAll(apps);
                  Util.postSuccess(listener,applications);
                }
                @Override public void onError(                ServiceCommandError error){
                  Util.postError(listener,error);
                }
              }
);
            }
            @Override public void onError(            ServiceCommandError error){
              Util.postError(listener,error);
            }
          }
);
        }
        @Override public void onError(        ServiceCommandError error){
          Util.postError(listener,error);
        }
      }
);
    }
    @Override public void onError(    ServiceCommandError error){
      Util.postError(listener,error);
    }
  }
);
}
Program: 20936
Project: 20936
Buggy source:
/** 
 * Listener which should receive discovery updates. It is not necessary to set this delegate property unless you are implementing your own device picker. Connect SDK provides a default DevicePicker which acts as a DiscoveryManagerListener, and should work for most cases. If you have provided a capabilityFilters array, the delegate will only receive update messages for ConnectableDevices which satisfy at least one of the CapabilityFilters. If no capabilityFilters array is provided, the listener will receive update messages for all ConnectableDevice objects that are discovered.
 */
public DiscoveryManagerListener getListener(){
  return listener;
}

Fixed version (ground truth):
/** 
 * Listener which should receive discovery updates. It is not necessary to set this delegate property unless you are implementing your own device picker. Connect SDK provides a default DevicePicker which acts as a DiscoveryManagerListener, and should work for most cases. If you have provided a capabilityFilters array, the delegate will only receive update messages for ConnectableDevices which satisfy at least one of the CapabilityFilters. If no capabilityFilters array is provided, the listener will receive update messages for all ConnectableDevice objects that are discovered.
 */
public ConnectableDeviceListener getListener(){
  return listener;
}
Program: 20937
Project: 20937
Buggy source:
/** 
 * Adds a DeviceService to the ConnectableDevice instance. Only one instance of each DeviceService type (webOS, Netcast, etc) may be attached to a single ConnectableDevice instance. If a device contains your service type already, your service will not be added.
 * @param service DeviceService to be added
 */
public void addService(DeviceService service){
  final List<String> added=getMismatchCapabilities(service.getCapabilities(),getCapabilities());
  Util.runOnUI(new Runnable(){
    @Override public void run(){
      for (      ConnectableDeviceListenerPair pair : deviceListeners) {
        pair.listener.onCapabilityUpdated(pair.device,added,null);
      }
    }
  }
);
  services.put(service.getServiceDescription().getServiceFilter(),service);
}

Fixed version (ground truth):
/** 
 * Adds a DeviceService to the ConnectableDevice instance. Only one instance of each DeviceService type (webOS, Netcast, etc) may be attached to a single ConnectableDevice instance. If a device contains your service type already, your service will not be added.
 * @param service DeviceService to be added
 */
public void addService(DeviceService service){
  final List<String> added=getMismatchCapabilities(service.getCapabilities(),getCapabilities());
  service.setListener(this);
  Util.runOnUI(new Runnable(){
    @Override public void run(){
      for (      ConnectableDeviceListenerPair pair : deviceListeners) {
        pair.listener.onCapabilityUpdated(pair.device,added,null);
      }
    }
  }
);
  services.put(service.getServiceDescription().getServiceFilter(),service);
}
Program: 20938
Project: 20938
Buggy source:
/** 
 * Sets the DiscoveryManagerListener
 * @param listener The listener that should receive callbacks.
 */
public void setListener(DiscoveryManagerListener listener){
  this.listener=listener;
}

Fixed version (ground truth):
/** 
 * Sets the DiscoveryManagerListener
 * @param listener The listener that should receive callbacks.
 */
public void setListener(ConnectableDeviceListener listener){
  this.listener=listener;
}
Program: 20939
Project: 20939
Buggy source:
@Override public void onConnectionSuccess(DeviceService service){
}

Fixed version (ground truth):
@Override public void onConnectionSuccess(DeviceService service){
  if (listener != null) {
  }
  if (isConnected()) {
    DiscoveryManager.getInstance().getConnectableDeviceStore().addDevice(this);
    setLastConnected(Util.getTime());
  }
}
Program: 20940
Project: 20940
Buggy source:
private JSONObject getStoredDevice(String uuid){
  JSONObject foundDevice=storedDevices.optJSONObject(uuid);
  if (foundDevice == null) {
    @SuppressWarnings("String_Node_Str") Iterator<String> iter=storedDevices.keys();
    while (iter.hasNext()) {
      String key=iter.next();
      JSONObject device=storedDevices.optJSONObject(key);
      JSONObject services=device.optJSONObject(ConnectableDevice.KEY_SERVICES);
      if (services != null && services.has(uuid))       return device;
    }
  }
  return null;
}

Fixed version (ground truth):
private JSONObject getStoredDevice(String uuid){
  JSONObject foundDevice=storedDevices.optJSONObject(uuid);
  if (foundDevice == null) {
    @SuppressWarnings("String_Node_Str") Iterator<String> iter=storedDevices.keys();
    while (iter.hasNext()) {
      String key=iter.next();
      JSONObject device=storedDevices.optJSONObject(key);
      JSONObject services=device.optJSONObject(ConnectableDevice.KEY_SERVICES);
      if (services != null && services.has(uuid))       return device;
    }
  }
  return foundDevice;
}
Program: 20941
Project: 20941
Buggy source:
private ConnectableDevice getActiveDevice(String uuid){
  ConnectableDevice foundDevice=activeDevices.get(uuid);
  if (foundDevice == null) {
    for (    ConnectableDevice device : activeDevices.values()) {
      for (      DeviceService service : device.getServices()) {
        if (uuid.equals(service.getServiceDescription().getUUID())) {
          return foundDevice;
        }
      }
    }
  }
  return null;
}

Fixed version (ground truth):
private ConnectableDevice getActiveDevice(String uuid){
  ConnectableDevice foundDevice=activeDevices.get(uuid);
  if (foundDevice == null) {
    for (    ConnectableDevice device : activeDevices.values()) {
      for (      DeviceService service : device.getServices()) {
        if (uuid.equals(service.getServiceDescription().getUUID())) {
          return foundDevice;
        }
      }
    }
  }
  return foundDevice;
}
Program: 20942
Project: 20942
Buggy source:
@Override public void onServiceAdded(DiscoveryProvider provider,ServiceDescription serviceDescription){
  Log.d("String_Node_Str",serviceDescription.getFriendlyName() + "String_Node_Str" + serviceDescription.getServiceID()+ "String_Node_Str");
  boolean deviceIsNew=false;
  ConnectableDevice device=null;
  if (connectableDeviceStore != null) {
    device=connectableDeviceStore.getDevice(serviceDescription.getUUID());
    if (device != null)     allDevices.put(serviceDescription.getIpAddress(),device);
  }
  if (device == null)   device=allDevices.get(serviceDescription.getIpAddress());
  if (device == null) {
    device=new ConnectableDevice(serviceDescription);
    allDevices.put(serviceDescription.getIpAddress(),device);
    deviceIsNew=true;
  }
  device.setLastDetection(Util.getTime());
  device.setLastKnownIPAddress(serviceDescription.getIpAddress());
  addServiceDescriptionToDevice(serviceDescription,device);
  if (device.getServices().size() == 0)   return;
  if (deviceIsNew)   handleDeviceAdd(device);
 else   handleDeviceUpdate(device);
}

Fixed version (ground truth):
@Override public void onServiceAdded(DiscoveryProvider provider,ServiceDescription serviceDescription){
  Log.d("String_Node_Str",serviceDescription.getFriendlyName() + "String_Node_Str" + serviceDescription.getServiceID()+ "String_Node_Str");
  boolean deviceIsNew=false;
  ConnectableDevice device=null;
  if (connectableDeviceStore != null) {
    device=connectableDeviceStore.getDevice(serviceDescription.getUUID());
    if (device != null) {
      allDevices.put(serviceDescription.getIpAddress(),device);
      device.setIpAddress(serviceDescription.getIpAddress());
    }
  }
  if (device == null)   device=allDevices.get(serviceDescription.getIpAddress());
  if (device == null) {
    device=new ConnectableDevice(serviceDescription);
    device.setIpAddress(serviceDescription.getIpAddress());
    allDevices.put(serviceDescription.getIpAddress(),device);
    deviceIsNew=true;
  }
  device.setLastDetection(Util.getTime());
  device.setLastKnownIPAddress(serviceDescription.getIpAddress());
  addServiceDescriptionToDevice(serviceDescription,device);
  if (device.getServices().size() == 0)   return;
  if (deviceIsNew)   handleDeviceAdd(device);
 else   handleDeviceUpdate(device);
}
Program: 20944
Project: 20944
Buggy source:
public void handleDeviceUpdate(ConnectableDevice device){
  if (deviceIsCompatible(device)) {
    if (compatibleDevices.containsKey(device.getIpAddress())) {
      for (      DiscoveryManagerListener listenter : discoveryListeners) {
        listenter.onDeviceUpdated(this,device);
      }
    }
 else {
      handleDeviceAdd(device);
    }
  }
 else {
    compatibleDevices.remove(device.getIpAddress());
    handleDeviceLoss(device);
  }
}

Fixed version (ground truth):
public void handleDeviceUpdate(ConnectableDevice device){
  if (deviceIsCompatible(device)) {
    if (device.getIpAddress() != null && compatibleDevices.containsKey(device.getIpAddress())) {
      for (      DiscoveryManagerListener listenter : discoveryListeners) {
        listenter.onDeviceUpdated(this,device);
      }
    }
 else {
      handleDeviceAdd(device);
    }
  }
 else {
    compatibleDevices.remove(device.getIpAddress());
    handleDeviceLoss(device);
  }
}
Program: 20945
Project: 20945
Buggy source:
protected void handleRegistered(){
  if (serviceReadyListener != null) {
    isServiceReady=true;
    serviceReadyListener.onServiceReady();
  }
  state=State.REGISTERED;
  if (!commandQueue.isEmpty()) {
    LinkedHashSet<ServiceCommand<ResponseListener<Object>>> tempHashSet=new LinkedHashSet<ServiceCommand<ResponseListener<Object>>>(commandQueue);
    for (    ServiceCommand<ResponseListener<Object>> command : tempHashSet) {
      Log.d("String_Node_Str","String_Node_Str" + command.getTarget());
      sendCommandImmediately(command);
      commandQueue.remove(command);
    }
  }
}

Fixed version (ground truth):
protected void handleRegistered(){
  if (serviceReadyListener != null) {
    isServiceReady=true;
    serviceReadyListener.onServiceReady();
  }
  state=State.REGISTERED;
  if (!commandQueue.isEmpty()) {
    LinkedHashSet<ServiceCommand<ResponseListener<Object>>> tempHashSet=new LinkedHashSet<ServiceCommand<ResponseListener<Object>>>(commandQueue);
    for (    ServiceCommand<ResponseListener<Object>> command : tempHashSet) {
      Log.d("String_Node_Str","String_Node_Str" + command.getTarget());
      sendCommandImmediately(command);
      commandQueue.remove(command);
    }
  }
  Util.runOnUI(new Runnable(){
    @Override public void run(){
      if (listener != null)       listener.onConnectionSuccess(WebOSTVService.this);
    }
  }
);
}
Program: 20946
Project: 20946
Buggy source:
public JSONObject toJSONObject(){
  JSONObject jsonObj=new JSONObject();
  try {
    jsonObj.putOpt(KEY_FILTER,serviceFilter);
    jsonObj.putOpt(KEY_IP_ADDRESS,ipAddress);
    jsonObj.putOpt(KEY_UUID,UUID);
    jsonObj.putOpt(KEY_FRIENDLY,friendlyName);
    jsonObj.putOpt(KEY_MODEL_NAME,modelName);
    jsonObj.putOpt(KEY_MODEL_NUMBER,modelNumber);
    jsonObj.putOpt(KEY_PORT,port);
    jsonObj.putOpt(KEY_VERSION,version);
  }
 catch (  JSONException e) {
    e.printStackTrace();
  }
  return jsonObj;
}

Fixed version (ground truth):
public JSONObject toJSONObject(){
  JSONObject jsonObj=new JSONObject();
  try {
    jsonObj.putOpt(KEY_FILTER,serviceFilter);
    jsonObj.putOpt(KEY_IP_ADDRESS,ipAddress);
    jsonObj.putOpt(KEY_UUID,UUID);
    jsonObj.putOpt(KEY_FRIENDLY,friendlyName);
    jsonObj.putOpt(KEY_MODEL_NAME,modelName);
    jsonObj.putOpt(KEY_MODEL_NUMBER,modelNumber);
    jsonObj.putOpt(KEY_PORT,port);
    jsonObj.putOpt(KEY_VERSION,version);
    jsonObj.putOpt(KEY_SERVICE_ID,serviceID);
  }
 catch (  JSONException e) {
    e.printStackTrace();
  }
  return jsonObj;
}
Program: 20947
Project: 20947
Buggy source:
public ServiceDescription(JSONObject json){
  json.optString(KEY_FILTER,null);
  json.optString(KEY_IP_ADDRESS,null);
  json.optString(KEY_UUID,null);
  json.optString(KEY_FRIENDLY,null);
  json.optString(KEY_MODEL_NAME,null);
  json.optString(KEY_MODEL_NUMBER,null);
  json.optInt(KEY_PORT,-1);
  json.optString(KEY_VERSION,null);
}

Fixed version (ground truth):
public ServiceDescription(JSONObject json){
  serviceFilter=json.optString(KEY_FILTER,null);
  ipAddress=json.optString(KEY_IP_ADDRESS,null);
  UUID=json.optString(KEY_UUID,null);
  friendlyName=json.optString(KEY_FRIENDLY,null);
  modelName=json.optString(KEY_MODEL_NAME,null);
  modelNumber=json.optString(KEY_MODEL_NUMBER,null);
  port=json.optInt(KEY_PORT,-1);
  version=json.optString(KEY_VERSION,null);
  serviceID=json.optString(KEY_SERVICE_ID,null);
}
Program: 20948
Project: 20948
Buggy source:
@Override public void getAppList(final AppListListener listener){
  getTotalNumberOfApplications(2,new AppCountListener(){
    @Override public void onSuccess(    final Integer count){
      getApplications(2,count,new AppListListener(){
        @Override public void onSuccess(        List<AppInfo> apps){
          applications=apps;
          getTotalNumberOfApplications(3,new AppCountListener(){
            @Override public void onSuccess(            final Integer count){
              getApplications(3,count,new AppListListener(){
                @Override public void onSuccess(                List<AppInfo> apps){
                  applications=apps;
                  Util.postSuccess(listener,apps);
                }
                @Override public void onError(                ServiceCommandError error){
                  Util.postError(listener,error);
                }
              }
);
            }
            @Override public void onError(            ServiceCommandError error){
              Util.postError(listener,error);
            }
          }
);
        }
        @Override public void onError(        ServiceCommandError error){
          Util.postError(listener,error);
        }
      }
);
    }
    @Override public void onError(    ServiceCommandError error){
      Util.postError(listener,error);
    }
  }
);
}

Fixed version (ground truth):
@Override public void getAppList(final AppListListener listener){
  applications.clear();
  getTotalNumberOfApplications(2,new AppCountListener(){
    @Override public void onSuccess(    final Integer count){
      getApplications(2,count,new AppListListener(){
        @Override public void onSuccess(        List<AppInfo> apps){
          applications.addAll(apps);
          getTotalNumberOfApplications(3,new AppCountListener(){
            @Override public void onSuccess(            final Integer count){
              getApplications(3,count,new AppListListener(){
                @Override public void onSuccess(                List<AppInfo> apps){
                  applications.addAll(apps);
                  Util.postSuccess(listener,applications);
                }
                @Override public void onError(                ServiceCommandError error){
                  Util.postError(listener,error);
                }
              }
);
            }
            @Override public void onError(            ServiceCommandError error){
              Util.postError(listener,error);
            }
          }
);
        }
        @Override public void onError(        ServiceCommandError error){
          Util.postError(listener,error);
        }
      }
);
    }
    @Override public void onError(    ServiceCommandError error){
      Util.postError(listener,error);
    }
  }
);
}
Program: 20950
Project: 20950
Buggy source:
@Override public void playMedia(String url,String mimeType,String title,String description,String iconSrc,boolean shouldLoop,LaunchListener listener){
  displayMedia(url,mimeType,title,description,iconSrc,listener);
}

Fixed version (ground truth):
@Override public void playMedia(final String url,final String mimeType,final String title,final String description,final String iconSrc,final boolean shouldLoop,final LaunchListener listener){
  displayMedia(url,mimeType,title,description,iconSrc,listener);
}
Program: 20951
Project: 20951
Buggy source:
@Override public CapabilityPriorityLevel getLauncherCapabilityLevel(){
  return CapabilityPriorityLevel.NORMAL;
}

Fixed version (ground truth):
@Override public CapabilityPriorityLevel getLauncherCapabilityLevel(){
  return CapabilityPriorityLevel.HIGH;
}
Program: 20953
Project: 20953
Buggy source:
@Override public void onReceive(Context context,Intent intent){
  String action=intent.getAction();
  if (action.equals(WifiManager.SUPPLICANT_CONNECTION_CHANGE_ACTION)) {
    if (intent.getBooleanExtra(WifiManager.EXTRA_SUPPLICANT_CONNECTED,false)) {
      if (mShouldResume) {
        for (        DiscoveryProvider provider : discoveryProviders) {
          provider.start();
        }
      }
    }
 else {
      Log.w("String_Node_Str","String_Node_Str");
      for (      DiscoveryProvider provider : discoveryProviders) {
        provider.reset();
      }
      allDevices.clear();
      for (      ConnectableDevice device : compatibleDevices.values()) {
        handleDeviceLoss(device);
      }
      compatibleDevices.clear();
      mShouldResume=true;
      stop();
    }
  }
}

Fixed version (ground truth):
@Override public void onReceive(Context context,Intent intent){
  String action=intent.getAction();
  if (action.equals(WifiManager.SUPPLICANT_CONNECTION_CHANGE_ACTION)) {
    if (intent.getBooleanExtra(WifiManager.EXTRA_SUPPLICANT_CONNECTED,false)) {
      TimerTask task=new TimerTask(){
        @Override public void run(){
          if (mShouldResume) {
            for (            DiscoveryProvider provider : discoveryProviders) {
              provider.start();
            }
          }
        }
      }
;
      Timer t=new Timer();
      t.schedule(task,2000);
    }
 else {
      Log.w("String_Node_Str","String_Node_Str");
      for (      DiscoveryProvider provider : discoveryProviders) {
        provider.reset();
      }
      allDevices.clear();
      for (      ConnectableDevice device : compatibleDevices.values()) {
        handleDeviceLoss(device);
      }
      compatibleDevices.clear();
      mShouldResume=true;
      stop();
    }
  }
}
Program: 20954
Project: 20954
Buggy source:
public void sendSearch(){
  List<String> killKeys=new ArrayList<String>();
  long killPoint=new Date().getTime() - (RESCAN_INTERVAL * RESCAN_ATTEMPTS);
  for (  String key : foundServices.keySet()) {
    ServiceDescription service=foundServices.get(key);
    if (service.getLastDetection() < killPoint) {
      killKeys.add(key);
    }
  }
  for (  String key : killKeys) {
    final ServiceDescription service=foundServices.get(key);
    Util.runOnUI(new Runnable(){
      @Override public void run(){
        for (        DiscoveryProviderListener listener : serviceListeners) {
          listener.onServiceRemoved(SSDPDiscoveryProvider.this,service);
        }
      }
    }
);
    foundServices.remove(key);
  }
  for (  JSONObject searchTarget : serviceFilters) {
    SSDPSearchMsg search=null;
    try {
      search=new SSDPSearchMsg(searchTarget.getString("String_Node_Str"));
    }
 catch (    JSONException e) {
      e.printStackTrace();
      return;
    }
    final String message=search.toString();
    for (int i=0; i < 3; i++) {
      TimerTask task=new TimerTask(){
        @Override public void run(){
          try {
            mSSDPSocket.send(message);
          }
 catch (          IOException e) {
            e.printStackTrace();
          }
        }
      }
;
      dataTimer.schedule(task,i * 1000);
    }
  }
  ;
}

Fixed version (ground truth):
public void sendSearch(){
  List<String> killKeys=new ArrayList<String>();
  long killPoint=new Date().getTime() - (RESCAN_INTERVAL * RESCAN_ATTEMPTS);
  for (  String key : foundServices.keySet()) {
    ServiceDescription service=foundServices.get(key);
    if (service.getLastDetection() < killPoint) {
      killKeys.add(key);
    }
  }
  for (  String key : killKeys) {
    final ServiceDescription service=foundServices.get(key);
    Util.runOnUI(new Runnable(){
      @Override public void run(){
        for (        DiscoveryProviderListener listener : serviceListeners) {
          listener.onServiceRemoved(SSDPDiscoveryProvider.this,service);
        }
      }
    }
);
    foundServices.remove(key);
  }
  for (  JSONObject searchTarget : serviceFilters) {
    SSDPSearchMsg search=null;
    try {
      search=new SSDPSearchMsg(searchTarget.getString("String_Node_Str"));
    }
 catch (    JSONException e) {
      e.printStackTrace();
      return;
    }
    final String message=search.toString();
    for (int i=0; i < 3; i++) {
      TimerTask task=new TimerTask(){
        @Override public void run(){
          try {
            if (mSSDPSocket != null)             mSSDPSocket.send(message);
          }
 catch (          IOException e) {
            e.printStackTrace();
          }
        }
      }
;
      dataTimer.schedule(task,i * 1000);
    }
  }
  ;
}
Program: 20957
Project: 20957
Buggy source:
@Override public void connect(){
  mServiceReachability=DeviceServiceReachability.getReachability(serviceDescription.getIpAddress(),this);
  mServiceReachability.start();
  connected=true;
}

Fixed version (ground truth):
@Override public void connect(){
  connected=true;
}
Program: 20958
Project: 20958
Buggy source:
@Override public void connect(){
  mServiceReachability=DeviceServiceReachability.getReachability(serviceDescription.getIpAddress(),this);
  mServiceReachability.start();
  connected=true;
}

Fixed version (ground truth):
@Override public void connect(){
  connected=true;
}
Program: 20959
Project: 20959
Buggy source:
private void hConnectSuccess(){
  mServiceReachability=DeviceServiceReachability.getReachability(serviceDescription.getIpAddress(),this);
  mServiceReachability.start();
  connected=true;
  if (serviceReadyListener != null) {
    isServiceReady=true;
    serviceReadyListener.onServiceReady();
  }
}

Fixed version (ground truth):
private void hConnectSuccess(){
  connected=true;
  if (serviceReadyListener != null) {
    isServiceReady=true;
    serviceReadyListener.onServiceReady();
  }
}
Program: 20961
Project: 20961
Buggy source:
private ServiceCommand<ResponseListener<Object>> getMuteStatus(boolean isSubscription,final MuteListener listener){
  ServiceCommand<ResponseListener<Object>> request;
  ResponseListener<Object> responseListener=new ResponseListener<Object>(){
    @Override public void onSuccess(    Object response){
      try {
        JSONObject jsonObj=(JSONObject)response;
        boolean isMute=(Boolean)jsonObj.get("String_Node_Str");
        Util.postSuccess(listener,isMute);
      }
 catch (      JSONException e) {
        e.printStackTrace();
      }
    }
    @Override public void onError(    ServiceCommandError error){
      Util.postError(listener,error);
    }
  }
;
  if (isSubscription)   request=new URLServiceSubscription<ResponseListener<Object>>(this,MUTE,null,responseListener);
 else   request=new ServiceCommand<ResponseListener<Object>>(this,MUTE,null,true,responseListener);
  request.send();
  return request;
}

Fixed version (ground truth):
private ServiceCommand<ResponseListener<Object>> getMuteStatus(boolean isSubscription,final MuteListener listener){
  ServiceCommand<ResponseListener<Object>> request;
  ResponseListener<Object> responseListener=new ResponseListener<Object>(){
    @Override public void onSuccess(    Object response){
      try {
        JSONObject jsonObj=(JSONObject)response;
        boolean isMute=(Boolean)jsonObj.get("String_Node_Str");
        Util.postSuccess(listener,isMute);
      }
 catch (      JSONException e) {
        e.printStackTrace();
      }
    }
    @Override public void onError(    ServiceCommandError error){
      Util.postError(listener,error);
    }
  }
;
  if (isSubscription)   request=new URLServiceSubscription<ResponseListener<Object>>(this,MUTE,null,true,responseListener);
 else   request=new ServiceCommand<ResponseListener<Object>>(this,MUTE,null,true,responseListener);
  request.send();
  return request;
}
Program: 20962
Project: 20962
Buggy source:
public URLServiceSubscription(DeviceService service,String uri,JSONObject payload,ResponseListener<Object> listener){
  super(service,uri,payload,listener);
}

Fixed version (ground truth):
public URLServiceSubscription(DeviceService service,String uri,JSONObject payload,boolean isWebOS,ResponseListener<Object> listener){
  super(service,uri,payload,isWebOS,listener);
}
Program: 20963
Project: 20963
Buggy source:
@SuppressWarnings("String_Node_Str") @Override public void run(){
  ServiceCommand<ResponseListener<Object>> command=(ServiceCommand<ResponseListener<Object>>)mCommand;
  Object payload=command.getPayload();
  HttpRequestBase request=command.getRequest();
  HttpResponse response=null;
  int code=-1;
  if (payload != null && command.getHttpMethod().equalsIgnoreCase(ServiceCommand.TYPE_POST)) {
    HttpPost post=(HttpPost)request;
    HttpEntity entity=null;
    try {
      if (payload instanceof String) {
        entity=new StringEntity((String)payload);
      }
 else       if (payload instanceof JSONObject) {
        entity=new StringEntity((String)payload);
      }
    }
 catch (    UnsupportedEncodingException e) {
      e.printStackTrace();
    }
    if (entity == null) {
      Util.postError(command.getResponseListener(),new ServiceCommandError(0,"String_Node_Str",null));
      return;
    }
    post.setEntity(entity);
  }
  try {
    response=httpClient.execute(request);
    code=response.getStatusLine().getStatusCode();
    if (code == 200 || code == 201) {
      HttpEntity entity=response.getEntity();
      String message=EntityUtils.toString(entity,"String_Node_Str");
      Util.postSuccess(command.getResponseListener(),message);
    }
 else {
      Util.postError(command.getResponseListener(),ServiceCommandError.getError(code));
    }
  }
 catch (  ClientProtocolException e) {
    e.printStackTrace();
  }
catch (  IOException e) {
    e.printStackTrace();
  }
}

Fixed version (ground truth):
@SuppressWarnings("String_Node_Str") @Override public void run(){
  ServiceCommand<ResponseListener<Object>> command=(ServiceCommand<ResponseListener<Object>>)mCommand;
  Object payload=command.getPayload();
  HttpRequestBase request=command.getRequest();
  HttpResponse response=null;
  int code=-1;
  if (payload != null && command.getHttpMethod().equalsIgnoreCase(ServiceCommand.TYPE_POST)) {
    request.setHeader(HttpMessage.CONTENT_TYPE_HEADER,"String_Node_Str");
    HttpPost post=(HttpPost)request;
    HttpEntity entity=null;
    try {
      if (payload instanceof String) {
        entity=new StringEntity((String)payload);
      }
 else       if (payload instanceof JSONObject) {
        entity=new StringEntity((String)payload);
      }
    }
 catch (    UnsupportedEncodingException e) {
      e.printStackTrace();
    }
    if (entity == null) {
      Util.postError(command.getResponseListener(),new ServiceCommandError(0,"String_Node_Str",null));
      return;
    }
    post.setEntity(entity);
  }
  try {
    response=httpClient.execute(request);
    code=response.getStatusLine().getStatusCode();
    if (code == 200 || code == 201) {
      HttpEntity entity=response.getEntity();
      String message=EntityUtils.toString(entity,"String_Node_Str");
      Util.postSuccess(command.getResponseListener(),message);
    }
 else {
      Util.postError(command.getResponseListener(),ServiceCommandError.getError(code));
    }
  }
 catch (  ClientProtocolException e) {
    e.printStackTrace();
  }
catch (  IOException e) {
    e.printStackTrace();
  }
}
Program: 20965
Project: 20965
Buggy source:
/** 
 * Registers an app ID to be checked upon discovery of this device. If the app is found on the target device, the DIALService will gain the "Launcher.<appID>" capability, where <appID> is the value of the appId parameter. This method must be called before starting DiscoveryManager for the first time.
 * @param appId ID of the app to be checked for
 */
public static void registerApp(String appId){
  if (registeredApps.contains(appId))   registeredApps.add(appId);
}

Fixed version (ground truth):
/** 
 * Registers an app ID to be checked upon discovery of this device. If the app is found on the target device, the DIALService will gain the "Launcher.<appID>" capability, where <appID> is the value of the appId parameter. This method must be called before starting DiscoveryManager for the first time.
 * @param appId ID of the app to be checked for
 */
public static void registerApp(String appId){
  if (!registeredApps.contains(appId))   registeredApps.add(appId);
}
Program: 20966
Project: 20966
Buggy source:
private void launchApp(String appId,JSONObject params,AppLaunchListener listener){
  if (appId == null || appId.length() == 0) {
    Util.postError(listener,new ServiceCommandError(0,"String_Node_Str",null));
    return;
  }
  AppInfo appInfo=new AppInfo();
  appInfo.setId(appId);
  launchAppWithInfo(appInfo,listener);
}

Fixed version (ground truth):
private void launchApp(String appId,JSONObject params,AppLaunchListener listener){
  if (appId == null || appId.length() == 0) {
    Util.postError(listener,new ServiceCommandError(0,"String_Node_Str",null));
    return;
  }
  AppInfo appInfo=new AppInfo();
  appInfo.setName(appId);
  appInfo.setId(appId);
  launchAppWithInfo(appInfo,listener);
}
Program: 20967
Project: 20967
Buggy source:
@Override public void onLoseReachability(DeviceServiceReachability reachability){
  if (connected) {
    disconnect();
  }
 else {
    mServiceReachability.stop();
  }
}

Fixed version (ground truth):
@Override public void onLoseReachability(DeviceServiceReachability reachability){
  if (connected) {
    disconnect();
  }
 else {
    if (mServiceReachability != null)     mServiceReachability.stop();
  }
}
Program: 20968
Project: 20968
Buggy source:
@Override public void onLoseReachability(DeviceServiceReachability reachability){
  if (connected) {
    disconnect();
  }
 else {
    mServiceReachability.stop();
  }
}

Fixed version (ground truth):
@Override public void onLoseReachability(DeviceServiceReachability reachability){
  if (connected) {
    disconnect();
  }
 else {
    if (mServiceReachability != null)     mServiceReachability.stop();
  }
}
Program: 20969
Project: 20969
Buggy source:
public String getUUID(){
  return this.UUID;
}

Fixed version (ground truth):
public String getUUID(){
  if (this.UUID == null)   this.UUID=java.util.UUID.randomUUID().toString();
  return this.UUID;
}
Program: 20970
Project: 20970
Buggy source:
public JSONObject toJSONObject(){
  JSONObject deviceObject=new JSONObject();
  try {
    deviceObject.put("String_Node_Str",getIpAddress());
    deviceObject.put("String_Node_Str",getFriendlyName());
    deviceObject.put("String_Node_Str",getModelName());
    deviceObject.put("String_Node_Str",getModelNumber());
    deviceObject.put("String_Node_Str",getLastSeenOnWifi());
    deviceObject.put("String_Node_Str",getLastConnected());
    deviceObject.put("String_Node_Str",getLastDetection());
    JSONObject jsonServices=new JSONObject();
    for (    DeviceService service : services.values()) {
      JSONObject serviceObject=service.toJSONObject();
      jsonServices.put(service.getServiceConfig().getServiceUUID(),serviceObject);
    }
    deviceObject.put("String_Node_Str",jsonServices);
  }
 catch (  JSONException e) {
    e.printStackTrace();
  }
  return deviceObject;
}

Fixed version (ground truth):
public JSONObject toJSONObject(){
  JSONObject deviceObject=new JSONObject();
  try {
    deviceObject.put(KEY_ID,getUUID());
    deviceObject.put(KEY_LAST_IP,getIpAddress());
    deviceObject.put(KEY_FRIENDLY,getFriendlyName());
    deviceObject.put(KEY_MODEL_NAME,getModelName());
    deviceObject.put(KEY_MODEL_NUMBER,getModelNumber());
    deviceObject.put(KEY_LAST_SEEN,getLastSeenOnWifi());
    deviceObject.put(KEY_LAST_CONNECTED,getLastConnected());
    deviceObject.put(KEY_LAST_DETECTED,getLastDetection());
    JSONObject jsonServices=new JSONObject();
    for (    DeviceService service : services.values()) {
      JSONObject serviceObject=service.toJSONObject();
      jsonServices.put(service.getServiceConfig().getServiceUUID(),serviceObject);
    }
    deviceObject.put(KEY_SERVICES,jsonServices);
  }
 catch (  JSONException e) {
    e.printStackTrace();
  }
  return deviceObject;
}
Program: 20971
Project: 20971
Buggy source:
public ConnectableDevice(String ipAddress,String friendlyName,String modelName,String modelNumber){
  this.ipAddress=ipAddress;
  this.friendlyName=friendlyName;
  this.modelName=modelName;
  this.modelNumber=modelNumber;
  services=new ConcurrentHashMap<String,DeviceService>();
  deviceListeners=new CopyOnWriteArrayList<ConnectableDeviceListenerPair>();
}

Fixed version (ground truth):
public ConnectableDevice(JSONObject json,ConnectableDeviceStore deviceStore){
  setUUID(json.optString(KEY_ID,null));
  setLastKnownIPAddress(json.optString(KEY_LAST_IP,null));
  setFriendlyName(json.optString(KEY_FRIENDLY,null));
  setModelName(json.optString(KEY_MODEL_NAME,null));
  setModelNumber(json.optString(KEY_MODEL_NUMBER,null));
  setLastSeenOnWifi(json.optString(KEY_LAST_SEEN,null));
  setLastConnected(json.optLong(KEY_LAST_CONNECTED,0));
  setLastDetection(json.optLong(KEY_LAST_DETECTED,0));
  JSONObject jsonServices=json.optJSONObject(KEY_SERVICES);
  if (jsonServices != null) {
    @SuppressWarnings("String_Node_Str") Iterator<String> iter=jsonServices.keys();
    while (iter.hasNext()) {
      String key=iter.next();
      JSONObject jsonService=jsonServices.optJSONObject(key);
      if (jsonService != null) {
        DeviceService newService=DeviceService.getService(jsonService,deviceStore);
        if (newService != null)         addService(newService);
      }
    }
  }
}
Program: 20972
Project: 20972
Buggy source:
/** 
 * A List of all ConnectableDevices in the ConnectableDeviceStore. These ConnectableDevice objects are for informational use only, and should not be interacted with. DiscoveryManager uses these ConnectableDevice objects to populate discovered ConnectableDevices with relevant data (last connected, pairing info, etc).
 */
public List<ConnectableDevice> getStoredDevices();

Fixed version (ground truth):
/** 
 * A JSONObject of all ConnectableDevices in the ConnectableDeviceStore. To gt a strongly-typed ConnectableDevice object, use the `getDevice(String);` method.
 */
public JSONObject getStoredDevices();
Program: 20974
Project: 20974
Buggy source:
/** 
 * Initilizes the Discovery manager with a valid context.  This should be done as soon as possible and it should use getApplicationContext() as the Discovery manager could persist longer than the current Activity. This accepts a ConnectableDeviceStore to use instead of the default device store.
 * @code MyConnectableDeviceStore myDeviceStore = new MyConnectableDeviceStore(); DiscoveryManager.init(getApplicationContext(), myDeviceStore);
 * @endcode
 */
@SuppressWarnings("String_Node_Str") public static synchronized void init(Context context,ConnectableDeviceStore connectableDeviceStore){
  airplaneMode=Settings.System.getInt(context.getContentResolver(),Settings.System.AIRPLANE_MODE_ON,0);
  if (isAirplaneMode()) {
    return;
  }
  instance=new DiscoveryManager(context,connectableDeviceStore);
}

Fixed version (ground truth):
/** 
 * Initilizes the Discovery manager with a valid context.  This should be done as soon as possible and it should use getApplicationContext() as the Discovery manager could persist longer than the current Activity. This accepts a ConnectableDeviceStore to use instead of the default device store.
 * @code MyConnectableDeviceStore myDeviceStore = new MyConnectableDeviceStore(); DiscoveryManager.init(getApplicationContext(), myDeviceStore);
 * @endcode
 */
@SuppressWarnings("String_Node_Str") public static synchronized void init(Context context,ConnectableDeviceStore connectableDeviceStore){
  instance=new DiscoveryManager(context,connectableDeviceStore);
}
Program: 20976
Project: 20976
Buggy source:
/** 
 * Start scanning for devices on the local network.
 */
public void start(){
  if (discoveryProviders == null) {
    return;
  }
  Util.runOnUI(new Runnable(){
    @Override public void run(){
      if (discoveryProviders.size() == 0) {
        registerDefaultDeviceTypes();
      }
      registerBroadcastReceiver();
      multicastLock.acquire();
      ConnectivityManager connManager=(ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
      NetworkInfo mWifi=connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
      if (mWifi.isConnected()) {
        for (        DiscoveryProvider provider : discoveryProviders) {
          provider.start();
        }
      }
 else {
        Log.w("String_Node_Str","String_Node_Str");
        Util.runOnUI(new Runnable(){
          @Override public void run(){
            for (            DiscoveryManagerListener listener : discoveryListeners)             listener.onDiscoveryFailed(DiscoveryManager.this,new ServiceCommandError(0,"String_Node_Str",null));
          }
        }
);
      }
    }
  }
);
}

Fixed version (ground truth):
/** 
 * Start scanning for devices on the local network.
 */
public void start(){
  if (mSearching)   return;
  mSearching=true;
  if (discoveryProviders == null) {
    return;
  }
  Util.runOnUI(new Runnable(){
    @Override public void run(){
      if (discoveryProviders.size() == 0) {
        registerDefaultDeviceTypes();
      }
      if (mShouldResume) {
        mShouldResume=false;
      }
 else {
        registerBroadcastReceiver();
      }
      multicastLock.acquire();
      ConnectivityManager connManager=(ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
      NetworkInfo mWifi=connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
      if (mWifi.isConnected()) {
        for (        DiscoveryProvider provider : discoveryProviders) {
          provider.start();
        }
      }
 else {
        Log.w("String_Node_Str","String_Node_Str");
        mShouldResume=true;
        Util.runOnUI(new Runnable(){
          @Override public void run(){
            for (            DiscoveryManagerListener listener : discoveryListeners)             listener.onDiscoveryFailed(DiscoveryManager.this,new ServiceCommandError(0,"String_Node_Str",null));
          }
        }
);
      }
    }
  }
);
}
Program: 20977
Project: 20977
Buggy source:
private void registerBroadcastReceiver(){
  if (isBroadcastReceiverRegistered == false) {
    isBroadcastReceiverRegistered=true;
    IntentFilter intent=new IntentFilter(WifiManager.SUPPLICANT_STATE_CHANGED_ACTION);
    context.registerReceiver(receiver,intent);
  }
}

Fixed version (ground truth):
private void registerBroadcastReceiver(){
  if (isBroadcastReceiverRegistered == false) {
    isBroadcastReceiverRegistered=true;
    IntentFilter intent=new IntentFilter(WifiManager.SUPPLICANT_CONNECTION_CHANGE_ACTION);
    context.registerReceiver(receiver,intent);
  }
}
Program: 20978
Project: 20978
Buggy source:
/** 
 * Registers a commonly-used set of DeviceServices with DiscoveryManager. This method will be called on first call of startDiscovery if no DeviceServices have been registered. - CastDiscoveryProvider + CastService - SSDPDiscoveryProvider + DIALService + DLNAService (limited to LG TVs, currently) + NetcastTVService + RokuService + WebOSTVService
 */
public void registerDefaultDeviceTypes(){
  registerDeviceService(WebOSTVService.class,SSDPDiscoveryProvider.class);
  registerDeviceService(NetcastTVService.class,SSDPDiscoveryProvider.class);
  registerDeviceService(DIALService.class,SSDPDiscoveryProvider.class);
  registerDeviceService(RokuService.class,SSDPDiscoveryProvider.class);
  registerDeviceService(CastService.class,CastDiscoveryProvider.class);
}

Fixed version (ground truth):
/** 
 * Registers a commonly-used set of DeviceServices with DiscoveryManager. This method will be called on first call of startDiscovery if no DeviceServices have been registered. - CastDiscoveryProvider + CastService - SSDPDiscoveryProvider + DIALService + DLNAService (limited to LG TVs, currently) + NetcastTVService + RokuService + WebOSTVService
 */
public void registerDefaultDeviceTypes(){
  registerDeviceService(DIALService.class,SSDPDiscoveryProvider.class);
}
Program: 20979
Project: 20979
Buggy source:
@Override public void onReceive(Context context,Intent intent){
  String action=intent.getAction();
  if (action.equals(WifiManager.SUPPLICANT_STATE_CHANGED_ACTION)) {
    SupplicantState state=intent.getParcelableExtra(WifiManager.EXTRA_NEW_STATE);
    if (SupplicantState.isValidState(state)) {
      if (state == SupplicantState.DISCONNECTED) {
        Log.w("String_Node_Str","String_Node_Str");
        for (        DiscoveryProvider provider : discoveryProviders) {
          provider.reset();
        }
        allDevices.clear();
        for (        ConnectableDevice device : compatibleDevices.values()) {
          handleDeviceLoss(device);
        }
        compatibleDevices.clear();
      }
    }
  }
}

Fixed version (ground truth):
@Override public void onReceive(Context context,Intent intent){
  String action=intent.getAction();
  if (action.equals(WifiManager.SUPPLICANT_CONNECTION_CHANGE_ACTION)) {
    if (intent.getBooleanExtra(WifiManager.EXTRA_SUPPLICANT_CONNECTED,false)) {
      if (mShouldResume) {
        for (        DiscoveryProvider provider : discoveryProviders) {
          provider.start();
        }
      }
    }
 else {
      Log.w("String_Node_Str","String_Node_Str");
      for (      DiscoveryProvider provider : discoveryProviders) {
        provider.reset();
      }
      allDevices.clear();
      for (      ConnectableDevice device : compatibleDevices.values()) {
        handleDeviceLoss(device);
      }
      compatibleDevices.clear();
      mShouldResume=true;
      stop();
    }
  }
}