nus-yam/ex-repair huggingface dataset:
Program: 99415
Project: 99415
Buggy source:
/** 
 * The   {@link TokenResponse} obtained as a result of a successful authentication request execution.
 * @return the {@link TokenResponse} obtained as a result of a successful authentication request execution.
 */
TokenResponse getTokenResponse();

Fixed version (ground truth):
/** 
 * The   {@link com.stormpath.sdk.oauth.authz.TokenResponse} obtained as a result of a successful authentication request execution.
 * @return the {@link com.stormpath.sdk.oauth.authz.TokenResponse} obtained as a result of a successful authentication request execution.
 */
TokenResponse getTokenResponse();
Program: 99416
Project: 99416
Buggy source:
/** 
 * Specifies the   {@link ScopeFactory} to be used for this authentication request.
 * @param scopeFactory the {@link ScopeFactory} to be used for this authentication request.
 * @return this instance for method chaining.
 */
public BasicOauthAuthenticationRequestBuilder using(ScopeFactory scopeFactory);

Fixed version (ground truth):
/** 
 * Specifies the   {@link ScopeFactory} to be used for this authentication request.If not provided an empty scope will be returned.
 * @param scopeFactory the {@link ScopeFactory} to be used for this authentication request.
 * @return this instance for method chaining.
 */
public BasicOauthAuthenticationRequestBuilder using(ScopeFactory scopeFactory);
Program: 99417
Project: 99417
Buggy source:
/** 
 * Specifies the <a href="http://en.wikipedia.org/wiki/Time_to_live">time to live</a> of this authentication request in seconds.
 * @param ttl the time to live (in seconds) of this authentication request.
 * @return this instance for method chaining.
 */
public BasicOauthAuthenticationRequestBuilder withTtl(long ttl);

Fixed version (ground truth):
/** 
 * Specifies the <a href="http://en.wikipedia.org/wiki/Time_to_live">time to live</a> of this authentication request in seconds. If not provided the default ttl (3600 seconds) will be used.
 * @param ttl the time to live (in seconds) of this authentication request.
 * @return this instance for method chaining.
 */
public BasicOauthAuthenticationRequestBuilder withTtl(long ttl);
Program: 99418
Project: 99418
Buggy source:
/** 
 * Utility function for creating a new BufferedEntity and wrapping any errors as an AmazonClientException.
 * @param entity The HTTP entity to wrap with a buffered HTTP entity.
 * @return A new BufferedHttpEntity wrapping the specified entity.
 */
private HttpEntity newBufferedHttpEntity(HttpEntity entity){
  try {
    return new BufferedHttpEntity(entity);
  }
 catch (  IOException e) {
    throw new RestException("String_Node_Str" + e.getMessage(),e);
  }
}

Fixed version (ground truth):
/** 
 * Utility function for creating a new BufferedEntity and wrapping any errors as a RestException.
 * @param entity The HTTP entity to wrap with a buffered HTTP entity.
 * @return A new BufferedHttpEntity wrapping the specified entity.
 */
private HttpEntity newBufferedHttpEntity(HttpEntity entity){
  try {
    return new BufferedHttpEntity(entity);
  }
 catch (  IOException e) {
    throw new RestException("String_Node_Str" + e.getMessage(),e);
  }
}
Program: 99419
Project: 99419
Buggy source:
@SuppressWarnings("String_Node_Str") private DataStore createDataStore(Object requestExecutor,Object secondCtorArg){
  String requestExecutorInterfaceClassName="String_Node_Str";
  Class requestExecutorInterfaceClass;
  try {
    requestExecutorInterfaceClass=ClassUtils.forName(requestExecutorInterfaceClassName);
  }
 catch (  Throwable t) {
    throw new RuntimeException("String_Node_Str" + requestExecutorInterfaceClassName + "String_Node_Str",t);
  }
  String className="String_Node_Str";
  Class dataStoreClass;
  try {
    dataStoreClass=ClassUtils.forName(className);
  }
 catch (  Throwable t) {
    throw new RuntimeException("String_Node_Str" + className + "String_Node_Str"+ "String_Node_Str",t);
  }
  Constructor ctor=ClassUtils.getConstructor(dataStoreClass,requestExecutorInterfaceClass,secondCtorArg.getClass());
  try {
    return (DataStore)ctor.newInstance(requestExecutor,secondCtorArg);
  }
 catch (  Throwable t) {
    throw new RuntimeException("String_Node_Str" + className,t);
  }
}

Fixed version (ground truth):
@SuppressWarnings("String_Node_Str") private DataStore createDataStore(Object requestExecutor,Object secondCtorArg){
  String requestExecutorInterfaceClassName="String_Node_Str";
  Class requestExecutorInterfaceClass;
  try {
    requestExecutorInterfaceClass=ClassUtils.forName(requestExecutorInterfaceClassName);
  }
 catch (  Throwable t) {
    throw new RuntimeException("String_Node_Str" + requestExecutorInterfaceClassName + "String_Node_Str",t);
  }
  String className="String_Node_Str";
  Class dataStoreClass;
  try {
    dataStoreClass=ClassUtils.forName(className);
  }
 catch (  Throwable t) {
    throw new RuntimeException("String_Node_Str" + className + "String_Node_Str"+ "String_Node_Str",t);
  }
  Class secondCtorArgClass=secondCtorArg.getClass();
  if (Integer.class.equals(secondCtorArgClass)) {
    secondCtorArgClass=int.class;
  }
  Constructor ctor=ClassUtils.getConstructor(dataStoreClass,requestExecutorInterfaceClass,secondCtorArgClass);
  try {
    return (DataStore)ctor.newInstance(requestExecutor,secondCtorArg);
  }
 catch (  Throwable t) {
    throw new RuntimeException("String_Node_Str" + className,t);
  }
}
Program: 99420
Project: 99420
Buggy source:
public Object getProperty(String name){
  readLock.lock();
  try {
    if (!HREF_PROP_NAME.equals(name)) {
      if (!isMaterialized()) {
        materialize();
      }
    }
    return this.properties.get(name);
  }
  finally {
    readLock.unlock();
  }
}

Fixed version (ground truth):
public Object getProperty(String name){
  if (!HREF_PROP_NAME.equals(name)) {
    if (!isMaterialized()) {
      materialize();
    }
  }
  readLock.lock();
  try {
    return this.properties.get(name);
  }
  finally {
    readLock.unlock();
  }
}
Program: 99421
Project: 99421
Buggy source:
/** 
 * Constructor
 * @param usbDevice           the UsbDevice
 * @param usbDeviceConnection the UsbDeviceConnection
 * @param usbInterface        the UsbInterface
 * @param usbEndpoint         the UsbEndpoint
 */
public MidiOutputDevice(@NonNull UsbDevice usbDevice,@NonNull UsbDeviceConnection usbDeviceConnection,@NonNull UsbInterface usbInterface,@NonNull UsbEndpoint usbEndpoint){
  this.usbDevice=usbDevice;
  this.usbDeviceConnection=usbDeviceConnection;
  this.usbInterface=usbInterface;
  waiterThread=new WaiterThread();
  outputEndpoint=usbEndpoint;
  this.usbDeviceConnection.claimInterface(this.usbInterface,true);
  waiterThread.setName("String_Node_Str" + usbDevice.getDeviceName() + "String_Node_Str");
  waiterThread.start();
}

Fixed version (ground truth):
/** 
 * Constructor
 * @param usbDevice the UsbDevice
 * @param usbDeviceConnection the UsbDeviceConnection
 * @param usbInterface the UsbInterface
 * @param usbEndpoint the UsbEndpoint
 */
public MidiOutputDevice(@NonNull UsbDevice usbDevice,@NonNull UsbDeviceConnection usbDeviceConnection,@NonNull UsbInterface usbInterface,@NonNull UsbEndpoint usbEndpoint){
  this.usbDevice=usbDevice;
  this.usbDeviceConnection=usbDeviceConnection;
  this.usbInterface=usbInterface;
  waiterThread=new WaiterThread();
  outputEndpoint=usbEndpoint;
  this.usbDeviceConnection.claimInterface(this.usbInterface,true);
  waiterThread.setName("String_Node_Str" + usbDevice.getDeviceName() + "String_Node_Str");
  waiterThread.start();
  for (int i=0; i < BUFFER_POOL_SIZE; i++) {
    bufferPool.addLast(new byte[4]);
  }
}
Program: 99425
Project: 99425
Buggy source:
/** 
 * Constructor
 * @param usbManager the UsbManager
 * @param deviceAttachedListener the OnMidiDeviceAttachedListener
 * @param deviceDetachedHandler the OnMidiDeviceDetachedListener
 */
MidiDeviceConnectionWatchThread(@NonNull UsbManager usbManager,@NonNull OnMidiDeviceAttachedListener deviceAttachedListener,@NonNull Handler deviceDetachedHandler){
  this.usbManager=usbManager;
  this.deviceAttachedListener=deviceAttachedListener;
  this.deviceDetachedHandler=deviceDetachedHandler;
  connectedDevices=new HashSet<UsbDevice>();
  stopFlag=false;
  deviceFilters=DeviceFilter.getDeviceFilters(context);
}

Fixed version (ground truth):
/** 
 * Constructor
 * @param usbManager the UsbManager
 * @param deviceAttachedListener the OnMidiDeviceAttachedListener
 * @param deviceDetachedHandler the OnMidiDeviceDetachedListener
 */
MidiDeviceConnectionWatchThread(@NonNull UsbManager usbManager,@NonNull OnMidiDeviceAttachedListener deviceAttachedListener,@NonNull Handler deviceDetachedHandler){
  this.usbManager=usbManager;
  this.deviceAttachedListener=deviceAttachedListener;
  this.deviceDetachedHandler=deviceDetachedHandler;
  connectedDevices=new HashSet<>();
  stopFlag=false;
  deviceFilters=DeviceFilter.getDeviceFilters(context);
}
Program: 99426
Project: 99426
Buggy source:
/** 
 * stops the watching thread <br /> <br /> Note: Takes one second until the thread stops. The device attached / detached events will be noticed until the thread will completely stops.
 */
public void stop(){
  thread.stopFlag=true;
  thread.interrupt();
  while (thread.isAlive()) {
    try {
      Thread.sleep(100);
    }
 catch (    InterruptedException e) {
    }
  }
}

Fixed version (ground truth):
/** 
 * Stops the watching thread <br /> <br /> Note: Takes one second until the thread stops. The device attached / detached events will be noticed until the thread will completely stops.
 */
public void stop(){
  thread.stopFlag=true;
  thread.interrupt();
  while (thread.isAlive()) {
    try {
      Thread.sleep(100);
    }
 catch (    InterruptedException e) {
    }
  }
}
Program: 99427
Project: 99427
Buggy source:
@Override public boolean handleMessage(Message message){
  UsbDevice detachedDevice=(UsbDevice)message.obj;
  deviceDetachedListener.onDeviceDetached(detachedDevice);
  AsyncTask<UsbDevice,Void,Void> task=new AsyncTask<UsbDevice,Void,Void>(){
    @Override protected Void doInBackground(    UsbDevice... params){
      if (params == null || params.length < 1) {
        return null;
      }
      UsbDevice usbDevice=params[0];
      Set<MidiInputDevice> inputDevices=midiInputDevices.get(usbDevice);
      if (inputDevices != null && inputDevices.size() > 0) {
        for (        MidiInputDevice inputDevice : inputDevices) {
          if (inputDevice != null) {
            inputDevice.stop();
            deviceDetachedListener.onMidiInputDeviceDetached(inputDevice);
          }
        }
        midiInputDevices.remove(usbDevice);
      }
      Set<MidiOutputDevice> outputDevices=midiOutputDevices.get(usbDevice);
      if (outputDevices != null) {
        for (        MidiOutputDevice outputDevice : outputDevices) {
          if (outputDevice != null) {
            outputDevice.stop();
            deviceDetachedListener.onMidiOutputDeviceDetached(outputDevice);
          }
        }
        midiOutputDevices.remove(usbDevice);
      }
      UsbDeviceConnection deviceConnection=deviceConnections.get(usbDevice);
      if (deviceConnection != null) {
        deviceConnection.close();
        deviceConnections.remove(usbDevice);
      }
      Log.d(Constants.TAG,"String_Node_Str" + usbDevice.getDeviceName() + "String_Node_Str");
      return null;
    }
  }
;
  task.execute(detachedDevice);
  return true;
}

Fixed version (ground truth):
@Override public boolean handleMessage(Message message){
  AsyncTask<UsbDevice,Void,Void> task=new AsyncTask<UsbDevice,Void,Void>(){
    @Override protected Void doInBackground(    UsbDevice... params){
      if (params == null || params.length < 1) {
        return null;
      }
      UsbDevice usbDevice=params[0];
      onDeviceDetached(usbDevice);
      return null;
    }
  }
;
  UsbDevice detachedDevice=(UsbDevice)message.obj;
  task.execute(detachedDevice);
  return true;
}
Program: 99428
Project: 99428
Buggy source:
@Override protected Void doInBackground(UsbDevice... params){
  if (params == null || params.length < 1) {
    return null;
  }
  UsbDevice usbDevice=params[0];
  Set<MidiInputDevice> inputDevices=midiInputDevices.get(usbDevice);
  if (inputDevices != null && inputDevices.size() > 0) {
    for (    MidiInputDevice inputDevice : inputDevices) {
      if (inputDevice != null) {
        inputDevice.stop();
        deviceDetachedListener.onMidiInputDeviceDetached(inputDevice);
      }
    }
    midiInputDevices.remove(usbDevice);
  }
  Set<MidiOutputDevice> outputDevices=midiOutputDevices.get(usbDevice);
  if (outputDevices != null) {
    for (    MidiOutputDevice outputDevice : outputDevices) {
      if (outputDevice != null) {
        outputDevice.stop();
        deviceDetachedListener.onMidiOutputDeviceDetached(outputDevice);
      }
    }
    midiOutputDevices.remove(usbDevice);
  }
  UsbDeviceConnection deviceConnection=deviceConnections.get(usbDevice);
  if (deviceConnection != null) {
    deviceConnection.close();
    deviceConnections.remove(usbDevice);
  }
  Log.d(Constants.TAG,"String_Node_Str" + usbDevice.getDeviceName() + "String_Node_Str");
  return null;
}

Fixed version (ground truth):
@Override protected Void doInBackground(UsbDevice... params){
  if (params == null || params.length < 1) {
    return null;
  }
  UsbDevice usbDevice=params[0];
  onDeviceDetached(usbDevice);
  return null;
}
Program: 99429
Project: 99429
Buggy source:
@Override public void run(){
  super.run();
  while (stopFlag == false) {
    checkConnectedDevices();
synchronized (deviceGrantQueue) {
      if (!deviceGrantQueue.isEmpty() && !isGranting) {
        isGranting=true;
        grantingDevice=deviceGrantQueue.remove();
        PendingIntent permissionIntent=PendingIntent.getBroadcast(context,0,new Intent(UsbMidiGrantedReceiver.USB_PERMISSION_GRANTED_ACTION),0);
        context.registerReceiver(new UsbMidiGrantedReceiver(grantingDevice,deviceAttachedListener),new IntentFilter(UsbMidiGrantedReceiver.USB_PERMISSION_GRANTED_ACTION));
        usbManager.requestPermission(grantingDevice,permissionIntent);
      }
    }
    try {
      sleep(1000);
    }
 catch (    InterruptedException e) {
    }
  }
  for (  UsbDevice device : grantedDevices) {
    Message message=deviceDetachedHandler.obtainMessage();
    message.obj=device;
    deviceDetachedHandler.sendMessage(message);
  }
  grantedDevices.clear();
}

Fixed version (ground truth):
@Override public void run(){
  super.run();
  while (stopFlag == false) {
    checkConnectedDevices();
synchronized (deviceGrantQueue) {
      if (!deviceGrantQueue.isEmpty() && !isGranting) {
        isGranting=true;
        grantingDevice=deviceGrantQueue.remove();
        PendingIntent permissionIntent=PendingIntent.getBroadcast(context,0,new Intent(UsbMidiGrantedReceiver.USB_PERMISSION_GRANTED_ACTION),0);
        context.registerReceiver(new UsbMidiGrantedReceiver(grantingDevice,deviceAttachedListener),new IntentFilter(UsbMidiGrantedReceiver.USB_PERMISSION_GRANTED_ACTION));
        usbManager.requestPermission(grantingDevice,permissionIntent);
      }
    }
    try {
      sleep(1000);
    }
 catch (    InterruptedException e) {
    }
  }
  for (  UsbDevice device : grantedDevices) {
    onDeviceDetached(device);
  }
  grantedDevices.clear();
}
Program: 99430
Project: 99430
Buggy source:
public void checkConnectedDevicesImmediately(){
  thread.checkConnectedDevices();
}

Fixed version (ground truth):
/** 
 * Checks the connected USB MIDI devices
 */
public void checkConnectedDevicesImmediately(){
  thread.checkConnectedDevices();
}
Program: 99433
Project: 99433
Buggy source:
@Override public void onMidiSingleByte(@NonNull MidiInputDevice sender,int cable,int byte1){
  if (receiver != null) {
    try {
      final SysexMessage message=new SysexMessage();
      message.setMessage(new byte[]{(byte)(byte1 & 0xff)},1);
      receiver.send(message,-1);
    }
 catch (    final InvalidMidiDataException e) {
      Log.d(Constants.TAG,"String_Node_Str",e);
    }
  }
}

Fixed version (ground truth):
@Override public void onMidiSingleByte(@NonNull MidiInputDevice sender,int cable,int byte1){
  if (receiver != null) {
    try {
      final ShortMessage message=new ShortMessage();
      message.setMessage(new byte[]{(byte)(byte1 & 0xff)},1);
      receiver.send(message,-1);
    }
 catch (    final InvalidMidiDataException e) {
      Log.d(Constants.TAG,"String_Node_Str",e);
    }
  }
}
Program: 99434
Project: 99434
Buggy source:
@Override public void onMidiSingleByte(@NonNull MidiInputDevice sender,int cable,int byte1){
  if (receiver != null) {
    try {
      final SysexMessage message=new SysexMessage();
      message.setMessage(new byte[]{(byte)(byte1 & 0xff)},1);
      receiver.send(message,-1);
    }
 catch (    final InvalidMidiDataException e) {
      Log.d(Constants.TAG,"String_Node_Str",e);
    }
  }
}

Fixed version (ground truth):
@Override public void onMidiSingleByte(@NonNull MidiInputDevice sender,int cable,int byte1){
  if (receiver != null) {
    try {
      final ShortMessage message=new ShortMessage();
      message.setMessage(new byte[]{(byte)(byte1 & 0xff)},1);
      receiver.send(message,-1);
    }
 catch (    final InvalidMidiDataException e) {
      Log.d(Constants.TAG,"String_Node_Str",e);
    }
  }
}
Program: 99435
Project: 99435
Buggy source:
@Override public void onDestroy(){
  super.onDestroy();
  if (deviceConnectionWatcher != null) {
    deviceConnectionWatcher.stop();
  }
  deviceConnectionWatcher=null;
  if (midiInputDevice != null) {
    midiInputDevice.stop();
    midiInputDevice=null;
  }
  midiOutputDevice=null;
  deviceConnection=null;
  Toast.makeText(this,"String_Node_Str",Toast.LENGTH_SHORT).show();
}

Fixed version (ground truth):
@Override public void onDestroy(){
  super.onDestroy();
  if (deviceConnectionWatcher != null) {
    deviceConnectionWatcher.stop();
  }
  deviceConnectionWatcher=null;
  midiInputDevice=null;
  midiOutputDevice=null;
  deviceConnection=null;
  Toast.makeText(this,"String_Node_Str",Toast.LENGTH_SHORT).show();
}
Program: 99436
Project: 99436
Buggy source:
/** 
 * Get connected USB MIDI devices.
 * @return connected UsbDevice set
 */
@NonNull public final Set<UsbDevice> getConnectedUsbDevices(){
  if (deviceConnectionWatcher != null) {
    deviceConnectionWatcher.checkConnectedDevicesImmediately();
  }
  if (deviceConnections != null) {
    return Collections.unmodifiableSet(deviceConnections.keySet());
  }
  return Collections.unmodifiableSet(new HashSet<UsbDevice>());
}

Fixed version (ground truth):
/** 
 * Get connected USB MIDI devices.
 * @return connected UsbDevice set
 */
@NonNull public final Set<UsbDevice> getConnectedUsbDevices(){
  if (deviceConnectionWatcher != null) {
    deviceConnectionWatcher.checkConnectedDevicesImmediately();
  }
  if (connectedUsbDevices != null) {
    return Collections.unmodifiableSet(connectedUsbDevices);
  }
  return Collections.unmodifiableSet(new HashSet<UsbDevice>());
}
Program: 99437
Project: 99437
Buggy source:
@Override public void onDeviceDetached(@NonNull UsbDevice usbDevice){
}

Fixed version (ground truth):
@Override public void onDeviceDetached(@NonNull UsbDevice usbDevice){
  connectedUsbDevices.remove(usbDevice);
  UsbMidiDriver.this.onDeviceDetached(usbDevice);
}
Program: 99438
Project: 99438
Buggy source:
@Override public void onDeviceAttached(@NonNull UsbDevice usbDevice){
}

Fixed version (ground truth):
@Override public void onDeviceAttached(@NonNull UsbDevice usbDevice){
  connectedUsbDevices.add(usbDevice);
  UsbMidiDriver.this.onDeviceAttached(usbDevice);
}
Program: 99439
Project: 99439
Buggy source:
/** 
 * Stops using UsbMidiDriver. Shutdown the USB device communicating thread. The all connected devices will be closed.
 */
public final void close(){
  if (!isOpen) {
    return;
  }
  isOpen=false;
  deviceConnectionWatcher.stop();
  deviceConnectionWatcher=null;
  if (midiInputDevices != null) {
    midiInputDevices.clear();
  }
  midiInputDevices=null;
  if (midiOutputDevices != null) {
    midiOutputDevices.clear();
  }
  midiOutputDevices=null;
  deviceConnections=null;
}

Fixed version (ground truth):
/** 
 * Stops using UsbMidiDriver. Shutdown the USB device communicating thread. The all connected devices will be closed.
 */
public final void close(){
  if (!isOpen) {
    return;
  }
  isOpen=false;
  deviceConnectionWatcher.stop();
  deviceConnectionWatcher=null;
  if (midiInputDevices != null) {
    midiInputDevices.clear();
  }
  midiInputDevices=null;
  if (midiOutputDevices != null) {
    midiOutputDevices.clear();
  }
  midiOutputDevices=null;
  if (connectedUsbDevices != null) {
    connectedUsbDevices.clear();
  }
  connectedUsbDevices=null;
}
Program: 99440
Project: 99440
Buggy source:
/** 
 * Starts using UsbMidiDriver. Starts the USB device watching and communicating thread.
 */
public final void open(){
  if (isOpen) {
    return;
  }
  isOpen=true;
  deviceConnections=new HashMap<UsbDevice,UsbDeviceConnection>();
  midiInputDevices=new HashSet<MidiInputDevice>();
  midiOutputDevices=new HashSet<MidiOutputDevice>();
  UsbManager usbManager=(UsbManager)context.getApplicationContext().getSystemService(Context.USB_SERVICE);
  deviceAttachedListener=new OnMidiDeviceAttachedListenerImpl();
  deviceDetachedListener=new OnMidiDeviceDetachedListenerImpl();
  deviceConnectionWatcher=new MidiDeviceConnectionWatcher(context.getApplicationContext(),usbManager,deviceAttachedListener,deviceDetachedListener);
}

Fixed version (ground truth):
/** 
 * Starts using UsbMidiDriver. Starts the USB device watching and communicating thread.
 */
public final void open(){
  if (isOpen) {
    return;
  }
  isOpen=true;
  connectedUsbDevices=new HashSet<>();
  midiInputDevices=new HashSet<>();
  midiOutputDevices=new HashSet<>();
  UsbManager usbManager=(UsbManager)context.getApplicationContext().getSystemService(Context.USB_SERVICE);
  deviceAttachedListener=new OnMidiDeviceAttachedListenerImpl();
  deviceDetachedListener=new OnMidiDeviceDetachedListenerImpl();
  deviceConnectionWatcher=new MidiDeviceConnectionWatcher(context.getApplicationContext(),usbManager,deviceAttachedListener,deviceDetachedListener);
}
Program: 99441
Project: 99441
Buggy source:
/** 
 * Get connected USB MIDI devices.
 * @return connected UsbDevice set
 */
@NonNull public final Set<UsbDevice> getConnectedUsbDevices(){
  if (deviceConnectionWatcher != null) {
    deviceConnectionWatcher.checkConnectedDevicesImmediately();
  }
  if (deviceConnections != null) {
    return Collections.unmodifiableSet(deviceConnections.keySet());
  }
  return Collections.unmodifiableSet(new HashSet<UsbDevice>());
}

Fixed version (ground truth):
/** 
 * Get connected USB MIDI devices.
 * @return connected UsbDevice set
 */
@NonNull public final Set<UsbDevice> getConnectedUsbDevices(){
  if (deviceConnectionWatcher != null) {
    deviceConnectionWatcher.checkConnectedDevicesImmediately();
  }
  if (connectedUsbDevices != null) {
    return Collections.unmodifiableSet(connectedUsbDevices);
  }
  return Collections.unmodifiableSet(new HashSet<UsbDevice>());
}
Program: 99442
Project: 99442
Buggy source:
/** 
 * Get MIDI output device, if available.
 * @param usbDevice the UsbDevice
 * @return {@link Set<MidiOutputDevice>}
 */
@NonNull public final Set<MidiOutputDevice> getMidiOutputDevices(@NonNull UsbDevice usbDevice){
  if (deviceConnectionWatcher != null) {
    deviceConnectionWatcher.checkConnectedDevicesImmediately();
  }
  return Collections.unmodifiableSet(midiOutputDevices);
}

Fixed version (ground truth):
/** 
 * Get the all MIDI output devices.
 * @return {@link Set<MidiOutputDevice>}
 */
@NonNull public final Set<MidiOutputDevice> getMidiOutputDevices(){
  if (deviceConnectionWatcher != null) {
    deviceConnectionWatcher.checkConnectedDevicesImmediately();
  }
  return Collections.unmodifiableSet(midiOutputDevices);
}
Program: 99443
Project: 99443
Buggy source:
@Override public void onDeviceDetached(@NonNull UsbDevice usbDevice){
}

Fixed version (ground truth):
@Override public void onDeviceDetached(@NonNull UsbDevice usbDevice){
  connectedUsbDevices.remove(usbDevice);
  UsbMidiDriver.this.onDeviceDetached(usbDevice);
}
Program: 99444
Project: 99444
Buggy source:
@Override public void onDeviceAttached(@NonNull UsbDevice usbDevice){
}

Fixed version (ground truth):
@Override public void onDeviceAttached(@NonNull UsbDevice usbDevice){
  connectedUsbDevices.add(usbDevice);
  UsbMidiDriver.this.onDeviceAttached(usbDevice);
}
Program: 99445
Project: 99445
Buggy source:
/** 
 * Stops using UsbMidiDriver. Shutdown the USB device communicating thread. The all connected devices will be closed.
 */
public final void close(){
  if (!isOpen) {
    return;
  }
  isOpen=false;
  deviceConnectionWatcher.stop();
  deviceConnectionWatcher=null;
  if (midiInputDevices != null) {
    midiInputDevices.clear();
  }
  midiInputDevices=null;
  if (midiOutputDevices != null) {
    midiOutputDevices.clear();
  }
  midiOutputDevices=null;
  deviceConnections=null;
}

Fixed version (ground truth):
/** 
 * Stops using UsbMidiDriver. Shutdown the USB device communicating thread. The all connected devices will be closed.
 */
public final void close(){
  if (!isOpen) {
    return;
  }
  isOpen=false;
  deviceConnectionWatcher.stop();
  deviceConnectionWatcher=null;
  if (midiInputDevices != null) {
    midiInputDevices.clear();
  }
  midiInputDevices=null;
  if (midiOutputDevices != null) {
    midiOutputDevices.clear();
  }
  midiOutputDevices=null;
  if (connectedUsbDevices != null) {
    connectedUsbDevices.clear();
  }
  connectedUsbDevices=null;
}
Program: 99446
Project: 99446
Buggy source:
/** 
 * Starts using UsbMidiDriver. Starts the USB device watching and communicating thread.
 */
public final void open(){
  if (isOpen) {
    return;
  }
  isOpen=true;
  deviceConnections=new HashMap<UsbDevice,UsbDeviceConnection>();
  midiInputDevices=new HashSet<MidiInputDevice>();
  midiOutputDevices=new HashSet<MidiOutputDevice>();
  UsbManager usbManager=(UsbManager)context.getApplicationContext().getSystemService(Context.USB_SERVICE);
  deviceAttachedListener=new OnMidiDeviceAttachedListenerImpl();
  deviceDetachedListener=new OnMidiDeviceDetachedListenerImpl();
  deviceConnectionWatcher=new MidiDeviceConnectionWatcher(context.getApplicationContext(),usbManager,deviceAttachedListener,deviceDetachedListener);
}

Fixed version (ground truth):
/** 
 * Starts using UsbMidiDriver. Starts the USB device watching and communicating thread.
 */
public final void open(){
  if (isOpen) {
    return;
  }
  isOpen=true;
  connectedUsbDevices=new HashSet<>();
  midiInputDevices=new HashSet<>();
  midiOutputDevices=new HashSet<>();
  UsbManager usbManager=(UsbManager)context.getApplicationContext().getSystemService(Context.USB_SERVICE);
  deviceAttachedListener=new OnMidiDeviceAttachedListenerImpl();
  deviceDetachedListener=new OnMidiDeviceDetachedListenerImpl();
  deviceConnectionWatcher=new MidiDeviceConnectionWatcher(context.getApplicationContext(),usbManager,deviceAttachedListener,deviceDetachedListener);
}
Program: 99447
Project: 99447
Buggy source:
/** 
 * NRPN message This method is just the utility method, do not need to be implemented necessarily by subclass.
 * @param sender the Object which the event sent
 * @param cable the cable ID 0-15
 * @param channel the MIDI channel number 0-15
 * @param function 14bits
 * @param valueMSB higher 7bits
 * @param valueLSB lower 7bits. -1 if value has no LSB. If you know the function's parameter value have LSB, you must ignore when valueLSB < 0.
 */
@Override public void onMidiNRPNReceived(@NonNull MidiInputDevice sender,int cable,int channel,int function,int valueMSB,int valueLSB){
}

Fixed version (ground truth):
@Override public void onMidiNRPNReceived(@NonNull MidiInputDevice sender,int cable,int channel,int function,int value){
}
Program: 99448
Project: 99448
Buggy source:
/** 
 * RPN message This method is just the utility method, do not need to be implemented necessarily by subclass.
 * @param sender the Object which the event sent
 * @param cable the cable ID 0-15
 * @param channel the MIDI channel number 0-15
 * @param function 14bits
 * @param valueMSB higher 7bits
 * @param valueLSB lower 7bits. -1 if value has no LSB. If you know the function's parameter value have LSB, you must ignore when valueLSB < 0.
 */
@Override public void onMidiRPNReceived(@NonNull MidiInputDevice sender,int cable,int channel,int function,int valueMSB,int valueLSB){
}

Fixed version (ground truth):
@Override public void onMidiRPNReceived(@NonNull MidiInputDevice sender,int cable,int channel,int function,int value){
}
Program: 99449
Project: 99449
Buggy source:
/** 
 * NRPN message This method is just the utility method, do not need to be implemented necessarily by subclass.
 * @param sender the Object which the event sent
 * @param cable the cable ID 0-15
 * @param channel the MIDI channel number 0-15
 * @param function 14bits
 * @param valueMSB higher 7bits
 * @param valueLSB lower 7bits. -1 if value has no LSB. If you know the function's parameter value have LSB, you must ignore when valueLSB < 0.
 */
@Override public void onMidiNRPNReceived(@NonNull MidiInputDevice sender,int cable,int channel,int function,int valueMSB,int valueLSB){
}

Fixed version (ground truth):
@Override public void onMidiNRPNReceived(@NonNull MidiInputDevice sender,int cable,int channel,int function,int value){
}
Program: 99450
Project: 99450
Buggy source:
/** 
 * RPN message This method is just the utility method, do not need to be implemented necessarily by subclass.
 * @param sender the Object which the event sent
 * @param cable the cable ID 0-15
 * @param channel the MIDI channel number 0-15
 * @param function 14bits
 * @param valueMSB higher 7bits
 * @param valueLSB lower 7bits. -1 if value has no LSB. If you know the function's parameter value have LSB, you must ignore when valueLSB < 0.
 */
@Override public void onMidiRPNReceived(@NonNull MidiInputDevice sender,int cable,int channel,int function,int valueMSB,int valueLSB){
}

Fixed version (ground truth):
@Override public void onMidiRPNReceived(@NonNull MidiInputDevice sender,int cable,int channel,int function,int value){
}
Program: 99451
Project: 99451
Buggy source:
@Override public void onMidiNRPNReceived(@NonNull MidiInputDevice sender,int cable,int channel,int function,int valueMSB,int valueLSB){
  List<AbstractMidiFragment> midiFragments=getMidiFragments();
  for (  AbstractMidiFragment fragment : midiFragments) {
    fragment.onMidiNRPNReceived(sender,cable,channel,function,valueMSB,valueLSB);
  }
}

Fixed version (ground truth):
@Override public void onMidiNRPNReceived(@NonNull MidiInputDevice sender,int cable,int channel,int function,int value){
  List<AbstractMidiFragment> midiFragments=getMidiFragments();
  for (  AbstractMidiFragment fragment : midiFragments) {
    fragment.onMidiNRPNReceived(sender,cable,channel,function,value);
  }
}
Program: 99452
Project: 99452
Buggy source:
@Override public void onMidiRPNReceived(@NonNull MidiInputDevice sender,int cable,int channel,int function,int valueMSB,int valueLSB){
  List<AbstractMidiFragment> midiFragments=getMidiFragments();
  for (  AbstractMidiFragment fragment : midiFragments) {
    fragment.onMidiRPNReceived(sender,cable,channel,function,valueMSB,valueLSB);
  }
}

Fixed version (ground truth):
@Override public void onMidiRPNReceived(@NonNull MidiInputDevice sender,int cable,int channel,int function,int value){
  List<AbstractMidiFragment> midiFragments=getMidiFragments();
  for (  AbstractMidiFragment fragment : midiFragments) {
    fragment.onMidiRPNReceived(sender,cable,channel,function,value);
  }
}
Program: 99454
Project: 99454
Buggy source:
/** 
 * constructor
 * @param usbManager
 * @param deviceAttachedListener
 * @param deviceDetachedHandler
 */
MidiDeviceConnectionWatchThread(UsbManager usbManager,OnMidiDeviceAttachedListener deviceAttachedListener,Handler deviceDetachedHandler){
  this.usbManager=usbManager;
  this.deviceAttachedListener=deviceAttachedListener;
  this.deviceDetachedHandler=deviceDetachedHandler;
  connectedDeviceNameSet=new HashSet<String>();
  removedDeviceNames=new HashSet<String>();
  stopFlag=false;
  deviceFilters=DeviceFilter.getDeviceFilters(context);
}

Fixed version (ground truth):
/** 
 * constructor
 * @param usbManager
 * @param deviceAttachedListener
 * @param deviceDetachedHandler
 */
MidiDeviceConnectionWatchThread(UsbManager usbManager,OnMidiDeviceAttachedListener deviceAttachedListener,Handler deviceDetachedHandler){
  this.usbManager=usbManager;
  this.deviceAttachedListener=deviceAttachedListener;
  this.deviceDetachedHandler=deviceDetachedHandler;
  connectedDevices=new HashSet<UsbDevice>();
  stopFlag=false;
  deviceFilters=DeviceFilter.getDeviceFilters(context);
}
Program: 99455
Project: 99455
Buggy source:
@Override public void run(){
  super.run();
  while (stopFlag == false) {
    checkConnectedDevices();
synchronized (deviceGrantQueue) {
      if (!deviceGrantQueue.isEmpty() && !isGranting) {
        isGranting=true;
        UsbDevice device=deviceGrantQueue.remove();
        PendingIntent permissionIntent=PendingIntent.getBroadcast(context,0,new Intent(UsbMidiGrantedReceiver.USB_PERMISSION_GRANTED_ACTION),0);
        usbMidiGrantedReceiver=new UsbMidiGrantedReceiver(device.getDeviceName(),device,deviceAttachedListener);
        context.registerReceiver(usbMidiGrantedReceiver,new IntentFilter(UsbMidiGrantedReceiver.USB_PERMISSION_GRANTED_ACTION));
        usbManager.requestPermission(device,permissionIntent);
      }
    }
    try {
      sleep(1000);
    }
 catch (    InterruptedException e) {
    }
  }
}

Fixed version (ground truth):
@Override public void run(){
  super.run();
  while (stopFlag == false) {
    checkConnectedDevices();
synchronized (deviceGrantQueue) {
      if (!deviceGrantQueue.isEmpty() && !isGranting) {
        isGranting=true;
        grantingDevice=deviceGrantQueue.remove();
        PendingIntent permissionIntent=PendingIntent.getBroadcast(context,0,new Intent(UsbMidiGrantedReceiver.USB_PERMISSION_GRANTED_ACTION),0);
        usbMidiGrantedReceiver=new UsbMidiGrantedReceiver(grantingDevice,deviceAttachedListener);
        context.registerReceiver(usbMidiGrantedReceiver,new IntentFilter(UsbMidiGrantedReceiver.USB_PERMISSION_GRANTED_ACTION));
        usbManager.requestPermission(grantingDevice,permissionIntent);
      }
    }
    try {
      sleep(1000);
    }
 catch (    InterruptedException e) {
    }
  }
}
Program: 99456
Project: 99456
Buggy source:
/** 
 * checks Attached/Detached devices
 */
synchronized void checkConnectedDevices(){
  HashMap<String,UsbDevice> deviceMap=usbManager.getDeviceList();
  for (  String deviceName : deviceMap.keySet()) {
    if (removedDeviceNames.contains(deviceName)) {
      continue;
    }
    if (!connectedDeviceNameSet.contains(deviceName)) {
      connectedDeviceNameSet.add(deviceName);
      UsbDevice device=deviceMap.get(deviceName);
      Set<UsbInterface> midiInterfaces=UsbMidiDeviceUtils.findAllMidiInterfaces(device,deviceFilters);
      if (midiInterfaces.size() > 0) {
synchronized (deviceGrantQueue) {
          deviceGrantQueue.add(device);
        }
      }
    }
  }
  for (  String deviceName : connectedDeviceNameSet) {
    if (!deviceMap.containsKey(deviceName)) {
      removedDeviceNames.add(deviceName);
      UsbDevice device=grantedDeviceMap.remove(deviceName);
      Log.d(Constants.TAG,"String_Node_Str" + deviceName + "String_Node_Str"+ device+ "String_Node_Str");
      if (device != null) {
        Message message=deviceDetachedHandler.obtainMessage();
        message.obj=device;
        deviceDetachedHandler.sendMessage(message);
      }
    }
  }
  connectedDeviceNameSet.removeAll(removedDeviceNames);
}

Fixed version (ground truth):
/** 
 * checks Attached/Detached devices
 */
synchronized void checkConnectedDevices(){
  HashMap<String,UsbDevice> deviceMap=usbManager.getDeviceList();
  for (  UsbDevice device : deviceMap.values()) {
    if (deviceGrantQueue.contains(device) || connectedDevices.contains(device)) {
      continue;
    }
    Set<UsbInterface> midiInterfaces=UsbMidiDeviceUtils.findAllMidiInterfaces(device,deviceFilters);
    if (midiInterfaces.size() > 0) {
      Log.d(Constants.TAG,"String_Node_Str" + device.getDeviceName() + "String_Node_Str"+ device);
synchronized (deviceGrantQueue) {
        deviceGrantQueue.add(device);
      }
    }
  }
  for (  UsbDevice device : connectedDevices) {
    if (!deviceMap.containsValue(device)) {
      if (device.equals(grantingDevice)) {
        grantingDevice=null;
        continue;
      }
      grantedDevices.remove(device);
      Log.d(Constants.TAG,"String_Node_Str" + device.getDeviceName() + "String_Node_Str"+ device);
      Message message=deviceDetachedHandler.obtainMessage();
      message.obj=device;
      deviceDetachedHandler.sendMessage(message);
    }
  }
  connectedDevices.clear();
  connectedDevices.addAll(deviceMap.values());
}
Program: 99457
Project: 99457
Buggy source:
@Override public void onReceive(Context receiverContext,Intent intent){
  String action=intent.getAction();
  if (USB_PERMISSION_GRANTED_ACTION.equals(action)) {
    boolean granted=intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED,false);
    if (granted) {
      if (deviceAttachedListener != null && device != null) {
        grantedDeviceMap.put(deviceName,device);
        deviceAttachedListener.onDeviceAttached(device);
      }
    }
 else {
      notifyDeviceGranted();
    }
  }
}

Fixed version (ground truth):
@Override public void onReceive(Context receiverContext,Intent intent){
  String action=intent.getAction();
  if (USB_PERMISSION_GRANTED_ACTION.equals(action)) {
    boolean granted=intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED,false);
    if (granted) {
      if (deviceAttachedListener != null && device != null) {
        grantedDevices.add(device);
        deviceAttachedListener.onDeviceAttached(device);
      }
      isGranting=false;
      grantingDevice=null;
    }
 else {
      notifyDeviceGranted();
    }
  }
}
Program: 99458
Project: 99458
Buggy source:
/** 
 * constructor
 * @param context
 * @param usbManager
 * @param deviceAttachedListener
 * @param deviceDetachedListener
 */
public MidiDeviceConnectionWatcher(Context context,UsbManager usbManager,OnMidiDeviceAttachedListener deviceAttachedListener,final OnMidiDeviceDetachedListener deviceDetachedListener){
  this.context=context;
  deviceGrantQueue=new LinkedList<UsbDevice>();
  isGranting=false;
  grantedDeviceMap=new HashMap<String,UsbDevice>();
  deviceDetachedHandler=new Handler(new Handler.Callback(){
    @Override public boolean handleMessage(    Message message){
      UsbDevice detachedDevice=(UsbDevice)message.obj;
      deviceDetachedListener.onDeviceDetached(detachedDevice);
      return true;
    }
  }
);
  thread=new MidiDeviceConnectionWatchThread(usbManager,deviceAttachedListener,deviceDetachedHandler);
  thread.setName("String_Node_Str");
  thread.start();
}

Fixed version (ground truth):
/** 
 * constructor
 * @param context
 * @param usbManager
 * @param deviceAttachedListener
 * @param deviceDetachedListener
 */
public MidiDeviceConnectionWatcher(Context context,UsbManager usbManager,OnMidiDeviceAttachedListener deviceAttachedListener,final OnMidiDeviceDetachedListener deviceDetachedListener){
  this.context=context;
  deviceGrantQueue=new LinkedList<UsbDevice>();
  isGranting=false;
  grantingDevice=null;
  grantedDevices=new HashSet<UsbDevice>();
  deviceDetachedHandler=new Handler(new Handler.Callback(){
    @Override public boolean handleMessage(    Message message){
      UsbDevice detachedDevice=(UsbDevice)message.obj;
      deviceDetachedListener.onDeviceDetached(detachedDevice);
      return true;
    }
  }
);
  thread=new MidiDeviceConnectionWatchThread(usbManager,deviceAttachedListener,deviceDetachedHandler);
  thread.setName("String_Node_Str");
  thread.start();
}
Program: 99459
Project: 99459
Buggy source:
/** 
 * @param device
 * @param deviceAttachedListener
 */
public UsbMidiGrantedReceiver(String deviceName,UsbDevice device,OnMidiDeviceAttachedListener deviceAttachedListener){
  this.deviceName=deviceName;
  this.device=device;
  this.deviceAttachedListener=deviceAttachedListener;
}

Fixed version (ground truth):
/** 
 * @param device
 * @param deviceAttachedListener
 */
public UsbMidiGrantedReceiver(UsbDevice device,OnMidiDeviceAttachedListener deviceAttachedListener){
  this.device=device;
  this.deviceAttachedListener=deviceAttachedListener;
}
Program: 99460
Project: 99460
Buggy source:
/** 
 * Sends MIDI message to output device.
 * @param codeIndexNumber Code Index Number(CIN)
 * @param cable the cable ID 0-15
 * @param byte1 the first byte
 * @param byte2 the second byte
 * @param byte3 the third byte
 */
private void sendMidiMessage(int codeIndexNumber,int cable,int byte1,int byte2,int byte3){
  byte[] writeBuffer=new byte[4];
  writeBuffer[0]=(byte)(((cable & 0xf) << 4) | (codeIndexNumber & 0xf));
  writeBuffer[1]=(byte)byte1;
  writeBuffer[2]=(byte)byte2;
  writeBuffer[3]=(byte)byte3;
  Handler handler=waiterThread.getHandler();
  handler.sendMessage(Message.obtain(handler,0,writeBuffer));
}

Fixed version (ground truth):
/** 
 * Send a MIDI message with 3 bytes raw MIDI data
 * @param cable the cable ID 0-15
 * @param byte1 the first byte
 * @param byte2 the second byte: ignored when 1 byte message
 * @param byte3 the third byte: ignored when 1-2 byte message
 */
public void sendMidiMessage(int cable,int byte1,int byte2,int byte3){
  int codeIndexNumber=0;
switch (byte1 & 0xf0) {
case 0x80:
    codeIndexNumber=0x8;
  break;
case 0x90:
codeIndexNumber=0x9;
break;
case 0xa0:
codeIndexNumber=0xa;
break;
case 0xb0:
codeIndexNumber=0xb;
break;
case 0xc0:
codeIndexNumber=0xc;
break;
case 0xd0:
codeIndexNumber=0xd;
break;
case 0xe0:
codeIndexNumber=0xe;
break;
case 0xf0:
switch (byte1) {
case 0xf0:
if (byte2 == 0xf7) {
codeIndexNumber=0x6;
}
 else if (byte3 == 0xf7) {
codeIndexNumber=0x7;
}
 else {
return;
}
break;
case 0xf7:
return;
case 0xf4:
case 0xf5:
case 0xf9:
case 0xfd:
return;
case 0xf6:
case 0xf8:
case 0xfa:
case 0xfb:
case 0xfc:
case 0xfe:
case 0xff:
codeIndexNumber=0x5;
break;
case 0xf1:
case 0xf3:
codeIndexNumber=0x2;
break;
case 0xf2:
codeIndexNumber=0x3;
break;
default :
break;
}
break;
default :
return;
}
sendMidiMessage(codeIndexNumber,cable,byte1,byte2,byte3);
}
Program: 99461
Project: 99461
Buggy source:
/** 
 * Get UsbDevice's manufacturer name
 * @param usbDevice the UsbDevice
 * @param usbDeviceConnection the UsbDeviceConnection
 * @return the manufacturer name
 */
@Nullable public static String getManufacturerName(@NonNull UsbDevice usbDevice,@NonNull UsbDeviceConnection usbDeviceConnection){
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    return usbDevice.getManufacturerName();
  }
 else   if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
    byte[] rawDescriptors=usbDeviceConnection.getRawDescriptors();
    try {
      byte[] buffer=new byte[255];
      int indexOfManufacturerName=rawDescriptors[14] & 0xff;
      int manufacturerNameLength=usbDeviceConnection.controlTransfer(UsbConstants.USB_DIR_IN,USB_REQUEST_GET_DESCRIPTOR,(USB_DATA_TYPE_STRING << 8) | indexOfManufacturerName,0,buffer,255,0);
      return new String(buffer,2,manufacturerNameLength - 2,"String_Node_Str");
    }
 catch (    UnsupportedEncodingException e) {
      e.printStackTrace();
    }
  }
  return null;
}

Fixed version (ground truth):
/** 
 * Get UsbDevice's manufacturer name
 * @param usbDevice the UsbDevice
 * @param usbDeviceConnection the UsbDeviceConnection
 * @return the manufacturer name
 */
@SuppressLint("String_Node_Str") @Nullable public static String getManufacturerName(@NonNull UsbDevice usbDevice,@NonNull UsbDeviceConnection usbDeviceConnection){
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    return usbDevice.getManufacturerName();
  }
 else   if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
    byte[] rawDescriptors=usbDeviceConnection.getRawDescriptors();
    try {
      byte[] buffer=new byte[255];
      int indexOfManufacturerName=rawDescriptors[14] & 0xff;
      int manufacturerNameLength=usbDeviceConnection.controlTransfer(UsbConstants.USB_DIR_IN,USB_REQUEST_GET_DESCRIPTOR,(USB_DATA_TYPE_STRING << 8) | indexOfManufacturerName,0,buffer,255,0);
      return new String(buffer,2,manufacturerNameLength - 2,"String_Node_Str");
    }
 catch (    UnsupportedEncodingException e) {
      e.printStackTrace();
    }
  }
  return null;
}
Program: 99462
Project: 99462
Buggy source:
/** 
 * Get UsbDevice's product name
 * @param usbDevice the UsbDevice
 * @param usbDeviceConnection the UsbDeviceConnection
 * @return the product name
 */
@Nullable public static String getProductName(@NonNull UsbDevice usbDevice,@NonNull UsbDeviceConnection usbDeviceConnection){
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    return usbDevice.getProductName();
  }
 else   if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
    byte[] rawDescriptors=usbDeviceConnection.getRawDescriptors();
    try {
      byte[] buffer=new byte[255];
      int indexOfProductName=rawDescriptors[15] & 0xff;
      int productNameLength=usbDeviceConnection.controlTransfer(UsbConstants.USB_DIR_IN,USB_REQUEST_GET_DESCRIPTOR,(USB_DATA_TYPE_STRING << 8) | indexOfProductName,0,buffer,255,0);
      return new String(buffer,2,productNameLength - 2,"String_Node_Str");
    }
 catch (    UnsupportedEncodingException e) {
      e.printStackTrace();
    }
  }
  return null;
}

Fixed version (ground truth):
/** 
 * Get UsbDevice's product name
 * @param usbDevice the UsbDevice
 * @param usbDeviceConnection the UsbDeviceConnection
 * @return the product name
 */
@SuppressLint("String_Node_Str") @Nullable public static String getProductName(@NonNull UsbDevice usbDevice,@NonNull UsbDeviceConnection usbDeviceConnection){
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    return usbDevice.getProductName();
  }
 else   if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
    byte[] rawDescriptors=usbDeviceConnection.getRawDescriptors();
    try {
      byte[] buffer=new byte[255];
      int indexOfProductName=rawDescriptors[15] & 0xff;
      int productNameLength=usbDeviceConnection.controlTransfer(UsbConstants.USB_DIR_IN,USB_REQUEST_GET_DESCRIPTOR,(USB_DATA_TYPE_STRING << 8) | indexOfProductName,0,buffer,255,0);
      return new String(buffer,2,productNameLength - 2,"String_Node_Str");
    }
 catch (    UnsupportedEncodingException e) {
      e.printStackTrace();
    }
  }
  return null;
}
Program: 99463
Project: 99463
Buggy source:
/** 
 * stops the watching thread
 */
public void stop(){
  usbDeviceConnection.releaseInterface(usbInterface);
  resume();
  waiterThread.stopFlag=true;
  while (waiterThread.isAlive()) {
    try {
      Thread.sleep(100);
    }
 catch (    InterruptedException e) {
    }
  }
}

Fixed version (ground truth):
/** 
 * stops the watching thread
 */
public void stop(){
  usbDeviceConnection.releaseInterface(usbInterface);
  waiterThread.stopFlag=true;
  resume();
  while (waiterThread.isAlive()) {
    try {
      Thread.sleep(100);
    }
 catch (    InterruptedException e) {
    }
  }
}