nus-yam/ex-repair huggingface dataset:
Program: 32373
Project: 32373
Buggy source:
protected synchronized boolean sendMessageToRouterService(Message message,int retryCount){
  if (message == null) {
    Log.w(TAG,"String_Node_Str");
    return false;
  }
  if (isBound && routerServiceMessenger != null) {
    if (registeredWithRouterService || message.what == TransportConstants.ROUTER_REGISTER_CLIENT) {
      try {
        routerServiceMessenger.send(message);
        return true;
      }
 catch (      RemoteException e) {
        e.printStackTrace();
        if (e instanceof TransactionTooLargeException || (retryCount < 5 && routerServiceMessenger.getBinder().isBinderAlive() && routerServiceMessenger.getBinder().pingBinder())) {
          try {
            Thread.sleep(100);
          }
 catch (          InterruptedException e1) {
            e1.printStackTrace();
          }
          return sendMessageToRouterService(message,retryCount++);
        }
 else {
          Log.d(TAG,"String_Node_Str");
          routerServiceMessenger=null;
          registeredWithRouterService=false;
          isBound=false;
          onHardwareDisconnected(null);
          return false;
        }
      }
    }
 else {
      Log.e(TAG,"String_Node_Str");
      return false;
    }
  }
 else {
    Log.e(TAG,"String_Node_Str");
    return false;
  }
}

Fixed version (ground truth):
protected synchronized boolean sendMessageToRouterService(Message message,int retryCount){
  if (message == null) {
    Log.w(TAG,"String_Node_Str");
    return false;
  }
  if (isBound && routerServiceMessenger != null) {
    if (registeredWithRouterService || message.what == TransportConstants.ROUTER_REGISTER_CLIENT) {
      try {
        routerServiceMessenger.send(message);
        return true;
      }
 catch (      RemoteException e) {
        e.printStackTrace();
        if (e instanceof TransactionTooLargeException || (retryCount < 5 && routerServiceMessenger.getBinder().isBinderAlive() && routerServiceMessenger.getBinder().pingBinder())) {
          try {
            Thread.sleep(100);
          }
 catch (          InterruptedException e1) {
            e1.printStackTrace();
          }
          return sendMessageToRouterService(message,retryCount++);
        }
 else {
          Log.d(TAG,"String_Node_Str");
          routerServiceMessenger=null;
          registeredWithRouterService=false;
          isBound=false;
          onHardwareDisconnected(null);
          return false;
        }
      }
catch (      NullPointerException e) {
        Log.d(TAG,"String_Node_Str");
        routerServiceMessenger=null;
        registeredWithRouterService=false;
        isBound=false;
        onHardwareDisconnected(null);
        return false;
      }
    }
 else {
      Log.e(TAG,"String_Node_Str");
      return false;
    }
  }
 else {
    Log.e(TAG,"String_Node_Str");
    return false;
  }
}
Program: 32374
Project: 32374
Buggy source:
@Override public void onCreate(){
  super.onCreate();
  if (!processCheck()) {
    Log.e(TAG,"String_Node_Str");
    wrongProcess=true;
    stopSelf();
    return;
  }
  if (!AndroidTools.isServiceExported(this,new ComponentName(this,this.getClass()))) {
    Log.e(TAG,"String_Node_Str");
    stopSelf();
    return;
  }
 else {
    Log.d(TAG,"String_Node_Str");
  }
synchronized (REGISTERED_APPS_LOCK) {
    registeredApps=new HashMap<Long,RegisteredApp>();
  }
  closing=false;
  currentContext=getBaseContext();
  startVersionCheck();
  Log.i(TAG,"String_Node_Str");
synchronized (SESSION_LOCK) {
    this.sessionMap=new SparseArray<Long>();
    this.sessionHashIdMap=new SparseArray<Integer>();
  }
  packetExecuter=Executors.newSingleThreadExecutor();
}

Fixed version (ground truth):
@Override public void onCreate(){
  super.onCreate();
  if (!initCheck()) {
    stopSelf();
    return;
  }
  initPassed=true;
synchronized (REGISTERED_APPS_LOCK) {
    registeredApps=new HashMap<Long,RegisteredApp>();
  }
  closing=false;
  currentContext=getBaseContext();
  startVersionCheck();
  Log.i(TAG,"String_Node_Str");
synchronized (SESSION_LOCK) {
    this.sessionMap=new SparseArray<Long>();
    this.sessionHashIdMap=new SparseArray<Integer>();
  }
  packetExecuter=Executors.newSingleThreadExecutor();
}
Program: 32375
Project: 32375
Buggy source:
@Override public int onStartCommand(Intent intent,int flags,int startId){
  if (registeredApps == null) {
synchronized (REGISTERED_APPS_LOCK) {
      registeredApps=new HashMap<Long,RegisteredApp>();
    }
  }
  if (intent != null) {
    if (intent.hasExtra(TransportConstants.PING_ROUTER_SERVICE_EXTRA)) {
      if (startSequenceComplete) {
        Log.i(TAG,"String_Node_Str");
        initBluetoothSerialService();
      }
    }
  }
  shouldServiceRemainOpen(intent);
  return super.onStartCommand(intent,flags,startId);
}

Fixed version (ground truth):
@Override public int onStartCommand(Intent intent,int flags,int startId){
  if (!initPassed) {
    return super.onStartCommand(intent,flags,startId);
  }
  if (registeredApps == null) {
synchronized (REGISTERED_APPS_LOCK) {
      registeredApps=new HashMap<Long,RegisteredApp>();
    }
  }
  if (intent != null) {
    if (intent.hasExtra(TransportConstants.PING_ROUTER_SERVICE_EXTRA)) {
      if (startSequenceComplete) {
        Log.i(TAG,"String_Node_Str");
        initBluetoothSerialService();
      }
    }
  }
  shouldServiceRemainOpen(intent);
  return super.onStartCommand(intent,flags,startId);
}
Program: 32377
Project: 32377
Buggy source:
/** 
 * Indicate that the connection was lost and notify the UI Activity.
 */
private void connectionLost(){
  listening=false;
  Message msg=mHandler.obtainMessage(SdlRouterService.MESSAGE_TOAST);
  Bundle bundle=new Bundle();
  bundle.putString(TOAST,"String_Node_Str");
  msg.setData(bundle);
  getBluetoothSerialServerInstance().mHandler.sendMessage(msg);
  getBluetoothSerialServerInstance().stop();
}

Fixed version (ground truth):
/** 
 * Indicate that the connection was lost and notify the UI Activity.
 */
private void connectionLost(){
  Message msg=mHandler.obtainMessage(SdlRouterService.MESSAGE_TOAST);
  Bundle bundle=new Bundle();
  bundle.putString(TOAST,"String_Node_Str");
  msg.setData(bundle);
  getBluetoothSerialServerInstance().mHandler.sendMessage(msg);
  getBluetoothSerialServerInstance().stop();
}
Program: 32378
Project: 32378
Buggy source:
@SuppressLint("String_Node_Str") public AcceptThread(boolean secure){
synchronized (threadLock) {
    listening=false;
    BluetoothServerSocket tmp=null;
    mSocketType=secure ? "String_Node_Str" : "String_Node_Str";
    try {
      if (secure) {
        tmp=getBluetoothSerialServerInstance().mAdapter.listenUsingRfcommWithServiceRecord(NAME_SECURE,SERVER_UUID);
        listening=true;
      }
    }
 catch (    IOException e) {
      listening=false;
    }
catch (    SecurityException e2) {
      listening=false;
      interrupt();
    }
    mmServerSocket=tmp;
  }
}

Fixed version (ground truth):
@SuppressLint("String_Node_Str") public AcceptThread(boolean secure){
synchronized (threadLock) {
    BluetoothServerSocket tmp=null;
    mSocketType=secure ? "String_Node_Str" : "String_Node_Str";
    try {
      if (secure) {
        tmp=getBluetoothSerialServerInstance().mAdapter.listenUsingRfcommWithServiceRecord(NAME_SECURE,SERVER_UUID);
      }
    }
 catch (    IOException e) {
    }
catch (    SecurityException e2) {
      interrupt();
    }
    mmServerSocket=tmp;
  }
}
Program: 32379
Project: 32379
Buggy source:
/** 
 * We want to make sure we are in the right process here. If there is somesort of developer error  we want to just close out right away.
 * @return
 */
private boolean processCheck(){
  int myPid=android.os.Process.myPid();
  ActivityManager am=(ActivityManager)this.getSystemService(ACTIVITY_SERVICE);
  for (  RunningAppProcessInfo processInfo : am.getRunningAppProcesses()) {
    if (processInfo.pid == myPid) {
      return ROUTER_SERVICE_PROCESS.equals(processInfo.processName);
    }
  }
  return false;
}

Fixed version (ground truth):
/** 
 * We want to make sure we are in the right process here. If there is somesort of developer error  we want to just close out right away.
 * @return
 */
private boolean processCheck(){
  int myPid=android.os.Process.myPid();
  ActivityManager am=(ActivityManager)this.getSystemService(ACTIVITY_SERVICE);
  if (am == null || am.getRunningAppProcesses() == null)   return false;
  for (  RunningAppProcessInfo processInfo : am.getRunningAppProcesses()) {
    if (processInfo != null && processInfo.pid == myPid) {
      return ROUTER_SERVICE_PROCESS.equals(processInfo.processName);
    }
  }
  return false;
}
Program: 32380
Project: 32380
Buggy source:
public synchronized void cancel(){
  try {
    if (mmInStream != null) {
      mmInStream.close();
    }
    if (mmSocket != null) {
      mmSocket.close();
    }
  }
 catch (  IOException e) {
  }
}

Fixed version (ground truth):
public synchronized void cancel(){
  try {
    if (mmInStream != null) {
      mmInStream.close();
    }
    if (mmSocket != null) {
      mmSocket.close();
    }
  }
 catch (  IOException|NullPointerException e) {
  }
}
Program: 32381
Project: 32381
Buggy source:
@SuppressLint("String_Node_Str") public void run(){
  Log.d(TAG,"String_Node_Str");
  byte input=0;
  MultiplexBluetoothTransport.currentlyConnectedDevice=mmSocket.getRemoteDevice().getName();
  MultiplexBluetoothTransport.currentlyConnectedDeviceAddress=mmSocket.getRemoteDevice().getAddress();
  boolean stateProgress;
  psm.reset();
  while (true) {
    try {
      input=(byte)mmInStream.read();
      stateProgress=psm.handleByte(input);
      if (!stateProgress) {
        psm.reset();
        continue;
      }
      if (psm.getState() == SdlPsm.FINISHED_STATE) {
        mHandler.obtainMessage(SdlRouterService.MESSAGE_READ,psm.getFormedPacket()).sendToTarget();
        psm.reset();
      }
    }
 catch (    IOException e) {
      Log.e(TAG,"String_Node_Str");
      e.printStackTrace();
      connectionLost();
      break;
    }
  }
}

Fixed version (ground truth):
@SuppressLint("String_Node_Str") public void run(){
  Log.d(TAG,"String_Node_Str");
  byte input=0;
  MultiplexBluetoothTransport.currentlyConnectedDevice=mmSocket.getRemoteDevice().getName();
  MultiplexBluetoothTransport.currentlyConnectedDeviceAddress=mmSocket.getRemoteDevice().getAddress();
  boolean stateProgress;
  psm.reset();
  while (true) {
    try {
      input=(byte)mmInStream.read();
      stateProgress=psm.handleByte(input);
      if (!stateProgress) {
        psm.reset();
        continue;
      }
      if (psm.getState() == SdlPsm.FINISHED_STATE) {
        mHandler.obtainMessage(SdlRouterService.MESSAGE_READ,psm.getFormedPacket()).sendToTarget();
        psm.reset();
      }
    }
 catch (    IOException|NullPointerException e) {
      Log.e(TAG,"String_Node_Str");
      e.printStackTrace();
      connectionLost();
      break;
    }
  }
}
Program: 32384
Project: 32384
Buggy source:
private void readFromTransport(){
  try {
    try {
      byteRead=(byte)_input.read();
    }
 catch (    Exception e) {
      if (!isHalted) {
        clearInputStream();
        if (_adapter != null && !_adapter.isEnabled()) {
          disconnect("String_Node_Str",new SdlException("String_Node_Str",e,SdlExceptionCause.BLUETOOTH_DISABLED));
        }
 else {
          disconnect("String_Node_Str",e);
        }
      }
      return;
    }
    stateProgress=psm.handleByte(byteRead);
    if (!stateProgress) {
      psm.reset();
      if (byteRead == -1) {
        if (!isHalted) {
          DebugTool.logError("String_Node_Str");
          disconnect("String_Node_Str",null);
        }
      }
    }
    if (psm.getState() == SdlPsm.FINISHED_STATE) {
      handleReceivedPacket((SdlPacket)psm.getFormedPacket());
      psm.reset();
    }
  }
 catch (  Exception excp) {
    if (!isHalted) {
      clearInputStream();
      String errString="String_Node_Str" + excp.toString();
      DebugTool.logError(errString,excp);
      disconnect(errString,excp);
    }
    return;
  }
}

Fixed version (ground truth):
private void readFromTransport(){
  try {
    try {
      bytesRead=_input.read(buffer);
    }
 catch (    Exception e) {
      if (!isHalted) {
        clearInputStream();
        if (_adapter != null && !_adapter.isEnabled()) {
          disconnect("String_Node_Str",new SdlException("String_Node_Str",e,SdlExceptionCause.BLUETOOTH_DISABLED));
        }
 else {
          disconnect("String_Node_Str",e);
        }
      }
      return;
    }
    for (int i=0; i < bytesRead; i++) {
      currentByte=buffer[i];
      stateProgress=psm.handleByte(currentByte);
      if (!stateProgress) {
        psm.reset();
        if (currentByte == -1) {
          if (!isHalted) {
            DebugTool.logError("String_Node_Str");
            disconnect("String_Node_Str",null);
          }
        }
      }
      if (psm.getState() == SdlPsm.FINISHED_STATE) {
        handleReceivedPacket((SdlPacket)psm.getFormedPacket());
        psm.reset();
      }
    }
  }
 catch (  Exception excp) {
    if (!isHalted) {
      clearInputStream();
      String errString="String_Node_Str" + excp.toString();
      DebugTool.logError(errString,excp);
      disconnect(errString,excp);
    }
    return;
  }
}
Program: 32385
Project: 32385
Buggy source:
@SuppressLint("String_Node_Str") public void run(){
  Log.d(TAG,"String_Node_Str");
  byte input=0;
  MultiplexBluetoothTransport.currentlyConnectedDevice=mmSocket.getRemoteDevice().getName();
  MultiplexBluetoothTransport.currentlyConnectedDeviceAddress=mmSocket.getRemoteDevice().getAddress();
  boolean stateProgress;
  psm.reset();
  while (true) {
    try {
      input=(byte)mmInStream.read();
      stateProgress=psm.handleByte(input);
      if (!stateProgress) {
        psm.reset();
        continue;
      }
      if (psm.getState() == SdlPsm.FINISHED_STATE) {
        mHandler.obtainMessage(SdlRouterService.MESSAGE_READ,psm.getFormedPacket()).sendToTarget();
        psm.reset();
      }
    }
 catch (    IOException e) {
      Log.e(TAG,"String_Node_Str");
      e.printStackTrace();
      connectionLost();
      break;
    }
  }
}

Fixed version (ground truth):
@SuppressLint("String_Node_Str") public void run(){
  Log.d(TAG,"String_Node_Str");
  byte input=0;
  int bytesRead=0;
  byte[] buffer=new byte[READ_BUFFER_SIZE];
  MultiplexBluetoothTransport.currentlyConnectedDevice=mmSocket.getRemoteDevice().getName();
  MultiplexBluetoothTransport.currentlyConnectedDeviceAddress=mmSocket.getRemoteDevice().getAddress();
  boolean stateProgress;
  psm.reset();
  while (true) {
    try {
      bytesRead=mmInStream.read(buffer);
      Log.i(getClass().getName(),"String_Node_Str" + bytesRead + "String_Node_Str");
      for (int i=0; i < bytesRead; i++) {
        input=buffer[i];
        stateProgress=psm.handleByte(input);
        if (!stateProgress) {
          psm.reset();
          continue;
        }
        if (psm.getState() == SdlPsm.FINISHED_STATE) {
          mHandler.obtainMessage(SdlRouterService.MESSAGE_READ,psm.getFormedPacket()).sendToTarget();
          psm.reset();
        }
      }
    }
 catch (    IOException e) {
      Log.e(TAG,"String_Node_Str");
      e.printStackTrace();
      connectionLost();
      break;
    }
  }
}
Program: 32386
Project: 32386
Buggy source:
/** 
 * Performs actual thread work
 */
@Override public void run(){
  logInfo("String_Node_Str");
  psm.reset();
  while (!isHalted) {
    setCurrentState(TCPTransportState.CONNECTING);
    if (!connect()) {
      if (isHalted) {
        logInfo("String_Node_Str");
      }
 else {
        disconnect("String_Node_Str",new SdlException("String_Node_Str",SdlExceptionCause.SDL_CONNECTION_FAILED),true);
      }
      break;
    }
synchronized (TCPTransport.this) {
      setCurrentState(TCPTransportState.CONNECTED);
      handleTransportConnected();
    }
    byte input;
    boolean stateProgress=false;
    while (!isHalted) {
      logInfo("String_Node_Str");
      try {
        input=(byte)mInputStream.read();
      }
 catch (      IOException e) {
        internalHandleStreamReadError();
        break;
      }
synchronized (TCPTransport.this) {
        if (mThread.isInterrupted()) {
          logInfo("String_Node_Str");
          break;
        }
      }
      logInfo("String_Node_Str");
      stateProgress=psm.handleByte(input);
      if (!stateProgress) {
        psm.reset();
      }
      if (psm.getState() == SdlPsm.FINISHED_STATE) {
synchronized (TCPTransport.this) {
          handleReceivedPacket((SdlPacket)psm.getFormedPacket());
        }
        psm.reset();
      }
    }
  }
  logInfo("String_Node_Str");
  setCurrentState(TCPTransportState.IDLE);
}

Fixed version (ground truth):
/** 
 * Performs actual thread work
 */
@Override public void run(){
  logInfo("String_Node_Str");
  psm.reset();
  while (!isHalted) {
    setCurrentState(TCPTransportState.CONNECTING);
    if (!connect()) {
      if (isHalted) {
        logInfo("String_Node_Str");
      }
 else {
        disconnect("String_Node_Str",new SdlException("String_Node_Str",SdlExceptionCause.SDL_CONNECTION_FAILED),true);
      }
      break;
    }
synchronized (TCPTransport.this) {
      setCurrentState(TCPTransportState.CONNECTED);
      handleTransportConnected();
    }
    byte input;
    byte[] buffer=new byte[READ_BUFFER_SIZE];
    int bytesRead;
    boolean stateProgress=false;
    while (!isHalted) {
      try {
        bytesRead=mInputStream.read(buffer);
      }
 catch (      IOException e) {
        internalHandleStreamReadError();
        break;
      }
synchronized (TCPTransport.this) {
        if (mThread.isInterrupted()) {
          logInfo("String_Node_Str");
          break;
        }
      }
      for (int i=0; i < bytesRead; i++) {
        input=buffer[i];
        stateProgress=psm.handleByte(input);
        if (!stateProgress) {
          psm.reset();
        }
        if (psm.getState() == SdlPsm.FINISHED_STATE) {
synchronized (TCPTransport.this) {
            handleReceivedPacket((SdlPacket)psm.getFormedPacket());
          }
          psm.reset();
        }
      }
    }
  }
  logInfo("String_Node_Str");
  setCurrentState(TCPTransportState.IDLE);
}
Program: 32388
Project: 32388
Buggy source:
/** 
 * Using the knowledge that all SDL enabled apps have an SDL Broadcast Receiver that has an intent filter that includes a specific  intent. 
 * @return 
 */
private static List<SdlApp> findAllSdlApps(Context context){
  List<SdlApp> apps=new ArrayList<SdlApp>();
  PackageManager packageManager=context.getPackageManager();
  Intent intent=new Intent();
  intent.setAction("String_Node_Str");
  List<ResolveInfo> infoList=packageManager.queryBroadcastReceivers(intent,0);
  if (infoList != null) {
    String packageName;
    for (    ResolveInfo info : infoList) {
      packageName=info.activityInfo.packageName;
      try {
        apps.add(new SdlApp(packageName,packageManager.getPackageInfo(packageName,0).versionCode));
      }
 catch (      NameNotFoundException e) {
        e.printStackTrace();
      }
    }
    return apps;
  }
 else {
    Log.i(TAG,"String_Node_Str");
    return null;
  }
}

Fixed version (ground truth):
/** 
 * Using the knowledge that all SDL enabled apps have an SDL Broadcast Receiver that has an intent filter that includes a specific  intent. 
 * @return 
 */
private static List<SdlApp> findAllSdlApps(Context context){
  List<SdlApp> apps=new ArrayList<SdlApp>();
  PackageManager packageManager=context.getPackageManager();
  Intent intent=new Intent();
  intent.setAction("String_Node_Str");
  List<ResolveInfo> infoList=packageManager.queryBroadcastReceivers(intent,0);
  Collections.sort(infoList,new Comparator<ResolveInfo>(){
    @Override public int compare(    ResolveInfo lhs,    ResolveInfo rhs){
      return lhs.activityInfo.packageName.compareTo(rhs.activityInfo.packageName);
    }
  }
);
  if (infoList != null) {
    String packageName;
    for (    ResolveInfo info : infoList) {
      packageName=info.activityInfo.packageName;
      try {
        apps.add(new SdlApp(packageName,packageManager.getPackageInfo(packageName,0).versionCode));
      }
 catch (      NameNotFoundException e) {
        e.printStackTrace();
      }
    }
    return apps;
  }
 else {
    Log.i(TAG,"String_Node_Str");
    return null;
  }
}
Program: 32390
Project: 32390
Buggy source:
@Override public void httpCallComplete(String response){
  setTrustedList(context,response);
  pendingListRefresh=false;
  if (listCallback != null) {
    listCallback.onListObtained(true);
  }
}

Fixed version (ground truth):
@Override public void httpCallComplete(String response){
  setTrustedList(context,response);
  setLastRequest(context,object.toString());
  pendingListRefresh=false;
  if (listCallback != null) {
    listCallback.onListObtained(true);
  }
}
Program: 32392
Project: 32392
Buggy source:
/** 
 * Determines if an instance of the Router Service is currently running on the device. 
 * @param context A context to access Android system services through.
 * @param pingService Set this to true if you want to make sure the service is up and listening to bluetooth
 * @return True if a SDL Router Service is currently running, false otherwise.
 */
private static boolean isRouterServiceRunning(Context context,boolean pingService){
  if (context == null) {
    Log.e(TAG,"String_Node_Str");
    return false;
  }
  ActivityManager manager=(ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE);
  if (runningBluetoothServicePackage == null) {
    runningBluetoothServicePackage=new Vector<ComponentName>();
  }
 else {
    runningBluetoothServicePackage.clear();
  }
  for (  RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
    if ((service.service.getClassName()).toLowerCase(Locale.US).contains(SDL_ROUTER_SERVICE_CLASS_NAME)) {
      runningBluetoothServicePackage.add(service.service);
      if (pingService) {
        Intent intent=new Intent();
        intent.setClassName(service.service.getPackageName(),service.service.getClassName());
        intent.putExtra(TransportConstants.PING_ROUTER_SERVICE_EXTRA,pingService);
        context.startService(intent);
      }
    }
  }
  return runningBluetoothServicePackage.size() > 0;
}

Fixed version (ground truth):
/** 
 * Determines if an instance of the Router Service is currently running on the device. 
 * @param context A context to access Android system services through.
 * @param pingService Set this to true if you want to make sure the service is up and listening to bluetooth
 * @return True if a SDL Router Service is currently running, false otherwise.
 */
private static boolean isRouterServiceRunning(Context context,boolean pingService){
  if (context == null) {
    Log.e(TAG,"String_Node_Str");
    return false;
  }
  ActivityManager manager=(ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE);
  if (runningBluetoothServicePackage == null) {
    runningBluetoothServicePackage=new Vector<ComponentName>();
  }
 else {
    runningBluetoothServicePackage.clear();
  }
  for (  RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
    if ((service.service.getClassName()).toLowerCase(Locale.US).contains(SDL_ROUTER_SERVICE_CLASS_NAME) && AndroidTools.isServiceExported(context,service.service)) {
      runningBluetoothServicePackage.add(service.service);
      if (pingService) {
        Intent intent=new Intent();
        intent.setClassName(service.service.getPackageName(),service.service.getClassName());
        intent.putExtra(TransportConstants.PING_ROUTER_SERVICE_EXTRA,pingService);
        context.startService(intent);
      }
    }
  }
  return runningBluetoothServicePackage.size() > 0;
}
Program: 32393
Project: 32393
Buggy source:
@Override public void onCreate(){
  super.onCreate();
  if (!processCheck()) {
    Log.e(TAG,"String_Node_Str");
    wrongProcess=true;
    stopSelf();
    return;
  }
 else {
    Log.d(TAG,"String_Node_Str");
  }
synchronized (REGISTERED_APPS_LOCK) {
    registeredApps=new HashMap<Long,RegisteredApp>();
  }
  closing=false;
  currentContext=getBaseContext();
  startVersionCheck();
  Log.i(TAG,"String_Node_Str");
synchronized (SESSION_LOCK) {
    this.sessionMap=new SparseArray<Long>();
    this.sessionHashIdMap=new SparseArray<Integer>();
  }
  packetExecuter=Executors.newSingleThreadExecutor();
}

Fixed version (ground truth):
@Override public void onCreate(){
  super.onCreate();
  if (!processCheck()) {
    Log.e(TAG,"String_Node_Str");
    wrongProcess=true;
    stopSelf();
    return;
  }
  if (!AndroidTools.isServiceExported(this,new ComponentName(this,this.getClass()))) {
    Log.e(TAG,"String_Node_Str");
    stopSelf();
    return;
  }
 else {
    Log.d(TAG,"String_Node_Str");
  }
synchronized (REGISTERED_APPS_LOCK) {
    registeredApps=new HashMap<Long,RegisteredApp>();
  }
  closing=false;
  currentContext=getBaseContext();
  startVersionCheck();
  Log.i(TAG,"String_Node_Str");
synchronized (SESSION_LOCK) {
    this.sessionMap=new SparseArray<Long>();
    this.sessionHashIdMap=new SparseArray<Integer>();
  }
  packetExecuter=Executors.newSingleThreadExecutor();
}
Program: 32394
Project: 32394
Buggy source:
private boolean bindToService(){
  if (isBound) {
    return true;
  }
  Intent bindingIntent=new Intent();
  bindingIntent.setClassName(this.routerService.getPackageName(),this.routerService.getClassName());
  context.startService(bindingIntent);
  bindingIntent.setAction(TransportConstants.BIND_REQUEST_TYPE_STATUS);
  return context.bindService(bindingIntent,routerConnection,Context.BIND_AUTO_CREATE);
}

Fixed version (ground truth):
private boolean bindToService(){
  if (isBound) {
    return true;
  }
  if (clientMessenger == null) {
    return false;
  }
  Intent bindingIntent=new Intent();
  bindingIntent.setClassName(this.routerService.getPackageName(),this.routerService.getClassName());
  context.startService(bindingIntent);
  bindingIntent.setAction(TransportConstants.BIND_REQUEST_TYPE_STATUS);
  return context.bindService(bindingIntent,routerConnection,Context.BIND_AUTO_CREATE);
}
Program: 32395
Project: 32395
Buggy source:
public void checkIsConnected(){
  if (!bindToService()) {
    cb.onConnectionStatusUpdate(false,routerService,context);
    unBindFromService();
  }
}

Fixed version (ground truth):
public void checkIsConnected(){
  if (!AndroidTools.isServiceExported(context,routerService) || !bindToService()) {
    cb.onConnectionStatusUpdate(false,routerService,context);
    unBindFromService();
  }
}
Program: 32397
Project: 32397
Buggy source:
/** 
 * Continuously reads data from the transport's input stream, blocking when no data is available.
 */
private void readFromTransport(){
  final int READ_BUFFER_SIZE=4096;
  byte[] buffer=new byte[READ_BUFFER_SIZE];
  int bytesRead;
  boolean stateProgress=false;
  while (!isInterrupted()) {
    try {
      bytesRead=mInputStream.read(buffer);
      if (bytesRead == -1) {
        if (isInterrupted()) {
          logI("String_Node_Str");
        }
 else {
          logI("String_Node_Str");
          disconnect("String_Node_Str",null);
        }
        return;
      }
    }
 catch (    IOException e) {
      if (isInterrupted()) {
        logW("String_Node_Str",e);
      }
 else {
        logW("String_Node_Str",e);
        disconnect("String_Node_Str",e);
      }
      return;
    }
    logD("String_Node_Str" + bytesRead + "String_Node_Str");
    if (isInterrupted()) {
      logI("String_Node_Str");
      return;
    }
    byte input;
    for (int i=0; i < bytesRead; i++) {
      input=buffer[i];
      stateProgress=psm.handleByte(input);
      if (!stateProgress) {
        psm.reset();
        buffer=new byte[READ_BUFFER_SIZE];
      }
      if (psm.getState() == SdlPsm.FINISHED_STATE) {
synchronized (USBTransport.this) {
          handleReceivedPacket((SdlPacket)psm.getFormedPacket());
        }
        psm.reset();
        buffer=new byte[READ_BUFFER_SIZE];
      }
    }
  }
}

Fixed version (ground truth):
/** 
 * Continuously reads data from the transport's input stream, blocking when no data is available.
 */
private void readFromTransport(){
  final int READ_BUFFER_SIZE=4096;
  byte[] buffer=new byte[READ_BUFFER_SIZE];
  int bytesRead;
  boolean stateProgress=false;
  while (!isInterrupted()) {
    try {
      if (mInputStream == null)       continue;
      bytesRead=mInputStream.read(buffer);
      if (bytesRead == -1) {
        if (isInterrupted()) {
          logI("String_Node_Str");
        }
 else {
          logI("String_Node_Str");
          disconnect("String_Node_Str",null);
        }
        return;
      }
    }
 catch (    IOException e) {
      if (isInterrupted()) {
        logW("String_Node_Str",e);
      }
 else {
        logW("String_Node_Str",e);
        disconnect("String_Node_Str",e);
      }
      return;
    }
    logD("String_Node_Str" + bytesRead + "String_Node_Str");
    if (isInterrupted()) {
      logI("String_Node_Str");
      return;
    }
    byte input;
    for (int i=0; i < bytesRead; i++) {
      input=buffer[i];
      stateProgress=psm.handleByte(input);
      if (!stateProgress) {
        psm.reset();
        buffer=new byte[READ_BUFFER_SIZE];
      }
      if (psm.getState() == SdlPsm.FINISHED_STATE) {
synchronized (USBTransport.this) {
          handleReceivedPacket((SdlPacket)psm.getFormedPacket());
        }
        psm.reset();
        buffer=new byte[READ_BUFFER_SIZE];
      }
    }
  }
}
Program: 32398
Project: 32398
Buggy source:
/** 
 * Looks for an already connected compatible accessory and connect to it.
 */
private void initializeAccessory(){
  logI("String_Node_Str");
  UsbAccessory acc=mConfig.getUsbAccessory();
  if (acc == null || !isAccessorySupported(acc)) {
    UsbManager usbManager=getUsbManager();
    UsbAccessory[] accessories=usbManager.getAccessoryList();
    if (accessories != null) {
      logD("String_Node_Str" + accessories.length + "String_Node_Str");
      for (      UsbAccessory accessory : accessories) {
        if (isAccessorySupported(accessory)) {
          acc=accessory;
          break;
        }
      }
    }
 else {
      logI("String_Node_Str");
      return;
    }
  }
  connectToAccessory(acc);
}

Fixed version (ground truth):
/** 
 * Looks for an already connected compatible accessory and connect to it.
 */
private void initializeAccessory(){
  if (!mConfig.getQueryUsbAcc()) {
    logI("String_Node_Str");
    return;
  }
  logI("String_Node_Str");
  UsbAccessory acc=mConfig.getUsbAccessory();
  if (acc == null || !isAccessorySupported(acc)) {
    UsbManager usbManager=getUsbManager();
    UsbAccessory[] accessories=usbManager.getAccessoryList();
    if (accessories != null) {
      logD("String_Node_Str" + accessories.length + "String_Node_Str");
      for (      UsbAccessory accessory : accessories) {
        if (isAccessorySupported(accessory)) {
          acc=accessory;
          break;
        }
      }
    }
 else {
      logI("String_Node_Str");
      return;
    }
  }
  connectToAccessory(acc);
}
Program: 32399
Project: 32399
Buggy source:
public USBTransportConfig(Context mainActivity,UsbAccessory usbAccessory){
  this.mainActivity=mainActivity;
  this.usbAccessory=usbAccessory;
}

Fixed version (ground truth):
public USBTransportConfig(Context mainActivity,UsbAccessory usbAccessory,boolean shareConnection,boolean queryUsbAcc){
  this.mainActivity=mainActivity;
  this.queryUsbAcc=queryUsbAcc;
  this.usbAccessory=usbAccessory;
  super.shareConnection=shareConnection;
}
Program: 32401
Project: 32401
Buggy source:
/** 
 * Using the knowledge that all SDL enabled apps have an SDL Broadcast Receiver that has an intent filter that includes a specific  intent. 
 * @return 
 */
private static List<SdlApp> findAllSdlApps(Context context){
  List<SdlApp> apps=new ArrayList<SdlApp>();
  PackageManager packageManager=context.getPackageManager();
  Intent intent=new Intent();
  intent.setAction("String_Node_Str");
  List<ResolveInfo> infoList=packageManager.queryBroadcastReceivers(intent,0);
  if (infoList != null) {
    String packageName;
    for (    ResolveInfo info : infoList) {
      packageName=info.activityInfo.packageName;
      try {
        apps.add(new SdlApp(packageName,packageManager.getPackageInfo(packageName,0).versionCode));
      }
 catch (      NameNotFoundException e) {
        e.printStackTrace();
      }
    }
    return apps;
  }
 else {
    Log.i(TAG,"String_Node_Str");
    return null;
  }
}

Fixed version (ground truth):
/** 
 * Using the knowledge that all SDL enabled apps have an SDL Broadcast Receiver that has an intent filter that includes a specific  intent. 
 * @return 
 */
private static List<SdlApp> findAllSdlApps(Context context){
  List<SdlApp> apps=new ArrayList<SdlApp>();
  PackageManager packageManager=context.getPackageManager();
  Intent intent=new Intent();
  intent.setAction("String_Node_Str");
  List<ResolveInfo> infoList=packageManager.queryBroadcastReceivers(intent,0);
  Collections.sort(infoList,new Comparator<ResolveInfo>(){
    @Override public int compare(    ResolveInfo lhs,    ResolveInfo rhs){
      return lhs.activityInfo.packageName.compareTo(rhs.activityInfo.packageName);
    }
  }
);
  if (infoList != null) {
    String packageName;
    for (    ResolveInfo info : infoList) {
      packageName=info.activityInfo.packageName;
      try {
        apps.add(new SdlApp(packageName,packageManager.getPackageInfo(packageName,0).versionCode));
      }
 catch (      NameNotFoundException e) {
        e.printStackTrace();
      }
    }
    return apps;
  }
 else {
    Log.i(TAG,"String_Node_Str");
    return null;
  }
}
Program: 32403
Project: 32403
Buggy source:
@Override public void httpCallComplete(String response){
  setTrustedList(context,response);
  pendingListRefresh=false;
  if (listCallback != null) {
    listCallback.onListObtained(true);
  }
}

Fixed version (ground truth):
@Override public void httpCallComplete(String response){
  setTrustedList(context,response);
  setLastRequest(context,object.toString());
  pendingListRefresh=false;
  if (listCallback != null) {
    listCallback.onListObtained(true);
  }
}
Program: 32405
Project: 32405
Buggy source:
@Override public void httpFailure(int statusCode){
  Log.e(TAG,"String_Node_Str" + statusCode);
  pendingListRefresh=false;
}

Fixed version (ground truth):
@Override public void httpFailure(int statusCode){
  Log.e(TAG,"String_Node_Str" + statusCode);
  pendingListRefresh=false;
  if (listCallback != null) {
    listCallback.onListObtained(false);
  }
}
Program: 32406
Project: 32406
Buggy source:
/** 
 * Main function to call to ensure we are connecting to a validated router service
 * @return whether or not the currently running router service can be trusted.
 */
public boolean validate(){
  PackageManager pm=context.getPackageManager();
  String packageName=null;
  if (this.service != null) {
    Log.d(TAG,"String_Node_Str" + this.service.getClassName());
    if (!isServiceRunning(context,this.service)) {
      service=null;
      Log.w(TAG,"String_Node_Str");
    }
  }
  if (this.service == null) {
    this.service=componentNameForServiceRunning(pm);
    if (this.service == null) {
      wakeUpRouterServices();
      return false;
    }
  }
  packageName=this.appPackageForComponentName(service,pm);
  if (packageName != null) {
    if (wasInstalledByAppStore(packageName)) {
      if (isTrustedPackage(packageName,pm)) {
        return true;
      }
    }
  }
  if (context.getPackageName().equalsIgnoreCase(packageName)) {
    Log.d(TAG,"String_Node_Str");
    Intent intent=new Intent();
    intent.setComponent(service);
    try {
      context.stopService(intent);
    }
 catch (    Exception e) {
    }
  }
  wakeUpRouterServices();
  return false;
}

Fixed version (ground truth):
/** 
 * Main function to call to ensure we are connecting to a validated router service
 * @return whether or not the currently running router service can be trusted.
 */
public boolean validate(){
  PackageManager pm=context.getPackageManager();
  String packageName=null;
  if (this.service != null) {
    Log.d(TAG,"String_Node_Str" + this.service.getClassName());
    if (!isServiceRunning(context,this.service)) {
      service=null;
      Log.w(TAG,"String_Node_Str");
    }
  }
  if (this.service == null) {
    this.service=componentNameForServiceRunning(pm);
    if (this.service == null) {
      wakeUpRouterServices();
      return false;
    }
  }
  packageName=this.appPackageForComponentName(service,pm);
  if (packageName != null) {
    if (wasInstalledByAppStore(packageName)) {
      if (isTrustedPackage(packageName,pm)) {
        return true;
      }
    }
  }
  wakeUpRouterServices();
  return false;
}
Program: 32408
Project: 32408
Buggy source:
@Override public void httpCallComplete(String response){
  setTrustedList(context,response);
  pendingListRefresh=false;
}

Fixed version (ground truth):
@Override public void httpCallComplete(String response){
  setTrustedList(context,response);
  pendingListRefresh=false;
  if (listCallback != null) {
    listCallback.onListObtained(true);
  }
}
Program: 32412
Project: 32412
Buggy source:
@Override public void onConnectionStatusUpdate(boolean connected,ComponentName service,Context context){
  if (!connected && !list.isEmpty()) {
    SdlRouterStatusProvider provider=new SdlRouterStatusProvider(context,list.poll(),this);
    if (triggerRouterServicePing) {
      provider.setFlags(TransportConstants.ROUTER_STATUS_FLAG_TRIGGER_PING);
    }
    provider.checkIsConnected();
  }
 else {
    Log.d(TAG,service.getPackageName() + "String_Node_Str" + connected);
    if (callback != null) {
      callback.onConnectionStatusUpdate(connected,service,context);
    }
    list.clear();
  }
}

Fixed version (ground truth):
@Override public void onConnectionStatusUpdate(boolean connected,ComponentName service,Context context){
  if (!connected && !list.isEmpty()) {
    SdlRouterStatusProvider provider=new SdlRouterStatusProvider(context,list.poll(),this);
    if (triggerRouterServicePing) {
      provider.setFlags(TransportConstants.ROUTER_STATUS_FLAG_TRIGGER_PING);
    }
    provider.checkIsConnected();
  }
 else {
    if (service != null) {
      Log.d(TAG,service.getPackageName() + "String_Node_Str" + connected);
    }
 else {
      Log.d(TAG,"String_Node_Str");
    }
    if (callback != null) {
      callback.onConnectionStatusUpdate(connected,service,context);
    }
    list.clear();
  }
}
Program: 32413
Project: 32413
Buggy source:
@Override public void handleMessage(Message msg){
switch (msg.what) {
case TransportConstants.ROUTER_STATUS_CONNECTED_STATE_RESPONSE:
    provider.get().handleRouterStatusConnectedResponse(msg.arg1);
  break;
default :
break;
}
}

Fixed version (ground truth):
@Override public void handleMessage(Message msg){
  if (provider.get() == null) {
    return;
  }
switch (msg.what) {
case TransportConstants.ROUTER_STATUS_CONNECTED_STATE_RESPONSE:
    provider.get().handleRouterStatusConnectedResponse(msg.arg1);
  break;
default :
break;
}
}
Program: 32415
Project: 32415
Buggy source:
/** 
 * Determines if an instance of the Router Service is currently running on the device. 
 * @param context A context to access Android system services through.
 * @param pingService Set this to true if you want to make sure the service is up and listening to bluetooth
 * @return True if a SDL Router Service is currently running, false otherwise.
 */
private static boolean isRouterServiceRunning(Context context,boolean pingService){
  if (context == null) {
    Log.e(TAG,"String_Node_Str");
    return false;
  }
  ActivityManager manager=(ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE);
  if (runningBluetoothServicePackage == null) {
    runningBluetoothServicePackage=new Vector<ComponentName>();
  }
 else {
    runningBluetoothServicePackage.clear();
  }
  for (  RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
    if ((service.service.getClassName()).toLowerCase(Locale.US).contains(SDL_ROUTER_SERVICE_CLASS_NAME)) {
      runningBluetoothServicePackage.add(service.service);
      if (pingService) {
        Intent intent=new Intent();
        intent.setClassName(service.service.getPackageName(),service.service.getClassName());
        intent.putExtra(TransportConstants.PING_ROUTER_SERVICE_EXTRA,pingService);
        context.startService(intent);
      }
      return true;
    }
  }
  return false;
}

Fixed version (ground truth):
/** 
 * Determines if an instance of the Router Service is currently running on the device. 
 * @param context A context to access Android system services through.
 * @param pingService Set this to true if you want to make sure the service is up and listening to bluetooth
 * @return True if a SDL Router Service is currently running, false otherwise.
 */
private static boolean isRouterServiceRunning(Context context,boolean pingService){
  if (context == null) {
    Log.e(TAG,"String_Node_Str");
    return false;
  }
  ActivityManager manager=(ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE);
  if (runningBluetoothServicePackage == null) {
    runningBluetoothServicePackage=new Vector<ComponentName>();
  }
 else {
    runningBluetoothServicePackage.clear();
  }
  for (  RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
    if ((service.service.getClassName()).toLowerCase(Locale.US).contains(SDL_ROUTER_SERVICE_CLASS_NAME)) {
      runningBluetoothServicePackage.add(service.service);
      if (pingService) {
        Intent intent=new Intent();
        intent.setClassName(service.service.getPackageName(),service.service.getClassName());
        intent.putExtra(TransportConstants.PING_ROUTER_SERVICE_EXTRA,pingService);
        context.startService(intent);
      }
    }
  }
  return runningBluetoothServicePackage.size() > 0;
}
Program: 32417
Project: 32417
Buggy source:
protected MessageFrameAssembler getFrameAssemblerForFrame(SdlPacket packet){
  Hashtable<Integer,MessageFrameAssembler> hashSessionID=_assemblerForSessionID.get(packet.getSessionId());
  if (hashSessionID == null) {
    hashSessionID=new Hashtable<Integer,MessageFrameAssembler>();
    _assemblerForSessionID.put((byte)packet.getSessionId(),hashSessionID);
  }
  MessageFrameAssembler ret=(MessageFrameAssembler)_assemblerForMessageID.get(Integer.valueOf(packet.getMessageId()));
  if (ret == null) {
    ret=new MessageFrameAssembler();
    _assemblerForMessageID.put(Integer.valueOf(packet.getMessageId()),ret);
  }
  return ret;
}

Fixed version (ground truth):
protected MessageFrameAssembler getFrameAssemblerForFrame(SdlPacket packet){
  Integer iSessionId=Integer.valueOf(packet.getSessionId());
  Byte bySessionId=iSessionId.byteValue();
  Hashtable<Integer,MessageFrameAssembler> hashSessionID=_assemblerForSessionID.get(bySessionId);
  if (hashSessionID == null) {
    hashSessionID=new Hashtable<Integer,MessageFrameAssembler>();
    _assemblerForSessionID.put(bySessionId,hashSessionID);
  }
  MessageFrameAssembler ret=(MessageFrameAssembler)_assemblerForMessageID.get(Integer.valueOf(packet.getMessageId()));
  if (ret == null) {
    ret=new MessageFrameAssembler();
    _assemblerForMessageID.put(Integer.valueOf(packet.getMessageId()),ret);
  }
  return ret;
}
Program: 32419
Project: 32419
Buggy source:
/** 
 * If an app crashes the only way we can handle it being on the head unit is to send an unregister app interface rpc. This method should only be called when the router service recognizes the client is no longer valid
 * @param sessionId
 * @param version
 * @return
 */
private byte[] createForceUnregisterApp(byte sessionId,byte version){
  UnregisterAppInterface request=new UnregisterAppInterface();
  request.setCorrelationID(UNREGISTER_APP_INTERFACE_CORRELATION_ID);
  byte[] msgBytes=JsonRPCMarshaller.marshall(request,version);
  ProtocolMessage pm=new ProtocolMessage();
  pm.setData(msgBytes);
  pm.setSessionID(sessionId);
  pm.setMessageType(MessageType.RPC);
  pm.setSessionType(SessionType.RPC);
  pm.setFunctionID(FunctionID.getFunctionId(request.getFunctionName()));
  pm.setCorrID(request.getCorrelationID());
  if (request.getBulkData() != null)   pm.setBulkData(request.getBulkData());
  byte[] data=null;
  if (version > 1) {
    data=new byte[12 + pm.getJsonSize()];
  }
 else {
    data=pm.getData();
  }
  BinaryFrameHeader binFrameHeader=new BinaryFrameHeader();
  binFrameHeader=SdlPacketFactory.createBinaryFrameHeader(pm.getRPCType(),pm.getFunctionID(),pm.getCorrID(),pm.getJsonSize());
  System.arraycopy(binFrameHeader.assembleHeaderBytes(),0,data,0,12);
  System.arraycopy(pm.getData(),0,data,12,pm.getJsonSize());
  SdlPacket packet=new SdlPacket(version,false,SdlPacket.FRAME_TYPE_SINGLE,SdlPacket.SERVICE_TYPE_RPC,0,sessionId,data.length,data.length + 100,data);
  return packet.constructPacket();
}

Fixed version (ground truth):
/** 
 * If an app crashes the only way we can handle it being on the head unit is to send an unregister app interface rpc. This method should only be called when the router service recognizes the client is no longer valid
 * @param sessionId
 * @param version
 * @return
 */
private byte[] createForceUnregisterApp(byte sessionId,byte version){
  UnregisterAppInterface request=new UnregisterAppInterface();
  request.setCorrelationID(UNREGISTER_APP_INTERFACE_CORRELATION_ID);
  byte[] msgBytes=JsonRPCMarshaller.marshall(request,version);
  ProtocolMessage pm=new ProtocolMessage();
  pm.setData(msgBytes);
  pm.setSessionID(sessionId);
  pm.setMessageType(MessageType.RPC);
  pm.setSessionType(SessionType.RPC);
  pm.setFunctionID(FunctionID.getFunctionId(request.getFunctionName()));
  pm.setCorrID(request.getCorrelationID());
  if (request.getBulkData() != null)   pm.setBulkData(request.getBulkData());
  byte[] data=null;
  if (version > 1) {
    data=new byte[12 + pm.getJsonSize()];
    BinaryFrameHeader binFrameHeader=new BinaryFrameHeader();
    binFrameHeader=SdlPacketFactory.createBinaryFrameHeader(pm.getRPCType(),pm.getFunctionID(),pm.getCorrID(),pm.getJsonSize());
    System.arraycopy(binFrameHeader.assembleHeaderBytes(),0,data,0,12);
    System.arraycopy(pm.getData(),0,data,12,pm.getJsonSize());
  }
 else {
    data=pm.getData();
  }
  SdlPacket packet=new SdlPacket(version,false,SdlPacket.FRAME_TYPE_SINGLE,SdlPacket.SERVICE_TYPE_RPC,0,sessionId,data.length,data.length + 100,data);
  return packet.constructPacket();
}