nus-yam/ex-repair huggingface dataset:
Program: 26681
Project: 26681
Buggy source:
/** 
 * Reads the title of a fat beacon broadcast.
 * @param serviceData The ble advertised Eddystone URL Service UUID service data
 * @return Title encoded in the broadcast
 */
public static String getFatBeaconTitle(byte[] serviceData){
  if (serviceData.length > 2) {
    String title=new String(Arrays.copyOfRange(serviceData,3,serviceData.length)).trim();
    return title.indexOf('\uFFFD') == -1 ? title : "String_Node_Str";
  }
  return "String_Node_Str";
}

Fixed version (ground truth):
/** 
 * Reads the title of a fat beacon broadcast.
 * @param serviceData The ble advertised Eddystone URL Service UUID service data
 * @return Title encoded in the broadcast
 */
public static String getFatBeaconTitle(byte[] serviceData){
  if (serviceData.length > 2) {
    byte[] bytes=Arrays.copyOfRange(serviceData,3,serviceData.length);
    String title=new String(bytes,Charset.forName("String_Node_Str")).trim();
    return title.indexOf('\uFFFD') == -1 ? title : "String_Node_Str";
  }
  return "String_Node_Str";
}
Program: 26682
Project: 26682
Buggy source:
@Test public void getFatBeaconTitleTest(){
  assertEquals("String_Node_Str",EddystoneBeacon.getFatBeaconTitle(new byte[]{}));
  assertEquals("String_Node_Str",EddystoneBeacon.getFatBeaconTitle(new byte[]{0x01}));
  assertEquals("String_Node_Str",EddystoneBeacon.getFatBeaconTitle(new byte[]{0x01,0x02}));
  assertEquals("String_Node_Str",EddystoneBeacon.getFatBeaconTitle(new byte[]{0x01,0x02,0x00}));
  String title="String_Node_Str";
  int length=title.getBytes().length;
  byte[] serviceData=new byte[length + 3];
  System.arraycopy(title.getBytes(),0,serviceData,3,length);
  serviceData[0]=0x10;
  serviceData[1]=0x00;
  serviceData[2]=0x0e;
  assertEquals(title,EddystoneBeacon.getFatBeaconTitle(serviceData));
}

Fixed version (ground truth):
@Test public void getFatBeaconTitleTest() throws UnsupportedEncodingException {
  assertEquals("String_Node_Str",EddystoneBeacon.getFatBeaconTitle(new byte[]{}));
  assertEquals("String_Node_Str",EddystoneBeacon.getFatBeaconTitle(new byte[]{0x01}));
  assertEquals("String_Node_Str",EddystoneBeacon.getFatBeaconTitle(new byte[]{0x01,0x02}));
  assertEquals("String_Node_Str",EddystoneBeacon.getFatBeaconTitle(new byte[]{0x01,0x02,0x00}));
  String title="String_Node_Str";
  byte[] titleBytes=title.getBytes("String_Node_Str");
  int length=titleBytes.length;
  byte[] serviceData=new byte[length + 3];
  System.arraycopy(titleBytes,0,serviceData,3,length);
  serviceData[0]=0x10;
  serviceData[1]=0x00;
  serviceData[2]=0x0e;
  assertEquals(title,EddystoneBeacon.getFatBeaconTitle(serviceData));
}
Program: 26685
Project: 26685
Buggy source:
private void restoreCache(){
  SharedPreferences prefs=PreferenceManager.getDefaultSharedPreferences(this);
  int prefsVersion=prefs.getInt(PREFS_VERSION_KEY,0);
  long now=new Date().getTime();
  if (prefsVersion != PREFS_VERSION) {
    mScanStartTime=now;
    return;
  }
  mScanStartTime=prefs.getLong(SCAN_START_TIME_KEY,0);
  scanDelta=now - mScanStartTime;
  if (scanDelta >= SCAN_STALE_TIME_MILLIS) {
    mScanStartTime=now;
    return;
  }
  try {
    JSONObject serializedCollection=new JSONObject(prefs.getString(PW_COLLECTION_KEY,null));
    mPwCollection=PhysicalWebCollection.jsonDeserialize(serializedCollection);
    Utils.setPwsEndpoint(this,mPwCollection);
  }
 catch (  JSONException e) {
    Log.e(TAG,"String_Node_Str",e);
  }
catch (  PhysicalWebCollectionException e) {
    Log.e(TAG,"String_Node_Str",e);
  }
  for (  UrlDevice urlDevice : mPwCollection.getUrlDevices()) {
    if (Utils.isBleUrlDevice(urlDevice)) {
      Utils.updateRegion(urlDevice);
    }
  }
  if (scanDelta >= LOCAL_SCAN_STALE_TIME_MILLIS) {
    for (    UrlDevice urlDevice : mPwCollection.getUrlDevices()) {
      if (!Utils.isResolvableDevice(urlDevice)) {
        mPwCollection.removeUrlDevice(urlDevice);
      }
    }
  }
}

Fixed version (ground truth):
private void restoreCache(){
  SharedPreferences prefs=PreferenceManager.getDefaultSharedPreferences(this);
  int prefsVersion=prefs.getInt(PREFS_VERSION_KEY,0);
  long now=new Date().getTime();
  if (prefsVersion != PREFS_VERSION) {
    mScanStartTime=now;
    return;
  }
  mScanStartTime=prefs.getLong(SCAN_START_TIME_KEY,0);
  long scanDelta=now - mScanStartTime;
  if (scanDelta >= SCAN_STALE_TIME_MILLIS) {
    mScanStartTime=now;
    return;
  }
  try {
    JSONObject serializedCollection=new JSONObject(prefs.getString(PW_COLLECTION_KEY,null));
    mPwCollection=PhysicalWebCollection.jsonDeserialize(serializedCollection);
    Utils.setPwsEndpoint(this,mPwCollection);
  }
 catch (  JSONException e) {
    Log.e(TAG,"String_Node_Str",e);
  }
catch (  PhysicalWebCollectionException e) {
    Log.e(TAG,"String_Node_Str",e);
  }
  for (  UrlDevice urlDevice : mPwCollection.getUrlDevices()) {
    if (Utils.isBleUrlDevice(urlDevice)) {
      Utils.updateRegion(urlDevice);
    }
  }
  if (scanDelta >= LOCAL_SCAN_STALE_TIME_MILLIS) {
    for (    UrlDevice urlDevice : mPwCollection.getUrlDevices()) {
      if (!Utils.isResolvableDevice(urlDevice)) {
        mPwCollection.removeUrlDevice(urlDevice);
      }
    }
  }
}
Program: 26686
Project: 26686
Buggy source:
@Override public void onPeersAvailable(WifiP2pDeviceList list){
  Log.d(TAG,list.toString());
  for (  WifiP2pDevice device : list.getDeviceList()) {
    Utils.WifiDirectInfo info=Utils.parseWifiDirectName(device.deviceName);
    if (info != null) {
      String name=info.title;
      int port=info.port;
      reportUrlDevice(createUrlDeviceBuilder("String_Node_Str" + name,device.deviceAddress + "String_Node_Str" + port).setWifiAddress(device.deviceAddress).setWifiPort(port).setTitle(name).setDescription("String_Node_Str").build());
    }
  }
}

Fixed version (ground truth):
@Override public void onPeersAvailable(WifiP2pDeviceList list){
  Log.d(TAG,list.toString());
  for (  WifiP2pDevice device : list.getDeviceList()) {
    Utils.WifiDirectInfo info=Utils.parseWifiDirectName(device.deviceName);
    if (info != null) {
      String name=info.title;
      int port=info.port;
      reportUrlDevice(createUrlDeviceBuilder("String_Node_Str" + name,device.deviceAddress + "String_Node_Str" + port).setWifiAddress(device.deviceAddress).setWifiPort(port).setTitle(name).setDescription("String_Node_Str").setDeviceType(Utils.WIFI_DIRECT_DEVICE_TYPE).build());
    }
  }
}
Program: 26687
Project: 26687
Buggy source:
@Override public void onServiceConnected(ComponentName className,IBinder service){
  UrlDeviceDiscoveryService.LocalBinder localBinder=(UrlDeviceDiscoveryService.LocalBinder)service;
  localBinder.getServiceInstance().clearCache();
  mContext.unbindService(this);
}

Fixed version (ground truth):
@Override public void onServiceConnected(ComponentName className,IBinder service){
  UrlDeviceDiscoveryService.LocalBinder localBinder=(UrlDeviceDiscoveryService.LocalBinder)service;
  localBinder.getServiceInstance().restartScan();
  mContext.unbindService(this);
}
Program: 26688
Project: 26688
Buggy source:
/** 
 * Starts scanning with UrlDeviceDisoveryService.
 * @param context The context for the service.
 */
public static void startScan(Context context){
  new ServiceConnection(){
    private Context mContext;
    @Override public void onServiceConnected(    ComponentName className,    IBinder service){
      UrlDeviceDiscoveryService.LocalBinder localBinder=(UrlDeviceDiscoveryService.LocalBinder)service;
      localBinder.getServiceInstance().clearCache();
      mContext.unbindService(this);
    }
    @Override public void onServiceDisconnected(    ComponentName className){
    }
    public void connect(    Context context){
      mContext=context;
      Intent intent=new Intent(mContext,UrlDeviceDiscoveryService.class);
      mContext.startService(intent);
      mContext.bindService(intent,this,Context.BIND_AUTO_CREATE);
    }
  }
.connect(context);
}

Fixed version (ground truth):
/** 
 * Starts scanning with UrlDeviceDisoveryService.
 * @param context The context for the service.
 */
public static void startScan(Context context){
  new ServiceConnection(){
    private Context mContext;
    @Override public void onServiceConnected(    ComponentName className,    IBinder service){
      UrlDeviceDiscoveryService.LocalBinder localBinder=(UrlDeviceDiscoveryService.LocalBinder)service;
      localBinder.getServiceInstance().restartScan();
      mContext.unbindService(this);
    }
    @Override public void onServiceDisconnected(    ComponentName className){
    }
    public void connect(    Context context){
      mContext=context;
      Intent intent=new Intent(mContext,UrlDeviceDiscoveryService.class);
      mContext.startService(intent);
      mContext.bindService(intent,this,Context.BIND_AUTO_CREATE);
    }
  }
.connect(context);
}
Program: 26689
Project: 26689
Buggy source:
@Override public void onUrlDeviceDiscoveryUpdate(){
  for (  PwPair pwPair : mPwCollection.getGroupedPwPairsSortedByRank()) {
    String groupId=Utils.getGroupId(pwPair.getPwsResult());
    Log.d(TAG,"String_Node_Str" + groupId);
    if (mNearbyDeviceAdapter.containsGroupId(groupId)) {
      mNearbyDeviceAdapter.updateItem(pwPair);
    }
 else     if (!mGroupIdQueue.contains(groupId)) {
      mGroupIdQueue.add(groupId);
      if (mSecondScanComplete) {
        emptyGroupIdQueue();
      }
    }
  }
  safeNotifyChange();
}

Fixed version (ground truth):
@Override public void onUrlDeviceDiscoveryUpdate(){
  for (  PwPair pwPair : mPwCollection.getGroupedPwPairsSortedByRank()) {
    String groupId=Utils.getGroupId(pwPair.getPwsResult());
    Log.d(TAG,"String_Node_Str" + groupId);
    if (mNearbyDeviceAdapter.containsGroupId(groupId)) {
      mNearbyDeviceAdapter.updateItem(pwPair);
    }
 else     if (!mGroupIdQueue.contains(groupId)) {
      mGroupIdQueue.add(groupId);
      if (mSecondScanComplete) {
        emptyGroupIdQueue();
      }
    }
  }
  notifyChangeOnUiThread();
}
Program: 26690
Project: 26690
Buggy source:
private void startScanningDisplay(long scanStartTime,boolean hasResults){
  Log.d(TAG,"String_Node_Str" + scanStartTime + "String_Node_Str"+ hasResults);
  long elapsedMillis=new Date().getTime() - scanStartTime;
  if (elapsedMillis < FIRST_SCAN_TIME_MILLIS || (elapsedMillis < SECOND_SCAN_TIME_MILLIS && !hasResults)) {
    mScanningAnimationTextView.setAlpha(1f);
    mScanningAnimationDrawable.start();
    getListView().setVisibility(View.INVISIBLE);
  }
 else {
    showListView();
  }
  mSecondScanComplete=false;
  long firstDelay=Math.max(FIRST_SCAN_TIME_MILLIS - elapsedMillis,50);
  long secondDelay=Math.max(SECOND_SCAN_TIME_MILLIS - elapsedMillis,50);
  long thirdDelay=Math.max(THIRD_SCAN_TIME_MILLIS - elapsedMillis,50);
  mHandler.postDelayed(mFirstScanTimeout,firstDelay);
  mHandler.postDelayed(mSecondScanTimeout,secondDelay);
  mHandler.postDelayed(mThirdScanTimeout,thirdDelay);
}

Fixed version (ground truth):
private void startScanningDisplay(long scanStartTime,boolean hasResults){
  Log.d(TAG,"String_Node_Str" + scanStartTime + "String_Node_Str"+ hasResults);
  long elapsedMillis=new Date().getTime() - scanStartTime;
  if (elapsedMillis < FIRST_SCAN_TIME_MILLIS || (elapsedMillis < SECOND_SCAN_TIME_MILLIS && !hasResults)) {
    mNearbyDeviceAdapter.clear();
    mScanningAnimationTextView.setAlpha(1f);
    mScanningAnimationDrawable.start();
  }
 else {
    mSwipeRefreshWidget.setRefreshing(false);
  }
  mSecondScanComplete=false;
  long firstDelay=Math.max(FIRST_SCAN_TIME_MILLIS - elapsedMillis,0);
  long secondDelay=Math.max(SECOND_SCAN_TIME_MILLIS - elapsedMillis,0);
  long thirdDelay=Math.max(THIRD_SCAN_TIME_MILLIS - elapsedMillis,0);
  mHandler.postDelayed(mFirstScanTimeout,firstDelay);
  mHandler.postDelayed(mSecondScanTimeout,secondDelay);
  mHandler.postDelayed(mThirdScanTimeout,thirdDelay);
}
Program: 26691
Project: 26691
Buggy source:
@Override public synchronized void onServiceConnected(ComponentName className,IBinder service){
  UrlDeviceDiscoveryService.LocalBinder localBinder=(UrlDeviceDiscoveryService.LocalBinder)service;
  mDiscoveryService=localBinder.getServiceInstance();
  mDiscoveryService.addCallback(NearbyBeaconsFragment.this);
  if (!mRequestCachedUrlDevices) {
    mDiscoveryService.restartScan();
  }
  mPwCollection=mDiscoveryService.getPwCollection();
  startScanningDisplay(mDiscoveryService.getScanStartTime(),mDiscoveryService.hasResults());
}

Fixed version (ground truth):
@Override public synchronized void onServiceConnected(ComponentName className,IBinder service){
  UrlDeviceDiscoveryService.LocalBinder localBinder=(UrlDeviceDiscoveryService.LocalBinder)service;
  mDiscoveryService=localBinder.getServiceInstance();
  mDiscoveryService.addCallback(NearbyBeaconsFragment.this);
  if (!mRequestCachedUrlDevices) {
    mDiscoveryService.restartScan();
  }
  mPwCollection=mDiscoveryService.getPwCollection();
  onUrlDeviceDiscoveryUpdate();
  startScanningDisplay(mDiscoveryService.getScanStartTime(),mDiscoveryService.hasResults());
}
Program: 26692
Project: 26692
Buggy source:
private void emptyGroupIdQueue(){
  List<PwPair> pwPairs=new ArrayList<>();
  for (  String groupId : mGroupIdQueue) {
    Log.d(TAG,"String_Node_Str" + groupId);
    pwPairs.add(Utils.getTopRankedPwPairByGroupId(mPwCollection,groupId));
  }
  Collections.sort(pwPairs,Collections.reverseOrder());
  for (  PwPair pwPair : pwPairs) {
    mNearbyDeviceAdapter.addItem(pwPair);
  }
  mGroupIdQueue.clear();
  safeNotifyChange();
}

Fixed version (ground truth):
private void emptyGroupIdQueue(){
  List<PwPair> pwPairs=new ArrayList<>();
  for (  String groupId : mGroupIdQueue) {
    Log.d(TAG,"String_Node_Str" + groupId);
    pwPairs.add(Utils.getTopRankedPwPairByGroupId(mPwCollection,groupId));
  }
  Collections.sort(pwPairs,Collections.reverseOrder());
  for (  PwPair pwPair : pwPairs) {
    mNearbyDeviceAdapter.addItem(pwPair);
  }
  mGroupIdQueue.clear();
  notifyChangeOnUiThread();
}
Program: 26693
Project: 26693
Buggy source:
@Override public void onResume(){
  super.onResume();
  getActivity().getActionBar().setTitle(R.string.title_nearby_beacons);
  getActivity().getActionBar().setDisplayHomeAsUpEnabled(false);
  getListView().setVisibility(View.INVISIBLE);
  if (mFirstTime && !mMainActivity.isCheckingPermissions()) {
    restartScan();
  }
  mFirstTime=false;
}

Fixed version (ground truth):
@Override public void onResume(){
  super.onResume();
  getActivity().getActionBar().setTitle(R.string.title_nearby_beacons);
  getActivity().getActionBar().setDisplayHomeAsUpEnabled(false);
  if (mFirstTime && !mMainActivity.isCheckingPermissions()) {
    restartScan();
  }
  mFirstTime=false;
}
Program: 26694
Project: 26694
Buggy source:
/** 
 * Check if the given URL only uses characters from the set defined in RFC 3986 section 2 https://tools.ietf.org/html/rfc3986#section-2
 * @param url URL to check
 * @return True if the URL is RFC 3986 compliant
 */
private static boolean isAsciiUrl(String url){
  boolean isCompliant=false;
  try {
    URI uri=new URI(url);
    String urlString=uri.toASCIIString();
    isCompliant=url.equals(urlString);
  }
 catch (  URISyntaxException e) {
  }
  return isCompliant;
}

Fixed version (ground truth):
/** 
 * Check if the given URL only uses characters from the set defined in RFC 3986 section 2. https://tools.ietf.org/html/rfc3986#section-2
 * @param url URL to check
 * @return True if the URL is RFC 3986 compliant
 */
private static boolean isAsciiUrl(String url){
  boolean isCompliant=false;
  try {
    URI uri=new URI(url);
    String urlString=uri.toASCIIString();
    isCompliant=url.equals(urlString);
  }
 catch (  URISyntaxException e) {
  }
  return isCompliant;
}
Program: 26695
Project: 26695
Buggy source:
@Override public String getItem(int i){
  return mSortedDevices.get(i);
}

Fixed version (ground truth):
@Override public String getItem(int i){
  return mSortedUrls.get(i);
}
Program: 26696
Project: 26696
Buggy source:
@Override public int getCount(){
  return mSortedDevices.size();
}

Fixed version (ground truth):
@Override public int getCount(){
  return mSortedUrls.size();
}
Program: 26698
Project: 26698
Buggy source:
@Override public void onListItemClick(ListView l,View v,int position,long id){
  if (mIsScanRunning) {
    return;
  }
  String url=mNearbyDeviceAdapter.getUrlForListItem(position);
  String urlToNavigateTo=url;
  if (mUrlToUrlMetadata.get(url) != null) {
    String siteUrl=mUrlToUrlMetadata.get(url).siteUrl;
    if (siteUrl != null) {
      urlToNavigateTo=siteUrl;
    }
  }
  openUrlInBrowser(urlToNavigateTo);
}

Fixed version (ground truth):
@Override public void onListItemClick(ListView l,View v,int position,long id){
  if (mIsScanRunning) {
    return;
  }
  String url=mNearbyDeviceAdapter.getItem(position);
  String urlToNavigateTo=url;
  if (mUrlToUrlMetadata.get(url) != null) {
    String siteUrl=mUrlToUrlMetadata.get(url).siteUrl;
    if (siteUrl != null) {
      urlToNavigateTo=siteUrl;
    }
  }
  openUrlInBrowser(urlToNavigateTo);
}
Program: 26699
Project: 26699
Buggy source:
public void clear(){
  mSortedDevices.clear();
  mUrlToDeviceAddress.clear();
  notifyDataSetChanged();
}

Fixed version (ground truth):
public void clear(){
  mSortedUrls.clear();
  mUrlToDeviceAddress.clear();
  notifyDataSetChanged();
}
Program: 26700
Project: 26700
Buggy source:
@Override public void onUrlMetadataReceived(String url,PwsClient.UrlMetadata urlMetadata){
  mUrlToUrlMetadata.put(url,urlMetadata);
  String mockAddress=generateMockBluetoothAddress(url.hashCode());
  int mockRssi=0;
  int mockTxPower=0;
  mNearbyDeviceAdapter.addItem(url,mockAddress,mockTxPower);
  mNearbyDeviceAdapter.updateItem(url,mockAddress,mockRssi,mockTxPower);
  mNearbyDeviceAdapter.sortDevices();
  mNearbyDeviceAdapter.notifyDataSetChanged();
  mSwipeRefreshWidget.setRefreshing(false);
  fadeInListView();
}

Fixed version (ground truth):
@Override public void onUrlMetadataReceived(String url,PwsClient.UrlMetadata urlMetadata){
  mUrlToUrlMetadata.put(url,urlMetadata);
  String mockAddress=generateMockBluetoothAddress(url.hashCode());
  int mockRssi=0;
  int mockTxPower=0;
  mNearbyDeviceAdapter.addItem(url,mockAddress,mockTxPower);
  mNearbyDeviceAdapter.updateItem(url,mockAddress,mockRssi,mockTxPower);
  mNearbyDeviceAdapter.sortUrls();
  mNearbyDeviceAdapter.notifyDataSetChanged();
  mSwipeRefreshWidget.setRefreshing(false);
  fadeInListView();
}
Program: 26701
Project: 26701
Buggy source:
NearbyBeaconsAdapter(){
  mUrlToDeviceAddress=new HashMap<>();
  mUrlToTxPower=new HashMap<>();
  mRegionResolver=new RegionResolver();
  mSortedDevices=new ArrayList<>();
}

Fixed version (ground truth):
NearbyBeaconsAdapter(){
  mUrlToDeviceAddress=new HashMap<>();
  mUrlToTxPower=new HashMap<>();
  mRegionResolver=new RegionResolver();
  mSortedUrls=new ArrayList<>();
}
Program: 26702
Project: 26702
Buggy source:
private void handleFoundDevice(ScanResult scanResult){
  long timeStamp=scanResult.getTimestampNanos();
  long now=TimeUnit.MILLISECONDS.toNanos(System.currentTimeMillis());
  if (now - timeStamp < TimeUnit.SECONDS.toNanos(TIMEOUT_FOR_OLD_BEACONS)) {
    UriBeacon uriBeacon=UriBeacon.parseFromBytes(scanResult.getScanRecord().getBytes());
    if (uriBeacon != null) {
      String url=uriBeacon.getUriString();
      if (url != null && url.isEmpty()) {
        String address=scanResult.getDevice().getAddress();
        int rssi=scanResult.getRssi();
        int txPower=uriBeacon.getTxPowerLevel();
        if (!mUrlToUrlMetadata.containsKey(url)) {
          mUrlToUrlMetadata.put(url,null);
          mPublicUrls.add(url);
          mDeviceAddressToUrl.put(address,url);
          MetadataResolver.findUrlMetadata(this,UriBeaconDiscoveryService.this,url,txPower,rssi);
        }
        mRegionResolver.onUpdate(address,rssi,txPower);
      }
    }
  }
}

Fixed version (ground truth):
private void handleFoundDevice(ScanResult scanResult){
  long timeStamp=scanResult.getTimestampNanos();
  long now=TimeUnit.MILLISECONDS.toNanos(System.currentTimeMillis());
  if (now - timeStamp < TimeUnit.SECONDS.toNanos(TIMEOUT_FOR_OLD_BEACONS)) {
    UriBeacon uriBeacon=UriBeacon.parseFromBytes(scanResult.getScanRecord().getBytes());
    if (uriBeacon != null) {
      String url=uriBeacon.getUriString();
      if (url != null && !url.isEmpty()) {
        String address=scanResult.getDevice().getAddress();
        int rssi=scanResult.getRssi();
        int txPower=uriBeacon.getTxPowerLevel();
        if (!mUrlToUrlMetadata.containsKey(url)) {
          mUrlToUrlMetadata.put(url,null);
          mPublicUrls.add(url);
          mDeviceAddressToUrl.put(address,url);
          MetadataResolver.findUrlMetadata(this,UriBeaconDiscoveryService.this,url,txPower,rssi);
        }
        mRegionResolver.onUpdate(address,rssi,txPower);
      }
    }
  }
}
Program: 26703
Project: 26703
Buggy source:
public synchronized boolean start(Integer timeout) throws IOException {
  if (mThread == null) {
    mMulticastSocket=new MulticastSocket(SSDP_PORT);
    if (timeout != null && timeout > 0) {
      mMulticastSocket.setSoTimeout(timeout);
    }
    mThread=new Thread(this);
    mThread.start();
    return true;
  }
  return false;
}

Fixed version (ground truth):
public synchronized boolean start(Integer timeout) throws IOException {
  if (mThread == null) {
    mMulticastSocket=new DatagramSocket(SSDP_PORT);
    if (timeout != null && timeout > 0) {
      mMulticastSocket.setSoTimeout(timeout);
    }
    mThread=new Thread(this);
    mThread.start();
    return true;
  }
  return false;
}
Program: 26704
Project: 26704
Buggy source:
private void handleFoundDevice(ScanResult scanResult){
  UriBeacon uriBeacon=UriBeacon.parseFromBytes(scanResult.getScanRecord().getBytes());
  if (uriBeacon != null) {
    String address=scanResult.getDevice().getAddress();
    int rssi=scanResult.getRssi();
    int txPowerLevel=uriBeacon.getTxPowerLevel();
    String url=uriBeacon.getUriString();
    if (!mUrlToUrlMetadata.containsKey(url)) {
      mUrlToUrlMetadata.put(url,null);
      mDeviceAddressToUrl.put(address,url);
      MetadataResolver.findUrlMetadata(this,UriBeaconDiscoveryService.this,url);
    }
    mRegionResolver.onUpdate(address,rssi,txPowerLevel);
  }
}

Fixed version (ground truth):
private void handleFoundDevice(ScanResult scanResult){
  long timeStamp=scanResult.getTimestampNanos();
  long now=TimeUnit.MILLISECONDS.toNanos(System.currentTimeMillis());
  if (now - timeStamp < TimeUnit.SECONDS.toNanos(2)) {
    UriBeacon uriBeacon=UriBeacon.parseFromBytes(scanResult.getScanRecord().getBytes());
    if (uriBeacon != null) {
      String address=scanResult.getDevice().getAddress();
      int rssi=scanResult.getRssi();
      int txPowerLevel=uriBeacon.getTxPowerLevel();
      String url=uriBeacon.getUriString();
      if (!mUrlToUrlMetadata.containsKey(url)) {
        mUrlToUrlMetadata.put(url,null);
        mDeviceAddressToUrl.put(address,url);
        MetadataResolver.findUrlMetadata(this,UriBeaconDiscoveryService.this,url);
      }
      mRegionResolver.onUpdate(address,rssi,txPowerLevel);
    }
  }
}
Program: 26705
Project: 26705
Buggy source:
@Override public void onDestroy(){
  Log.d(TAG,"String_Node_Str");
  stopSearchingForUriBeacons();
  mMdnsUrlDiscoverer.stopScanning();
  unregisterReceiver(mScreenStateBroadcastReceiver);
  mUrlToUrlMetadata=new HashMap<>();
  cancelNotifications();
}

Fixed version (ground truth):
@Override public void onDestroy(){
  Log.d(TAG,"String_Node_Str");
  stopSearchingForUriBeacons();
  mMdnsUrlDiscoverer.stopScanning();
  unregisterReceiver(mScreenStateBroadcastReceiver);
  mUrlToUrlMetadata=new HashMap<>();
  mNotificationManager.cancelAll();
}
Program: 26706
Project: 26706
Buggy source:
/** 
 * Create a new set of notifications or update those existing
 */
private void updateNotifications(){
  mSortedDevices=new ArrayList<>(mDeviceAddressToUrl.keySet());
  Collections.sort(mSortedDevices,mComparator);
  if (mSortedDevices.size() == 0) {
    cancelNotifications();
    return;
  }
  if (mSortedDevices.size() > 0) {
    updateNearbyBeaconNotification(mDeviceAddressToUrl.get(mSortedDevices.get(0)),NEAREST_BEACON_NOTIFICATION_ID);
  }
  if (mSortedDevices.size() > 1) {
    updateNearbyBeaconNotification(mDeviceAddressToUrl.get(mSortedDevices.get(1)),SECOND_NEAREST_BEACON_NOTIFICATION_ID);
    updateSummaryNotification();
  }
}

Fixed version (ground truth):
/** 
 * Create a new set of notifications or update those existing
 */
private void updateNotifications(){
  mSortedDevices=new ArrayList<>(mDeviceAddressToUrl.keySet());
  Collections.sort(mSortedDevices,mComparator);
  if (mSortedDevices.size() == 0) {
    mNotificationManager.cancelAll();
    return;
  }
  if (mSortedDevices.size() > 0) {
    updateNearbyBeaconNotification(mDeviceAddressToUrl.get(mSortedDevices.get(0)),NEAREST_BEACON_NOTIFICATION_ID);
  }
  if (mSortedDevices.size() > 1) {
    updateNearbyBeaconNotification(mDeviceAddressToUrl.get(mSortedDevices.get(1)),SECOND_NEAREST_BEACON_NOTIFICATION_ID);
    updateSummaryNotification();
  }
}
Program: 26707
Project: 26707
Buggy source:
@Override public void onReceive(Context context,Intent intent){
  boolean isScreenOn=Intent.ACTION_SCREEN_ON.equals(intent.getAction());
  if (isScreenOn) {
    startSearchingForUriBeacons();
    mMdnsUrlDiscoverer.startScanning();
  }
 else {
    stopSearchingForUriBeacons();
    mMdnsUrlDiscoverer.stopScanning();
  }
}

Fixed version (ground truth):
@Override public void onReceive(Context context,Intent intent){
  boolean isScreenOn=Intent.ACTION_SCREEN_ON.equals(intent.getAction());
  if (isScreenOn) {
    startSearchingForUriBeacons();
    mMdnsUrlDiscoverer.startScanning();
  }
 else {
    initializeCleanVariables();
    mNotificationManager.cancelAll();
    stopSearchingForUriBeacons();
    mMdnsUrlDiscoverer.stopScanning();
  }
}
Program: 26708
Project: 26708
Buggy source:
private void initialize(){
  mRegionResolver=new RegionResolver();
  mNotificationManager=NotificationManagerCompat.from(this);
  mUrlToUrlMetadata=new HashMap<>();
  mSortedDevices=null;
  mDeviceAddressToUrl=new HashMap<>();
  mMdnsUrlDiscoverer=new MdnsUrlDiscoverer(this,UriBeaconDiscoveryService.this);
  initializeScreenStateBroadcastReceiver();
}

Fixed version (ground truth):
private void initialize(){
  mNotificationManager=NotificationManagerCompat.from(this);
  mMdnsUrlDiscoverer=new MdnsUrlDiscoverer(this,UriBeaconDiscoveryService.this);
  initializeCleanVariables();
  initializeScreenStateBroadcastReceiver();
}
Program: 26709
Project: 26709
Buggy source:
/** 
 * Called when the user presses the keyboard "DONE" key
 */
private void onEditorAction_nearestConfigurableBeaconUrlEditTextDoneKeyPressed(){
  hideSoftKeyboard();
  String url=mEditCardUrl.getText().toString();
  BeaconConfigHelper.writeBeaconUrl(getActivity(),this,mNearestDevice,url);
}

Fixed version (ground truth):
/** 
 * Called when the user presses the keyboard "DONE" key
 */
private void onEditorAction_nearestConfigurableBeaconUrlEditTextDoneKeyPressed(){
  hideSoftKeyboard();
  String url=mEditCardUrl.getText().toString();
  try {
    byte[] scanRecord=BeaconHelper.createAdvertisingPacket(url);
    mBeaconConfig.writeUriBeacon(scanRecord);
  }
 catch (  URISyntaxException e) {
  }
}
Program: 26710
Project: 26710
Buggy source:
@Override public void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  mRegionResolver=new RegionResolver();
  setHasOptionsMenu(true);
  getActivity().getActionBar().setDisplayHomeAsUpEnabled(true);
}

Fixed version (ground truth):
@Override public void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  mRegionResolver=new RegionResolver();
  mBeaconConfig=new BeaconConfigHelper(getActivity(),this);
  setHasOptionsMenu(true);
  getActivity().getActionBar().setDisplayHomeAsUpEnabled(true);
}
Program: 26711
Project: 26711
Buggy source:
private void handleFoundDevice(final ScanResult scanResult){
  final String address=scanResult.getDevice().getAddress();
  int rxPower=scanResult.getRssi();
  Log.i(TAG,String.format("String_Node_Str",address,rxPower));
  mRegionResolver.onUpdate(address,rxPower,TX_POWER_DEFAULT);
  final String nearestAddress=mRegionResolver.getNearestAddress();
  if (address.equals(nearestAddress)) {
    getActivity().runOnUiThread(new Runnable(){
      @Override public void run(){
        mNearestDevice=scanResult.getDevice();
        stopSearchingForDevices();
        mScanningImageView.setVisibility(View.INVISIBLE);
        mStatusTextView.setText(getString(R.string.config_found_beacon_text));
        mConfigurableBeaconAddressTextView.setText(nearestAddress);
        final Context context=BeaconConfigFragment.this.getActivity();
        BeaconConfigHelper.readBeaconUrl(context,BeaconConfigFragment.this,mNearestDevice);
      }
    }
);
  }
 else {
    Log.d(TAG,"String_Node_Str" + address);
  }
}

Fixed version (ground truth):
private void handleFoundDevice(final ScanResult scanResult){
  final String address=scanResult.getDevice().getAddress();
  int rxPower=scanResult.getRssi();
  Log.i(TAG,String.format("String_Node_Str",address,rxPower));
  mRegionResolver.onUpdate(address,rxPower,TX_POWER_DEFAULT);
  final String nearestAddress=mRegionResolver.getNearestAddress();
  if (address.equals(nearestAddress)) {
    getActivity().runOnUiThread(new Runnable(){
      @Override public void run(){
        mNearestDevice=scanResult.getDevice();
        stopSearchingForDevices();
        mScanningImageView.setVisibility(View.INVISIBLE);
        mStatusTextView.setText(getString(R.string.config_found_beacon_text));
        mConfigurableBeaconAddressTextView.setText(nearestAddress);
        final Context context=BeaconConfigFragment.this.getActivity();
        mBeaconConfig.connectUriBeacon(mNearestDevice);
      }
    }
);
  }
 else {
    Log.d(TAG,"String_Node_Str" + address);
  }
}
Program: 26712
Project: 26712
Buggy source:
@Override public void onPause(){
  super.onPause();
  mScanningAnimationDrawable.stop();
  stopSearchingForDevices();
}

Fixed version (ground truth):
@Override public void onPause(){
  super.onPause();
  mScanningAnimationDrawable.stop();
  stopSearchingForDevices();
  mBeaconConfig.closeUriBeacon();
}
Program: 26713
Project: 26713
Buggy source:
@Override public void run(){
  mNearestDevice=scanResult.getDevice();
  stopSearchingForDevices();
  mScanningImageView.setVisibility(View.INVISIBLE);
  mStatusTextView.setText(getString(R.string.config_found_beacon_text));
  mConfigurableBeaconAddressTextView.setText(nearestAddress);
  final Context context=BeaconConfigFragment.this.getActivity();
  BeaconConfigHelper.readBeaconUrl(context,BeaconConfigFragment.this,mNearestDevice);
}

Fixed version (ground truth):
@Override public void run(){
  getFragmentManager().popBackStack();
  int msgId=(status == BluetoothGatt.GATT_SUCCESS) ? R.string.config_url_saved : R.string.config_url_error;
  Toast.makeText(getActivity(),getString(msgId),Toast.LENGTH_SHORT).show();
}
Program: 26714
Project: 26714
Buggy source:
/** 
 * This is the class that listens for when the user taps the write-to-beacon button.
 */
public void onWriteToBeaconButtonClick(View view){
  mStatusTextView.setText(getString(R.string.config_writing_to_beacon_text));
  mEditCard.clearFocus();
  String url=mEditCardUrl.getText().toString();
  BeaconConfigHelper.writeBeaconUrl(getActivity(),BeaconConfigFragment.this,mNearestDevice,url);
}

Fixed version (ground truth):
/** 
 * This is the class that listens for when the user taps the write-to-beacon button.
 */
public void onWriteToBeaconButtonClick(View view){
  mStatusTextView.setText(getString(R.string.config_writing_to_beacon_text));
  mEditCard.clearFocus();
  String url=mEditCardUrl.getText().toString();
  try {
    byte[] scanRecord=BeaconHelper.createAdvertisingPacket(url);
    mBeaconConfig.writeUriBeacon(scanRecord);
  }
 catch (  URISyntaxException e) {
  }
}
Program: 26715
Project: 26715
Buggy source:
@Override public void onResume(){
  super.onResume();
  if (!mIsDemoMode) {
    getActivity().getActionBar().setTitle(R.string.title_nearby_beacons);
    startScanning();
  }
 else {
    getActivity().getActionBar().setTitle(R.string.title_nearby_beacons_demo);
  }
}

Fixed version (ground truth):
@Override public void onResume(){
  super.onResume();
  if (!mIsDemoMode) {
    getActivity().getActionBar().setTitle(R.string.title_nearby_beacons);
    getActivity().getActionBar().setDisplayHomeAsUpEnabled(false);
    startScanning();
  }
 else {
    getActivity().getActionBar().setTitle(R.string.title_nearby_beacons_demo);
  }
}
Program: 26716
Project: 26716
Buggy source:
@Override public void onResume(){
  super.onResume();
  if (!mIsDemoMode) {
    getActivity().getActionBar().setTitle(R.string.title_nearby_beacons);
    startScanning();
  }
 else {
    getActivity().getActionBar().setTitle(R.string.title_nearby_beacons_demo);
  }
}

Fixed version (ground truth):
@Override public void onResume(){
  super.onResume();
  if (!mIsDemoMode) {
    getActivity().getActionBar().setTitle(R.string.title_nearby_beacons);
    getActivity().getActionBar().setDisplayHomeAsUpEnabled(false);
    startScanning();
  }
 else {
    getActivity().getActionBar().setTitle(R.string.title_nearby_beacons_demo);
  }
}
Program: 26717
Project: 26717
Buggy source:
/** 
 * Called when the user presses the keyboard "DONE" key
 * @throws IOException
 */
private void onEditorAction_nearestConfigurableBeaconUrlEditTextDoneKeyPressed(){
  hideSoftKeyboard();
  String url=mConfigurableBeaconUrlEditText.getText().toString();
  BeaconConfigHelper.writeBeaconUrl(getActivity(),this,mFoundConfigurableBeaconBluetoothDevice,url);
}

Fixed version (ground truth):
/** 
 * Called when the user presses the keyboard "DONE" key
 */
private void onEditorAction_nearestConfigurableBeaconUrlEditTextDoneKeyPressed(){
  hideSoftKeyboard();
  String url=mConfigurableBeaconUrlEditText.getText().toString();
  BeaconConfigHelper.writeBeaconUrl(getActivity(),this,mFoundConfigurableBeaconBluetoothDevice,url);
}
Program: 26718
Project: 26718
Buggy source:
/** 
 * Find the url that is encoded into the scan record, but also expand a short url and ensure an http prefix exists.
 * @param scanRecord
 * @return
 */
public static String createUrlFromScanRecord(byte[] scanRecord){
  String url=null;
  UriBeacon uriBeacon=UriBeacon.parseFromBytes(scanRecord);
  if (uriBeacon != null) {
    url=uriBeacon.getUriString();
  }
  if (url != null) {
    if (UrlShortener.isShortUrl(url)) {
      url=UrlShortener.lengthenShortUrl(url);
    }
  }
  return url;
}

Fixed version (ground truth):
/** 
 * Find the url that is encoded into the scan record, but also expand a short url and ensure an http prefix exists.
 * @param scanRecord encoded url
 * @return The url that was encoded the scan record.
 */
public static String createUrlFromScanRecord(byte[] scanRecord){
  String url=null;
  UriBeacon uriBeacon=UriBeacon.parseFromBytes(scanRecord);
  if (uriBeacon != null) {
    url=uriBeacon.getUriString();
  }
  if (url != null) {
    if (UrlShortener.isShortUrl(url)) {
      url=UrlShortener.lengthenShortUrl(url);
    }
  }
  return url;
}
Program: 26719
Project: 26719
Buggy source:
/** 
 * Run actions given that the read operation of part 1 of the beacon's advertising packet has completed.
 * @param bluetoothGattCharacteristic
 */
private static void handleGattCharacteristicRead_beaconDataPart1(BluetoothGattCharacteristic bluetoothGattCharacteristic){
  mAdvertisingPacketData_read=bluetoothGattCharacteristic.getValue();
  readCharacteristic_beaconDataLength();
}

Fixed version (ground truth):
/** 
 * Run actions given that the read operation of part 1 of the beacon's advertising packet has completed.
 * @param bluetoothGattCharacteristic Data Part 1 characteristic that was read from the associated remote device.
 */
private static void handleGattCharacteristicRead_beaconDataPart1(BluetoothGattCharacteristic bluetoothGattCharacteristic){
  mAdvertisingPacketData_read=bluetoothGattCharacteristic.getValue();
  readCharacteristic_beaconDataLength();
}
Program: 26720
Project: 26720
Buggy source:
/** 
 * Run actions given that the read operation of part 1 of the beacon's advertising packet has completed.
 * @param bluetoothGattCharacteristic
 */
private static void handleGattCharacteristicRead_beaconDataPart2(BluetoothGattCharacteristic bluetoothGattCharacteristic){
  byte[] data_part2=bluetoothGattCharacteristic.getValue();
  ByteArrayOutputStream outputStream=new ByteArrayOutputStream();
  try {
    outputStream.write(mAdvertisingPacketData_read);
    outputStream.write(data_part2);
    mAdvertisingPacketData_read=outputStream.toByteArray();
    onReadComplete_beaconData();
  }
 catch (  IOException e) {
    e.printStackTrace();
  }
}

Fixed version (ground truth):
/** 
 * Run actions given that the read operation of part 1 of the beacon's advertising packet has completed.
 * @param bluetoothGattCharacteristic Data part 2 characteristic that was read from the associated remote device.
 */
private static void handleGattCharacteristicRead_beaconDataPart2(BluetoothGattCharacteristic bluetoothGattCharacteristic){
  byte[] data_part2=bluetoothGattCharacteristic.getValue();
  ByteArrayOutputStream outputStream=new ByteArrayOutputStream();
  try {
    outputStream.write(mAdvertisingPacketData_read);
    outputStream.write(data_part2);
    mAdvertisingPacketData_read=outputStream.toByteArray();
    onReadComplete_beaconData();
  }
 catch (  IOException e) {
    e.printStackTrace();
  }
}
Program: 26721
Project: 26721
Buggy source:
/** 
 * Write the given url to the currently-being-configured beacon. This involves constructing the adverstising packet that contains the url and then pushing that packet to the beacon via GATT.
 * @param url
 */
public static void writeBeaconUrl(Context context,BeaconConfigCallback beaconConfigCallback,BluetoothDevice beaconBluetoothDevice,String url){
  Log.d(TAG,"String_Node_Str" + "String_Node_Str" + url);
  Log.d(TAG,"String_Node_Str" + mBeaconBluetoothGattService);
  beginWritingBeaconAdvertisingPacket(url);
}

Fixed version (ground truth):
/** 
 * Write the given url to the currently-being-configured beacon. This involves constructing the adverstising packet that contains the url and then pushing that packet to the beacon via GATT.
 * @param url URL to write to the beacon
 */
public static void writeBeaconUrl(Context context,BeaconConfigCallback beaconConfigCallback,BluetoothDevice beaconBluetoothDevice,String url){
  Log.d(TAG,"String_Node_Str" + "String_Node_Str" + url);
  Log.d(TAG,"String_Node_Str" + mBeaconBluetoothGattService);
  beginWritingBeaconAdvertisingPacket(url);
}
Program: 26722
Project: 26722
Buggy source:
/** 
 * Start the process of writing an advertising packet that contains the given url to the currently-being-configured beacon.
 * @param url
 */
private static void beginWritingBeaconAdvertisingPacket(String url){
  try {
    mAdvertisingPacketData_write=BeaconHelper.createAdvertisingPacket(url);
  }
 catch (  IOException e) {
    e.printStackTrace();
  }
  byte[] data_toWrite;
  if (mAdvertisingPacketData_write.length <= MAX_NUM_BYTES_DATA_PART_1) {
    data_toWrite=mAdvertisingPacketData_write;
  }
 else {
    data_toWrite=Arrays.copyOfRange(mAdvertisingPacketData_write,0,MAX_NUM_BYTES_DATA_PART_1);
  }
  writeCharacteristic_beaconDataPart1(data_toWrite);
}

Fixed version (ground truth):
/** 
 * Start the process of writing an advertising packet that contains the given url to the currently-being-configured beacon.
 * @param url URL to write to the beacon
 */
private static void beginWritingBeaconAdvertisingPacket(String url){
  try {
    mAdvertisingPacketData_write=BeaconHelper.createAdvertisingPacket(url);
  }
 catch (  IOException e) {
    e.printStackTrace();
  }
  byte[] data_toWrite;
  if (mAdvertisingPacketData_write.length <= MAX_NUM_BYTES_DATA_PART_1) {
    data_toWrite=mAdvertisingPacketData_write;
  }
 else {
    data_toWrite=Arrays.copyOfRange(mAdvertisingPacketData_write,0,MAX_NUM_BYTES_DATA_PART_1);
  }
  writeCharacteristic_beaconDataPart1(data_toWrite);
}
Program: 26723
Project: 26723
Buggy source:
/** 
 * Called when the operation to read a beacon's GATT service has completed.
 * @param bluetoothGattCharacteristic
 */
private static void onNearbyBeaconsGattCharacteristicRead(BluetoothGattCharacteristic bluetoothGattCharacteristic){
  if (bluetoothGattCharacteristic.getUuid().equals(UUID_BEACON_DATA_PART_1)) {
    handleGattCharacteristicRead_beaconDataPart1(bluetoothGattCharacteristic);
  }
 else   if (bluetoothGattCharacteristic.getUuid().equals(UUID_BEACON_DATA_LENGTH)) {
    handleGattCharacteristicRead_beaconDataLength(bluetoothGattCharacteristic);
  }
 else   if (bluetoothGattCharacteristic.getUuid().equals(UUID_BEACON_DATA_PART_2)) {
    handleGattCharacteristicRead_beaconDataPart2(bluetoothGattCharacteristic);
  }
}

Fixed version (ground truth):
/** 
 * Called when the operation to read a beacon's GATT service has completed.
 * @param bluetoothGattCharacteristic Characteristic that was read from the associated remote device.
 */
private static void onNearbyBeaconsGattCharacteristicRead(BluetoothGattCharacteristic bluetoothGattCharacteristic){
  if (bluetoothGattCharacteristic.getUuid().equals(UUID_BEACON_DATA_PART_1)) {
    handleGattCharacteristicRead_beaconDataPart1(bluetoothGattCharacteristic);
  }
 else   if (bluetoothGattCharacteristic.getUuid().equals(UUID_BEACON_DATA_LENGTH)) {
    handleGattCharacteristicRead_beaconDataLength(bluetoothGattCharacteristic);
  }
 else   if (bluetoothGattCharacteristic.getUuid().equals(UUID_BEACON_DATA_PART_2)) {
    handleGattCharacteristicRead_beaconDataPart2(bluetoothGattCharacteristic);
  }
}
Program: 26724
Project: 26724
Buggy source:
/** 
 * Write the given data to the beacon's advertising packet. This only writes part 2 which is up to 8 bytes of the packet data and is appended to the data from part 1.
 * @param data
 */
private static void writeCharacteristic_beaconDataPart2(byte[] data){
  BluetoothGattCharacteristic characteristic_beaconDataPart2=mBeaconBluetoothGattService.getCharacteristic(UUID_BEACON_DATA_PART_2);
  characteristic_beaconDataPart2.setValue(data);
  mBluetoothGatt.writeCharacteristic(characteristic_beaconDataPart2);
}

Fixed version (ground truth):
/** 
 * Write the given data to the beacon's advertising packet. This only writes part 2 which is up to 8 bytes of the packet data and is appended to the data from part 1.
 * @param data Second part of the data to write to the beacon; up to 8 bytes.
 */
private static void writeCharacteristic_beaconDataPart2(byte[] data){
  BluetoothGattCharacteristic characteristic_beaconDataPart2=mBeaconBluetoothGattService.getCharacteristic(UUID_BEACON_DATA_PART_2);
  characteristic_beaconDataPart2.setValue(data);
  mBluetoothGatt.writeCharacteristic(characteristic_beaconDataPart2);
}
Program: 26725
Project: 26725
Buggy source:
/** 
 * Run actions given that the read operation of the length of the beacon's advertising packet has completed.
 * @param bluetoothGattCharacteristic
 */
private static void handleGattCharacteristicRead_beaconDataLength(BluetoothGattCharacteristic bluetoothGattCharacteristic){
  int dataLength=(int)bluetoothGattCharacteristic.getValue()[0];
  if (dataLength > MAX_NUM_BYTES_DATA_PART_1) {
    readCharacteristic_beaconDataPart2();
  }
 else {
    onReadComplete_beaconData();
  }
}

Fixed version (ground truth):
/** 
 * Run actions given that the read operation of the length of the beacon's advertising packet has completed.
 * @param bluetoothGattCharacteristic Length characteristic that was read from the associated remote device.
 */
private static void handleGattCharacteristicRead_beaconDataLength(BluetoothGattCharacteristic bluetoothGattCharacteristic){
  int dataLength=(int)bluetoothGattCharacteristic.getValue()[0];
  if (dataLength > MAX_NUM_BYTES_DATA_PART_1) {
    readCharacteristic_beaconDataPart2();
  }
 else {
    onReadComplete_beaconData();
  }
}
Program: 26726
Project: 26726
Buggy source:
/** 
 * Run actions given that the data was successfully written to part 1 of the beacon advertising packet.
 * @param bluetoothGattCharacteristic
 */
private static void handleGattCharacteristicWrite_beaconDataPart1(BluetoothGattCharacteristic bluetoothGattCharacteristic){
  if (mAdvertisingPacketData_write.length <= MAX_NUM_BYTES_DATA_PART_1) {
    onWriteComplete_beaconData();
  }
 else {
    byte[] data_toWrite=Arrays.copyOfRange(mAdvertisingPacketData_write,MAX_NUM_BYTES_DATA_PART_1,mAdvertisingPacketData_write.length);
    writeCharacteristic_beaconDataPart2(data_toWrite);
  }
}

Fixed version (ground truth):
/** 
 * Run actions given that the data was successfully written to part 1 of the beacon advertising packet.
 * @param bluetoothGattCharacteristic Data part 1 characteristic that was written to the associated remote device.
 */
private static void handleGattCharacteristicWrite_beaconDataPart1(BluetoothGattCharacteristic bluetoothGattCharacteristic){
  if (mAdvertisingPacketData_write.length <= MAX_NUM_BYTES_DATA_PART_1) {
    onWriteComplete_beaconData();
  }
 else {
    byte[] data_toWrite=Arrays.copyOfRange(mAdvertisingPacketData_write,MAX_NUM_BYTES_DATA_PART_1,mAdvertisingPacketData_write.length);
    writeCharacteristic_beaconDataPart2(data_toWrite);
  }
}
Program: 26727
Project: 26727
Buggy source:
/** 
 * Run actions given that the data was successfully written to part 2 of the beacon advertising packet.
 * @param bluetoothGattCharacteristic
 */
private static void handleGattCharacteristicWrite_beaconDataPart2(BluetoothGattCharacteristic bluetoothGattCharacteristic){
  onWriteComplete_beaconData();
}

Fixed version (ground truth):
/** 
 * Run actions given that the data was successfully written to part 2 of the beacon advertising packet.
 * @param bluetoothGattCharacteristic Data part 2 characteristic that was written to the associated remote device.
 */
private static void handleGattCharacteristicWrite_beaconDataPart2(BluetoothGattCharacteristic bluetoothGattCharacteristic){
  onWriteComplete_beaconData();
}
Program: 26728
Project: 26728
Buggy source:
/** 
 * Called when a characteristic write operation has occurred
 * @param gatt
 * @param characteristic
 * @param status
 */
@Override public void onCharacteristicWrite(BluetoothGatt gatt,BluetoothGattCharacteristic characteristic,int status){
  if (status == BluetoothGatt.GATT_SUCCESS) {
    onNearbyBeaconsGattCharacteristicWrite(characteristic);
  }
}

Fixed version (ground truth):
/** 
 * Called when a characteristic write operation has occurred
 * @param gatt GATT client that called writeCharacteristic
 * @param characteristic Characteristic that was written to the associated remote device.
 * @param status The result of the write operation GATT_SUCCESS if the operation succeeds.
 */
@Override public void onCharacteristicWrite(BluetoothGatt gatt,BluetoothGattCharacteristic characteristic,int status){
  if (status == BluetoothGatt.GATT_SUCCESS) {
    onNearbyBeaconsGattCharacteristicWrite(characteristic);
  }
}
Program: 26729
Project: 26729
Buggy source:
/** 
 * Write the given data to the beacon's advertising packet. This only writes part 1 which is up to 20 bytes of the packet data.
 * @param data
 */
private static void writeCharacteristic_beaconDataPart1(byte[] data){
  BluetoothGattCharacteristic characteristic_beaconDataPart1=mBeaconBluetoothGattService.getCharacteristic(UUID_BEACON_DATA_PART_1);
  characteristic_beaconDataPart1.setValue(data);
  mBluetoothGatt.writeCharacteristic(characteristic_beaconDataPart1);
}

Fixed version (ground truth):
/** 
 * Write the given data to the beacon's advertising packet. This only writes part 1 which is up to 20 bytes of the packet data.
 * @param data First part of the data to write to the beacon; up to 20 bytes
 */
private static void writeCharacteristic_beaconDataPart1(byte[] data){
  BluetoothGattCharacteristic characteristic_beaconDataPart1=mBeaconBluetoothGattService.getCharacteristic(UUID_BEACON_DATA_PART_1);
  characteristic_beaconDataPart1.setValue(data);
  mBluetoothGatt.writeCharacteristic(characteristic_beaconDataPart1);
}