Program: 58234
Project: 58234
Buggy source:
@Override public void onAdvertisementUpdate(ScanResult scanResult){
  if (mConnectedDevices.contains(scanResult.getDevice().getAddress())) {
    logEvent("String_Node_Str" + scanResult.getDevice().getAddress());
    return;
  }
  if (mConnectingDevices.contains(scanResult.getDevice().getAddress())) {
    logEvent("String_Node_Str" + scanResult.getDevice().getAddress());
    return;
  }
  if (mConnectionGovernor != null && !mConnectionGovernor.shouldConnectToPeripheral(scanResult)) {
    logEvent("String_Node_Str" + scanResult.getDevice().getAddress());
    return;
  }
  mConnectingDevices.add(scanResult.getDevice().getAddress());
  logEvent("String_Node_Str" + scanResult.getDevice().getAddress());
  scanResult.getDevice().connectGatt(mContext,false,new BluetoothGattCallback(){
    @Override public void onConnectionStateChange(    BluetoothGatt gatt,    int status,    int newState){
      if (status == BluetoothGatt.GATT_SUCCESS) {
        logEvent("String_Node_Str");
      }
 else {
      }
switch (newState) {
case BluetoothProfile.STATE_DISCONNECTED:
        logEvent("String_Node_Str" + gatt.getDevice().getAddress());
      mConnectedDevices.remove(gatt.getDevice().getAddress());
    mConnectingDevices.remove(gatt.getDevice().getAddress());
  if (mConnectionListener != null)   mConnectionListener.disconnectedFrom(gatt.getDevice().getAddress());
gatt.close();
startScanning();
break;
case BluetoothProfile.STATE_CONNECTED:
logEvent("String_Node_Str" + gatt.getDevice().getAddress());
mConnectedDevices.add(gatt.getDevice().getAddress());
mConnectingDevices.remove(gatt.getDevice().getAddress());
if (mConnectionListener != null) mConnectionListener.connectedTo(gatt.getDevice().getAddress());
stopScanning();
boolean discovering=gatt.discoverServices();
logEvent("String_Node_Str" + discovering);
break;
}
super.onConnectionStateChange(gatt,status,newState);
}
@Override public void onServicesDiscovered(BluetoothGatt gatt,int status){
if (status == BluetoothGatt.GATT_SUCCESS) logEvent("String_Node_Str");
 else logEvent("String_Node_Str" + status);
boolean foundService=false;
try {
List<BluetoothGattService> serviceList=gatt.getServices();
for (BluetoothGattService service : serviceList) {
if (service.getUuid().equals(GATT.SERVICE_UUID)) {
logEvent("String_Node_Str");
foundService=true;
List<BluetoothGattCharacteristic> characteristics=service.getCharacteristics();
for (BluetoothGattCharacteristic characteristic : characteristics) {
if (characteristic.getUuid().equals(GATT.IDENTITY_READ_UUID)) {
mCharacteristicUUIDToRequest.get(characteristic.getUuid()).mCharacteristic=characteristic;
}
 else if (characteristic.getUuid().equals(GATT.IDENTITY_WRITE_UUID)) {
mCharacteristicUUIDToRequest.get(characteristic.getUuid()).mCharacteristic=characteristic;
}
 else if (characteristic.getUuid().equals(GATT.MESSAGES_READ_UUID)) {
mCharacteristicUUIDToRequest.get(characteristic.getUuid()).mCharacteristic=characteristic;
}
 else if (characteristic.getUuid().equals(GATT.MESSAGES_WRITE_UUID)) {
mCharacteristicUUIDToRequest.get(characteristic.getUuid()).mCharacteristic=characteristic;
}
}
}
}
}
 catch (Exception e) {
logEvent("String_Node_Str" + e.getLocalizedMessage());
e.printStackTrace();
}
if (!foundService) logEvent("String_Node_Str");
 else beginRequestFlowWithPeripheral(gatt);
super.onServicesDiscovered(gatt,status);
}
@Override public void onCharacteristicRead(BluetoothGatt gatt,BluetoothGattCharacteristic characteristic,int status){
logEvent(String.format("String_Node_Str",characteristic.getUuid().toString().substring(0,3),characteristic.getValue() == null ? "String_Node_Str" : DataUtil.bytesToHex(characteristic.getValue()),status));
handleResponseForCurrentRequestToPeripheral(gatt,BLECentralRequest.RequestType.READ,characteristic,status);
super.onCharacteristicRead(gatt,characteristic,status);
}
@Override public void onCharacteristicWrite(BluetoothGatt gatt,BluetoothGattCharacteristic characteristic,int status){
logEvent(String.format("String_Node_Str",characteristic.getUuid(),status));
handleResponseForCurrentRequestToPeripheral(gatt,BLECentralRequest.RequestType.WRITE,characteristic,status);
super.onCharacteristicWrite(gatt,characteristic,status);
}
@Override public void onCharacteristicChanged(BluetoothGatt gatt,BluetoothGattCharacteristic characteristic){
String toLog=null;
try {
toLog="String_Node_Str" + characteristic.getStringValue(0);
}
 catch (Exception e) {
toLog="String_Node_Str" + characteristic.getUuid().toString();
}
logEvent(toLog);
super.onCharacteristicChanged(gatt,characteristic);
}
@Override public void onReadRemoteRssi(BluetoothGatt gatt,int rssi,int status){
Log.i(TAG,"String_Node_Str");
super.onReadRemoteRssi(gatt,rssi,status);
}
}
);
}

Fixed version (ground truth):
@Override public void onAdvertisementUpdate(ScanResult scanResult){
  if (mConnectedDevices.contains(scanResult.getDevice().getAddress())) {
    return;
  }
  if (mConnectingDevices.contains(scanResult.getDevice().getAddress())) {
    return;
  }
  if (mConnectionGovernor != null && !mConnectionGovernor.shouldConnectToPeripheral(scanResult)) {
    return;
  }
  mConnectingDevices.add(scanResult.getDevice().getAddress());
  logEvent("String_Node_Str" + scanResult.getDevice().getAddress());
  scanResult.getDevice().connectGatt(mContext,false,new BluetoothGattCallback(){
    @Override public void onConnectionStateChange(    BluetoothGatt gatt,    int status,    int newState){
      if (status == BluetoothGatt.GATT_SUCCESS) {
        logEvent("String_Node_Str");
      }
 else {
      }
switch (newState) {
case BluetoothProfile.STATE_DISCONNECTED:
        logEvent("String_Node_Str" + gatt.getDevice().getAddress());
      mConnectedDevices.remove(gatt.getDevice().getAddress());
    mConnectingDevices.remove(gatt.getDevice().getAddress());
  if (mConnectionListener != null)   mConnectionListener.disconnectedFrom(gatt.getDevice().getAddress());
gatt.close();
break;
case BluetoothProfile.STATE_CONNECTED:
logEvent("String_Node_Str" + gatt.getDevice().getAddress());
mConnectedDevices.add(gatt.getDevice().getAddress());
mConnectingDevices.remove(gatt.getDevice().getAddress());
if (mConnectionListener != null) mConnectionListener.connectedTo(gatt.getDevice().getAddress());
boolean discovering=gatt.discoverServices();
logEvent("String_Node_Str" + discovering);
break;
}
super.onConnectionStateChange(gatt,status,newState);
}
@Override public void onServicesDiscovered(BluetoothGatt gatt,int status){
if (status == BluetoothGatt.GATT_SUCCESS) logEvent("String_Node_Str");
 else logEvent("String_Node_Str" + status);
boolean foundService=false;
try {
List<BluetoothGattService> serviceList=gatt.getServices();
for (BluetoothGattService service : serviceList) {
if (service.getUuid().equals(GATT.SERVICE_UUID)) {
logEvent("String_Node_Str");
foundService=true;
List<BluetoothGattCharacteristic> characteristics=service.getCharacteristics();
for (BluetoothGattCharacteristic characteristic : characteristics) {
if (characteristic.getUuid().equals(GATT.IDENTITY_READ_UUID)) {
mCharacteristicUUIDToRequest.get(characteristic.getUuid()).mCharacteristic=characteristic;
}
 else if (characteristic.getUuid().equals(GATT.IDENTITY_WRITE_UUID)) {
mCharacteristicUUIDToRequest.get(characteristic.getUuid()).mCharacteristic=characteristic;
}
 else if (characteristic.getUuid().equals(GATT.MESSAGES_READ_UUID)) {
mCharacteristicUUIDToRequest.get(characteristic.getUuid()).mCharacteristic=characteristic;
}
 else if (characteristic.getUuid().equals(GATT.MESSAGES_WRITE_UUID)) {
mCharacteristicUUIDToRequest.get(characteristic.getUuid()).mCharacteristic=characteristic;
}
}
}
}
}
 catch (Exception e) {
logEvent("String_Node_Str" + e.getLocalizedMessage());
e.printStackTrace();
}
if (!foundService) logEvent("String_Node_Str");
 else beginRequestFlowWithPeripheral(gatt);
super.onServicesDiscovered(gatt,status);
}
@Override public void onCharacteristicRead(BluetoothGatt gatt,BluetoothGattCharacteristic characteristic,int status){
logEvent(String.format("String_Node_Str",characteristic.getUuid().toString().substring(0,3),characteristic.getValue() == null ? "String_Node_Str" : DataUtil.bytesToHex(characteristic.getValue()),status));
handleResponseForCurrentRequestToPeripheral(gatt,BLECentralRequest.RequestType.READ,characteristic,status);
super.onCharacteristicRead(gatt,characteristic,status);
}
@Override public void onCharacteristicWrite(BluetoothGatt gatt,BluetoothGattCharacteristic characteristic,int status){
logEvent(String.format("String_Node_Str",characteristic.getUuid(),status));
handleResponseForCurrentRequestToPeripheral(gatt,BLECentralRequest.RequestType.WRITE,characteristic,status);
super.onCharacteristicWrite(gatt,characteristic,status);
}
@Override public void onCharacteristicChanged(BluetoothGatt gatt,BluetoothGattCharacteristic characteristic){
String toLog=null;
try {
toLog="String_Node_Str" + characteristic.getStringValue(0);
}
 catch (Exception e) {
toLog="String_Node_Str" + characteristic.getUuid().toString();
}
logEvent(toLog);
super.onCharacteristicChanged(gatt,characteristic);
}
@Override public void onReadRemoteRssi(BluetoothGatt gatt,int rssi,int status){
Log.i(TAG,"String_Node_Str");
super.onReadRemoteRssi(gatt,rssi,status);
}
}
);
}