nus-yam/ex-repair huggingface dataset:
Program: 20877
Project: 20877
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: 20878
Project: 20878
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: 20879
Project: 20879
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: 20881
Project: 20881
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: 20882
Project: 20882
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: 20883
Project: 20883
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: 20884
Project: 20884
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: 20885
Project: 20885
Buggy source:
@Override public void closeWebApp(LaunchSession launchSession,ResponseListener<Object> listener){
  String uri="String_Node_Str";
  JSONObject payload=new JSONObject();
  try {
    payload.put("String_Node_Str",launchSession.getAppId());
    payload.put("String_Node_Str",launchSession.getSessionId());
  }
 catch (  JSONException e) {
    e.printStackTrace();
  }
  ServiceCommand<ResponseListener<Object>> request=new ServiceCommand<ResponseListener<Object>>(this,uri,payload,true,listener);
  request.send();
}

Fixed version (ground truth):
@Override public void closeWebApp(LaunchSession launchSession,ResponseListener<Object> listener){
  if (launchSession == null)   Util.postError(listener,new ServiceCommandError(0,"String_Node_Str",null));
  if (launchSession.getSessionId() == null)   Util.postError(listener,new ServiceCommandError(0,"String_Node_Str",null));
  String uri="String_Node_Str";
  JSONObject payload=new JSONObject();
  try {
    payload.put("String_Node_Str",launchSession.getAppId());
    payload.put("String_Node_Str",launchSession.getSessionId());
  }
 catch (  JSONException e) {
    e.printStackTrace();
  }
  WebOSWebAppSession webAppSession=new WebOSWebAppSession(launchSession,this);
  disconnectFromWebApp(webAppSession);
  ServiceCommand<ResponseListener<Object>> request=new ServiceCommand<ResponseListener<Object>>(this,uri,payload,true,listener);
  request.send();
}
Program: 20886
Project: 20886
Buggy source:
public void handleMessage(final Object message){
  if (mMessageSubscription == null)   return;
  Util.runOnUI(new Runnable(){
    @Override public void run(){
      getWebAppSessionListener().onReceiveMessage(WebOSWebAppSession.this,message);
    }
  }
);
}

Fixed version (ground truth):
public void handleMessage(final Object message){
  Util.runOnUI(new Runnable(){
    @Override public void run(){
      getWebAppSessionListener().onReceiveMessage(WebOSWebAppSession.this,message);
    }
  }
);
}
Program: 20887
Project: 20887
Buggy source:
public CastService(ServiceDescription serviceDescription,ServiceConfig serviceConfig){
  super(serviceDescription,serviceConfig);
  setCapabilities();
  this.castDevice=((CastServiceDescription)serviceDescription).getCastDevice();
  mCastClientListener=new CastListener();
  mConnectionCallbacks=new ConnectionCallbacks();
  mConnectionFailedListener=new ConnectionFailedListener();
  Cast.CastOptions.Builder apiOptionsBuilder=Cast.CastOptions.builder(castDevice,mCastClientListener);
  mApiClient=new GoogleApiClient.Builder(DiscoveryManager.getInstance().getContext()).addApi(Cast.API,apiOptionsBuilder.build()).addConnectionCallbacks(mConnectionCallbacks).addOnConnectionFailedListener(mConnectionFailedListener).build();
}

Fixed version (ground truth):
public CastService(ServiceDescription serviceDescription,ServiceConfig serviceConfig){
  super(serviceDescription,serviceConfig);
  setCapabilities();
  mCastClientListener=new CastListener();
  mConnectionCallbacks=new ConnectionCallbacks();
  mConnectionFailedListener=new ConnectionFailedListener();
}
Program: 20888
Project: 20888
Buggy source:
@Override public void joinWebApp(final LaunchSession webAppLaunchSession,final WebAppSession.LaunchListener listener){
  Cast.CastApi.joinApplication(mApiClient,webAppLaunchSession.getAppId(),webAppLaunchSession.getSessionId()).setResultCallback(new ResultCallback<Cast.ApplicationConnectionResult>(){
    @Override public void onResult(    Cast.ApplicationConnectionResult result){
      Status status=result.getStatus();
      if (status.isSuccess()) {
        Util.postSuccess(listener,new CastWebAppSession(webAppLaunchSession,CastService.this));
      }
 else {
        Util.postError(listener,new ServiceCommandError(result.getStatus().getStatusCode(),result.getStatus().toString(),result));
      }
    }
  }
);
}

Fixed version (ground truth):
@Override public void joinWebApp(String webAppId,WebAppSession.LaunchListener listener){
  LaunchSession launchSession=LaunchSession.launchSessionForAppId(webAppId);
  launchSession.setSessionType(LaunchSessionType.WebApp);
  launchSession.setService(this);
  joinWebApp(launchSession,listener);
}
Program: 20889
Project: 20889
Buggy source:
@Override public void joinWebApp(final LaunchSession webAppLaunchSession,final WebAppSession.LaunchListener listener){
  final WebOSWebAppSession webAppSession=new WebOSWebAppSession(webAppLaunchSession,this);
  webAppSession.join(new ResponseListener<Object>(){
    @Override public void onError(    ServiceCommandError error){
      Util.postError(listener,error);
    }
    @Override public void onSuccess(    Object object){
      Util.postSuccess(listener,webAppSession);
    }
  }
);
}

Fixed version (ground truth):
@Override public void joinWebApp(String webAppId,WebAppSession.LaunchListener listener){
  LaunchSession launchSession=LaunchSession.launchSessionForAppId(webAppId);
  launchSession.setSessionType(LaunchSessionType.WebApp);
  launchSession.setService(this);
  joinWebApp(launchSession,listener);
}
Program: 20891
Project: 20891
Buggy source:
public void joinWebApp(LaunchSession webAppLaunchSession,LaunchListener listener);

Fixed version (ground truth):
public void joinWebApp(String webAppId,LaunchListener listener);
Program: 20892
Project: 20892
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: 20893
Project: 20893
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: 20894
Project: 20894
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: 20895
Project: 20895
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: 20896
Project: 20896
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: 20897
Project: 20897
Buggy source:
/** 
 * Enumerates through all DeviceServices and attempts to connect to each of them. When all of a ConnectableDevice's DeviceServices are ready to receive commands, the ConnectableDevice will send a onDeviceReady message to its listener. It is always necessary to call connect on a ConnectableDevice, even if it contains no connectable DeviceServices.
 */
public void connect(){
  boolean isDeviceReady=true;
  for (  DeviceService service : services.values()) {
    if (service.isServiceReady() == false) {
      service.setServiceReadyListener(serviceReadyListener);
      isDeviceReady=false;
    }
    service.setDeviceListeners(deviceListeners);
    service.connect();
  }
  if (isDeviceReady == true) {
    Util.runOnUI(new Runnable(){
      @Override public void run(){
        for (        ConnectableDeviceListenerPair pair : deviceListeners) {
          pair.listener.onDeviceReady(pair.device);
        }
      }
    }
);
  }
}

Fixed version (ground truth):
/** 
 * Enumerates through all DeviceServices and attempts to connect to each of them. When all of a ConnectableDevice's DeviceServices are ready to receive commands, the ConnectableDevice will send a onDeviceReady message to its listener. It is always necessary to call connect on a ConnectableDevice, even if it contains no connectable DeviceServices.
 */
public void connect(){
  for (  DeviceService service : services.values()) {
    if (!service.isConnected()) {
      service.connect();
    }
  }
}
Program: 20898
Project: 20898
Buggy source:
@Override public void onConnectionSuccess(DeviceService service){
  if (listener != null) {
  }
  if (isConnected()) {
    DiscoveryManager.getInstance().getConnectableDeviceStore().addDevice(this);
    setLastConnected(Util.getTime());
  }
}

Fixed version (ground truth):
@Override public void onConnectionSuccess(DeviceService service){
  if (isConnected()) {
    DiscoveryManager.getInstance().getConnectableDeviceStore().addDevice(this);
    for (    ConnectableDeviceListenerPair pair : deviceListeners)     pair.listener.onDeviceReady(pair.device);
    setLastConnected(Util.getTime());
  }
}
Program: 20900
Project: 20900
Buggy source:
private boolean isNetcast(ServiceDescription description){
  return "String_Node_Str".equalsIgnoreCase(description.getModelName()) && "String_Node_Str".equalsIgnoreCase(description.getModelDescription());
}

Fixed version (ground truth):
public boolean isNetcast(ServiceDescription description){
  boolean isNetcastTV=false;
  String modelName=description.getModelName();
  String modelDescription=description.getModelDescription();
  if (modelName != null && modelName.toUpperCase(Locale.US).equals("String_Node_Str")) {
    if (modelDescription != null && !(modelDescription.toUpperCase(Locale.US).contains("String_Node_Str"))) {
      isNetcastTV=true;
    }
  }
  return isNetcastTV;
}
Program: 20901
Project: 20901
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){
  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
 */
public static synchronized void init(Context context,ConnectableDeviceStore connectableDeviceStore){
  instance=new DiscoveryManager(context,connectableDeviceStore);
}
Program: 20903
Project: 20903
Buggy source:
@Override public void disconnect(){
  isServiceReady=false;
  mApiClient.disconnect();
}

Fixed version (ground truth):
@Override public void disconnect(){
  mApiClient.disconnect();
}
Program: 20904
Project: 20904
Buggy source:
public CastService(ServiceDescription serviceDescription,ServiceConfig serviceConfig){
  super(serviceDescription,serviceConfig);
  setCapabilities();
  isServiceReady=false;
  this.castDevice=((CastServiceDescription)serviceDescription).getCastDevice();
  mCastClientListener=new CastListener();
  mConnectionCallbacks=new ConnectionCallbacks();
  mConnectionFailedListener=new ConnectionFailedListener();
  Cast.CastOptions.Builder apiOptionsBuilder=Cast.CastOptions.builder(castDevice,mCastClientListener);
  mApiClient=new GoogleApiClient.Builder(DiscoveryManager.getInstance().getContext()).addApi(Cast.API,apiOptionsBuilder.build()).addConnectionCallbacks(mConnectionCallbacks).addOnConnectionFailedListener(mConnectionFailedListener).build();
}

Fixed version (ground truth):
public CastService(ServiceDescription serviceDescription,ServiceConfig serviceConfig){
  super(serviceDescription,serviceConfig);
  setCapabilities();
  this.castDevice=((CastServiceDescription)serviceDescription).getCastDevice();
  mCastClientListener=new CastListener();
  mConnectionCallbacks=new ConnectionCallbacks();
  mConnectionFailedListener=new ConnectionFailedListener();
  Cast.CastOptions.Builder apiOptionsBuilder=Cast.CastOptions.builder(castDevice,mCastClientListener);
  mApiClient=new GoogleApiClient.Builder(DiscoveryManager.getInstance().getContext()).addApi(Cast.API,apiOptionsBuilder.build()).addConnectionCallbacks(mConnectionCallbacks).addOnConnectionFailedListener(mConnectionFailedListener).build();
}
Program: 20905
Project: 20905
Buggy source:
@Override public void onConnected(Bundle connectionHint){
  Log.d("String_Node_Str","String_Node_Str");
  isConnected=true;
  if (serviceReadyListener != null) {
    isServiceReady=true;
    serviceReadyListener.onServiceReady();
  }
}

Fixed version (ground truth):
@Override public void onConnected(Bundle connectionHint){
  Log.d("String_Node_Str","String_Node_Str");
  isConnected=true;
  if (listener != null) {
    Util.runOnUI(new Runnable(){
      @Override public void run(){
        listener.onConnectionSuccess(CastService.this);
      }
    }
);
  }
}
Program: 20906
Project: 20906
Buggy source:
/** 
 * Enumerates through all DeviceServices and attempts to connect to each of them. When all of a ConnectableDevice's DeviceServices are ready to receive commands, the ConnectableDevice will send a onDeviceReady message to its listener. It is always necessary to call connect on a ConnectableDevice, even if it contains no connectable DeviceServices.
 */
public void connect(){
  boolean isDeviceReady=true;
  for (  DeviceService service : services.values()) {
    if (service.isServiceReady() == false) {
      service.setServiceReadyListener(serviceReadyListener);
      isDeviceReady=false;
    }
    service.setDeviceListeners(deviceListeners);
    service.connect();
  }
  if (isDeviceReady == true) {
    Util.runOnUI(new Runnable(){
      @Override public void run(){
        for (        ConnectableDeviceListenerPair pair : deviceListeners) {
          pair.listener.onDeviceReady(pair.device);
        }
      }
    }
);
  }
}

Fixed version (ground truth):
/** 
 * Enumerates through all DeviceServices and attempts to connect to each of them. When all of a ConnectableDevice's DeviceServices are ready to receive commands, the ConnectableDevice will send a onDeviceReady message to its listener. It is always necessary to call connect on a ConnectableDevice, even if it contains no connectable DeviceServices.
 */
public void connect(){
  for (  DeviceService service : services.values()) {
    if (!service.isConnected()) {
      service.connect();
    }
  }
}
Program: 20907
Project: 20907
Buggy source:
@Override public void onConnectionSuccess(DeviceService service){
  if (listener != null) {
  }
  if (isConnected()) {
    DiscoveryManager.getInstance().getConnectableDeviceStore().addDevice(this);
    setLastConnected(Util.getTime());
  }
}

Fixed version (ground truth):
@Override public void onConnectionSuccess(DeviceService service){
  if (isConnected()) {
    DiscoveryManager.getInstance().getConnectableDeviceStore().addDevice(this);
    for (    ConnectableDeviceListenerPair pair : deviceListeners)     pair.listener.onDeviceReady(pair.device);
    setLastConnected(Util.getTime());
  }
}
Program: 20909
Project: 20909
Buggy source:
private boolean isNetcast(ServiceDescription description){
  return "String_Node_Str".equalsIgnoreCase(description.getModelName()) && "String_Node_Str".equalsIgnoreCase(description.getModelDescription());
}

Fixed version (ground truth):
public boolean isNetcast(ServiceDescription description){
  boolean isNetcastTV=false;
  String modelName=description.getModelName();
  String modelDescription=description.getModelDescription();
  if (modelName != null && modelName.toUpperCase(Locale.US).equals("String_Node_Str")) {
    if (modelDescription != null && !(modelDescription.toUpperCase(Locale.US).contains("String_Node_Str"))) {
      isNetcastTV=true;
    }
  }
  return isNetcastTV;
}
Program: 20910
Project: 20910
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){
  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
 */
public static synchronized void init(Context context,ConnectableDeviceStore connectableDeviceStore){
  instance=new DiscoveryManager(context,connectableDeviceStore);
}
Program: 20912
Project: 20912
Buggy source:
@Override public void disconnect(){
  isServiceReady=false;
  mApiClient.disconnect();
}

Fixed version (ground truth):
@Override public void disconnect(){
  mApiClient.disconnect();
}
Program: 20913
Project: 20913
Buggy source:
public CastService(ServiceDescription serviceDescription,ServiceConfig serviceConfig){
  super(serviceDescription,serviceConfig);
  setCapabilities();
  isServiceReady=false;
  this.castDevice=((CastServiceDescription)serviceDescription).getCastDevice();
  mCastClientListener=new CastListener();
  mConnectionCallbacks=new ConnectionCallbacks();
  mConnectionFailedListener=new ConnectionFailedListener();
  Cast.CastOptions.Builder apiOptionsBuilder=Cast.CastOptions.builder(castDevice,mCastClientListener);
  mApiClient=new GoogleApiClient.Builder(DiscoveryManager.getInstance().getContext()).addApi(Cast.API,apiOptionsBuilder.build()).addConnectionCallbacks(mConnectionCallbacks).addOnConnectionFailedListener(mConnectionFailedListener).build();
}

Fixed version (ground truth):
public CastService(ServiceDescription serviceDescription,ServiceConfig serviceConfig){
  super(serviceDescription,serviceConfig);
  setCapabilities();
  this.castDevice=((CastServiceDescription)serviceDescription).getCastDevice();
  mCastClientListener=new CastListener();
  mConnectionCallbacks=new ConnectionCallbacks();
  mConnectionFailedListener=new ConnectionFailedListener();
  Cast.CastOptions.Builder apiOptionsBuilder=Cast.CastOptions.builder(castDevice,mCastClientListener);
  mApiClient=new GoogleApiClient.Builder(DiscoveryManager.getInstance().getContext()).addApi(Cast.API,apiOptionsBuilder.build()).addConnectionCallbacks(mConnectionCallbacks).addOnConnectionFailedListener(mConnectionFailedListener).build();
}
Program: 20914
Project: 20914
Buggy source:
@Override public void onConnected(Bundle connectionHint){
  Log.d("String_Node_Str","String_Node_Str");
  isConnected=true;
  if (serviceReadyListener != null) {
    isServiceReady=true;
    serviceReadyListener.onServiceReady();
  }
}

Fixed version (ground truth):
@Override public void onConnected(Bundle connectionHint){
  Log.d("String_Node_Str","String_Node_Str");
  isConnected=true;
  if (listener != null) {
    Util.runOnUI(new Runnable(){
      @Override public void run(){
        listener.onConnectionSuccess(CastService.this);
      }
    }
);
  }
}
Program: 20915
Project: 20915
Buggy source:
public CastService(ServiceDescription serviceDescription,ServiceConfig serviceConfig){
  super(serviceDescription,serviceConfig);
  setCapabilities();
  this.castDevice=((CastServiceDescription)serviceDescription).getCastDevice();
  mCastClientListener=new CastListener();
  mConnectionCallbacks=new ConnectionCallbacks();
  mConnectionFailedListener=new ConnectionFailedListener();
  Cast.CastOptions.Builder apiOptionsBuilder=Cast.CastOptions.builder(castDevice,mCastClientListener);
  mApiClient=new GoogleApiClient.Builder(DiscoveryManager.getInstance().getContext()).addApi(Cast.API,apiOptionsBuilder.build()).addConnectionCallbacks(mConnectionCallbacks).addOnConnectionFailedListener(mConnectionFailedListener).build();
}

Fixed version (ground truth):
public CastService(ServiceDescription serviceDescription,ServiceConfig serviceConfig){
  super(serviceDescription,serviceConfig);
  setCapabilities();
  mCastClientListener=new CastListener();
  mConnectionCallbacks=new ConnectionCallbacks();
  mConnectionFailedListener=new ConnectionFailedListener();
}
Program: 20916
Project: 20916
Buggy source:
@Override public void joinWebApp(final LaunchSession webAppLaunchSession,final WebAppSession.LaunchListener listener){
  Cast.CastApi.joinApplication(mApiClient,webAppLaunchSession.getAppId(),webAppLaunchSession.getSessionId()).setResultCallback(new ResultCallback<Cast.ApplicationConnectionResult>(){
    @Override public void onResult(    Cast.ApplicationConnectionResult result){
      Status status=result.getStatus();
      if (status.isSuccess()) {
        Util.postSuccess(listener,new CastWebAppSession(webAppLaunchSession,CastService.this));
      }
 else {
        Util.postError(listener,new ServiceCommandError(result.getStatus().getStatusCode(),result.getStatus().toString(),result));
      }
    }
  }
);
}

Fixed version (ground truth):
@Override public void joinWebApp(String webAppId,WebAppSession.LaunchListener listener){
  LaunchSession launchSession=LaunchSession.launchSessionForAppId(webAppId);
  launchSession.setSessionType(LaunchSessionType.WebApp);
  launchSession.setService(this);
  joinWebApp(launchSession,listener);
}
Program: 20917
Project: 20917
Buggy source:
@Override public void joinWebApp(final LaunchSession webAppLaunchSession,final WebAppSession.LaunchListener listener){
  final WebOSWebAppSession webAppSession=new WebOSWebAppSession(webAppLaunchSession,this);
  webAppSession.join(new ResponseListener<Object>(){
    @Override public void onError(    ServiceCommandError error){
      Util.postError(listener,error);
    }
    @Override public void onSuccess(    Object object){
      Util.postSuccess(listener,webAppSession);
    }
  }
);
}

Fixed version (ground truth):
@Override public void joinWebApp(String webAppId,WebAppSession.LaunchListener listener){
  LaunchSession launchSession=LaunchSession.launchSessionForAppId(webAppId);
  launchSession.setSessionType(LaunchSessionType.WebApp);
  launchSession.setService(this);
  joinWebApp(launchSession,listener);
}
Program: 20919
Project: 20919
Buggy source:
public void joinWebApp(LaunchSession webAppLaunchSession,LaunchListener listener);

Fixed version (ground truth):
public void joinWebApp(String webAppId,LaunchListener listener);
Program: 20920
Project: 20920
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: 20921
Project: 20921
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: 20922
Project: 20922
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: 20923
Project: 20923
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: 20924
Project: 20924
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: 20925
Project: 20925
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: 20926
Project: 20926
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: 20928
Project: 20928
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: 20929
Project: 20929
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: 20930
Project: 20930
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);
}