Program: 162668
Project: 162668
Buggy source:
@TargetApi(5) protected Beacon fromScanData(byte[] bytesToProcess,int rssi,BluetoothDevice device,Beacon beacon){
  BleAdvertisement advert=new BleAdvertisement(bytesToProcess);
  boolean parseFailed=false;
  Pdu pduToParse=null;
  int startByte=0;
  ArrayList<Identifier> identifiers=new ArrayList<Identifier>();
  ArrayList<Long> dataFields=new ArrayList<Long>();
  for (  Pdu pdu : advert.getPdus()) {
    if (pdu.getType() == Pdu.GATT_SERVICE_UUID_PDU_TYPE || pdu.getType() == Pdu.MANUFACTURER_DATA_PDU_TYPE) {
      pduToParse=pdu;
      if (LogManager.isVerboseLoggingEnabled()) {
        LogManager.d(TAG,"String_Node_Str",pdu.getType(),bytesToHex(bytesToProcess),pdu.getStartIndex(),pdu.getEndIndex());
      }
      break;
    }
 else {
      if (LogManager.isVerboseLoggingEnabled()) {
        LogManager.d(TAG,"String_Node_Str",pdu.getType());
      }
    }
  }
  if (pduToParse == null) {
    if (LogManager.isVerboseLoggingEnabled()) {
      LogManager.d(TAG,"String_Node_Str");
    }
    parseFailed=true;
  }
 else {
    byte[] serviceUuidBytes=null;
    byte[] typeCodeBytes=longToByteArray(getMatchingBeaconTypeCode(),mMatchingBeaconTypeCodeEndOffset - mMatchingBeaconTypeCodeStartOffset + 1);
    if (getServiceUuid() != null) {
      serviceUuidBytes=longToByteArray(getServiceUuid(),mServiceUuidEndOffset - mServiceUuidStartOffset + 1,false);
    }
    startByte=pduToParse.getStartIndex();
    boolean patternFound=false;
    if (getServiceUuid() == null) {
      if (byteArraysMatch(bytesToProcess,startByte + mMatchingBeaconTypeCodeStartOffset,typeCodeBytes,0)) {
        patternFound=true;
      }
    }
 else {
      if (byteArraysMatch(bytesToProcess,startByte + mServiceUuidStartOffset,serviceUuidBytes,0) && byteArraysMatch(bytesToProcess,startByte + mMatchingBeaconTypeCodeStartOffset,typeCodeBytes,0)) {
        patternFound=true;
      }
    }
    if (patternFound == false) {
      if (getServiceUuid() == null) {
        if (LogManager.isVerboseLoggingEnabled()) {
          LogManager.d(TAG,"String_Node_Str" + "String_Node_Str",byteArrayToString(typeCodeBytes),bytesToHex(bytesToProcess));
        }
      }
 else {
        if (LogManager.isVerboseLoggingEnabled()) {
          LogManager.d(TAG,"String_Node_Str" + "String_Node_Str",byteArrayToString(serviceUuidBytes),startByte + mServiceUuidStartOffset,byteArrayToString(typeCodeBytes),startByte + mMatchingBeaconTypeCodeStartOffset,bytesToHex(bytesToProcess));
        }
      }
      parseFailed=true;
      beacon=null;
    }
 else {
      if (LogManager.isVerboseLoggingEnabled()) {
        LogManager.d(TAG,"String_Node_Str",byteArrayToString(typeCodeBytes));
        LogManager.d(TAG,"String_Node_Str",bytesToHex(bytesToProcess));
      }
    }
    if (patternFound) {
      if (bytesToProcess.length <= startByte + mLayoutSize && mAllowPduOverflow) {
        if (LogManager.isVerboseLoggingEnabled()) {
          LogManager.d(TAG,"String_Node_Str" + bytesToProcess.length + "String_Node_Str"+ (startByte + mLayoutSize));
        }
        bytesToProcess=ensureMaxSize(bytesToProcess,startByte + mLayoutSize);
      }
      for (int i=0; i < mIdentifierEndOffsets.size(); i++) {
        int endIndex=mIdentifierEndOffsets.get(i) + startByte;
        if (endIndex > pduToParse.getEndIndex() && mIdentifierVariableLengthFlags.get(i)) {
          if (LogManager.isVerboseLoggingEnabled()) {
            LogManager.d(TAG,"String_Node_Str" + (endIndex - pduToParse.getEndIndex()));
          }
          Identifier identifier=Identifier.fromBytes(bytesToProcess,mIdentifierStartOffsets.get(i) + startByte,pduToParse.getEndIndex() + 1,mIdentifierLittleEndianFlags.get(i));
          identifiers.add(identifier);
        }
 else         if (endIndex > pduToParse.getEndIndex() && !mAllowPduOverflow) {
          parseFailed=true;
          if (LogManager.isVerboseLoggingEnabled()) {
            LogManager.d(TAG,"String_Node_Str" + i + "String_Node_Str"+ endIndex+ "String_Node_Str"+ pduToParse.getEndIndex());
          }
        }
 else {
          Identifier identifier=Identifier.fromBytes(bytesToProcess,mIdentifierStartOffsets.get(i) + startByte,endIndex + 1,mIdentifierLittleEndianFlags.get(i));
          identifiers.add(identifier);
        }
      }
      for (int i=0; i < mDataEndOffsets.size(); i++) {
        int endIndex=mDataEndOffsets.get(i) + startByte;
        if (endIndex > pduToParse.getEndIndex() && !mAllowPduOverflow) {
          if (LogManager.isVerboseLoggingEnabled()) {
            LogManager.d(TAG,"String_Node_Str" + i + "String_Node_Str"+ endIndex+ "String_Node_Str"+ pduToParse.getEndIndex()+ "String_Node_Str");
          }
          dataFields.add(new Long(0l));
        }
 else {
          String dataString=byteArrayToFormattedString(bytesToProcess,mDataStartOffsets.get(i) + startByte,endIndex,mDataLittleEndianFlags.get(i));
          dataFields.add(Long.parseLong(dataString));
        }
      }
      if (mPowerStartOffset != null) {
        int endIndex=mPowerEndOffset + startByte;
        int txPower=0;
        try {
          if (endIndex > pduToParse.getEndIndex() && !mAllowPduOverflow) {
            parseFailed=true;
            if (LogManager.isVerboseLoggingEnabled()) {
              LogManager.d(TAG,"String_Node_Str" + endIndex + "String_Node_Str"+ pduToParse.getEndIndex());
            }
          }
 else {
            String powerString=byteArrayToFormattedString(bytesToProcess,mPowerStartOffset + startByte,mPowerEndOffset + startByte,false);
            txPower=Integer.parseInt(powerString) + mDBmCorrection;
            if (txPower > 127) {
              txPower-=256;
            }
            beacon.mTxPower=txPower;
          }
        }
 catch (        NumberFormatException e1) {
        }
catch (        NullPointerException e2) {
        }
      }
    }
  }
  if (parseFailed) {
    beacon=null;
  }
 else {
    int beaconTypeCode=0;
    String beaconTypeString=byteArrayToFormattedString(bytesToProcess,mMatchingBeaconTypeCodeStartOffset + startByte,mMatchingBeaconTypeCodeEndOffset + startByte,false);
    beaconTypeCode=Integer.parseInt(beaconTypeString);
    int manufacturer=0;
    String manufacturerString=byteArrayToFormattedString(bytesToProcess,startByte,startByte + 1,true);
    manufacturer=Integer.parseInt(manufacturerString);
    String macAddress=null;
    String name=null;
    if (device != null) {
      macAddress=device.getAddress();
      name=device.getName();
    }
    beacon.mIdentifiers=identifiers;
    beacon.mDataFields=dataFields;
    beacon.mRssi=rssi;
    beacon.mBeaconTypeCode=beaconTypeCode;
    if (mServiceUuid != null) {
      beacon.mServiceUuid=(int)mServiceUuid.longValue();
    }
 else {
      beacon.mServiceUuid=-1;
    }
    beacon.mBluetoothAddress=macAddress;
    beacon.mBluetoothName=name;
    beacon.mManufacturer=manufacturer;
    beacon.mParserIdentifier=mIdentifier;
  }
  return beacon;
}

Fixed version (ground truth):
@TargetApi(5) protected Beacon fromScanData(byte[] bytesToProcess,int rssi,BluetoothDevice device,Beacon beacon){
  BleAdvertisement advert=new BleAdvertisement(bytesToProcess);
  boolean parseFailed=false;
  Pdu pduToParse=null;
  int startByte=0;
  ArrayList<Identifier> identifiers=new ArrayList<Identifier>();
  ArrayList<Long> dataFields=new ArrayList<Long>();
  for (  Pdu pdu : advert.getPdus()) {
    if (pdu.getType() == Pdu.GATT_SERVICE_UUID_PDU_TYPE || pdu.getType() == Pdu.MANUFACTURER_DATA_PDU_TYPE) {
      pduToParse=pdu;
      if (LogManager.isVerboseLoggingEnabled()) {
        LogManager.d(TAG,"String_Node_Str",pdu.getType(),bytesToHex(bytesToProcess),pdu.getStartIndex(),pdu.getEndIndex());
      }
      break;
    }
 else {
      if (LogManager.isVerboseLoggingEnabled()) {
        LogManager.d(TAG,"String_Node_Str",pdu.getType());
      }
    }
  }
  if (pduToParse == null) {
    if (LogManager.isVerboseLoggingEnabled()) {
      LogManager.d(TAG,"String_Node_Str");
    }
    parseFailed=true;
  }
 else {
    byte[] serviceUuidBytes=null;
    byte[] typeCodeBytes=longToByteArray(getMatchingBeaconTypeCode(),mMatchingBeaconTypeCodeEndOffset - mMatchingBeaconTypeCodeStartOffset + 1);
    if (getServiceUuid() != null) {
      serviceUuidBytes=longToByteArray(getServiceUuid(),mServiceUuidEndOffset - mServiceUuidStartOffset + 1,false);
    }
    startByte=pduToParse.getStartIndex();
    boolean patternFound=false;
    if (getServiceUuid() == null) {
      if (byteArraysMatch(bytesToProcess,startByte + mMatchingBeaconTypeCodeStartOffset,typeCodeBytes,0)) {
        patternFound=true;
      }
    }
 else {
      if (byteArraysMatch(bytesToProcess,startByte + mServiceUuidStartOffset,serviceUuidBytes,0) && byteArraysMatch(bytesToProcess,startByte + mMatchingBeaconTypeCodeStartOffset,typeCodeBytes,0)) {
        patternFound=true;
      }
    }
    if (patternFound == false) {
      if (getServiceUuid() == null) {
        if (LogManager.isVerboseLoggingEnabled()) {
          LogManager.d(TAG,"String_Node_Str" + "String_Node_Str",byteArrayToString(typeCodeBytes),bytesToHex(bytesToProcess));
        }
      }
 else {
        if (LogManager.isVerboseLoggingEnabled()) {
          LogManager.d(TAG,"String_Node_Str" + "String_Node_Str",byteArrayToString(serviceUuidBytes),startByte + mServiceUuidStartOffset,byteArrayToString(typeCodeBytes),startByte + mMatchingBeaconTypeCodeStartOffset,bytesToHex(bytesToProcess));
        }
      }
      parseFailed=true;
      beacon=null;
    }
 else {
      if (LogManager.isVerboseLoggingEnabled()) {
        LogManager.d(TAG,"String_Node_Str",byteArrayToString(typeCodeBytes));
        LogManager.d(TAG,"String_Node_Str",bytesToHex(bytesToProcess));
      }
    }
    if (patternFound) {
      if (bytesToProcess.length <= startByte + mLayoutSize && mAllowPduOverflow) {
        if (LogManager.isVerboseLoggingEnabled()) {
          LogManager.d(TAG,"String_Node_Str" + bytesToProcess.length + "String_Node_Str"+ (startByte + mLayoutSize));
        }
        bytesToProcess=ensureMaxSize(bytesToProcess,startByte + mLayoutSize);
      }
      for (int i=0; i < mIdentifierEndOffsets.size(); i++) {
        int endIndex=mIdentifierEndOffsets.get(i) + startByte;
        if (endIndex > pduToParse.getEndIndex() && mIdentifierVariableLengthFlags.get(i)) {
          if (LogManager.isVerboseLoggingEnabled()) {
            LogManager.d(TAG,"String_Node_Str" + (endIndex - pduToParse.getEndIndex()));
          }
          Identifier identifier=Identifier.fromBytes(bytesToProcess,mIdentifierStartOffsets.get(i) + startByte,pduToParse.getEndIndex() + 1,mIdentifierLittleEndianFlags.get(i));
          identifiers.add(identifier);
        }
 else         if (endIndex > pduToParse.getEndIndex() && !mAllowPduOverflow) {
          parseFailed=true;
          if (LogManager.isVerboseLoggingEnabled()) {
            LogManager.d(TAG,"String_Node_Str" + i + "String_Node_Str"+ endIndex+ "String_Node_Str"+ pduToParse.getEndIndex());
          }
        }
 else {
          Identifier identifier=Identifier.fromBytes(bytesToProcess,mIdentifierStartOffsets.get(i) + startByte,endIndex + 1,mIdentifierLittleEndianFlags.get(i));
          identifiers.add(identifier);
        }
      }
      for (int i=0; i < mDataEndOffsets.size(); i++) {
        int endIndex=mDataEndOffsets.get(i) + startByte;
        if (endIndex > pduToParse.getEndIndex() && !mAllowPduOverflow) {
          if (LogManager.isVerboseLoggingEnabled()) {
            LogManager.d(TAG,"String_Node_Str" + i + "String_Node_Str"+ endIndex+ "String_Node_Str"+ pduToParse.getEndIndex()+ "String_Node_Str");
          }
          dataFields.add(new Long(0l));
        }
 else {
          String dataString=byteArrayToFormattedString(bytesToProcess,mDataStartOffsets.get(i) + startByte,endIndex,mDataLittleEndianFlags.get(i));
          dataFields.add(Long.decode(dataString));
        }
      }
      if (mPowerStartOffset != null) {
        int endIndex=mPowerEndOffset + startByte;
        int txPower=0;
        try {
          if (endIndex > pduToParse.getEndIndex() && !mAllowPduOverflow) {
            parseFailed=true;
            if (LogManager.isVerboseLoggingEnabled()) {
              LogManager.d(TAG,"String_Node_Str" + endIndex + "String_Node_Str"+ pduToParse.getEndIndex());
            }
          }
 else {
            String powerString=byteArrayToFormattedString(bytesToProcess,mPowerStartOffset + startByte,mPowerEndOffset + startByte,false);
            txPower=Integer.parseInt(powerString) + mDBmCorrection;
            if (txPower > 127) {
              txPower-=256;
            }
            beacon.mTxPower=txPower;
          }
        }
 catch (        NumberFormatException e1) {
        }
catch (        NullPointerException e2) {
        }
      }
    }
  }
  if (parseFailed) {
    beacon=null;
  }
 else {
    int beaconTypeCode=0;
    String beaconTypeString=byteArrayToFormattedString(bytesToProcess,mMatchingBeaconTypeCodeStartOffset + startByte,mMatchingBeaconTypeCodeEndOffset + startByte,false);
    beaconTypeCode=Integer.parseInt(beaconTypeString);
    int manufacturer=0;
    String manufacturerString=byteArrayToFormattedString(bytesToProcess,startByte,startByte + 1,true);
    manufacturer=Integer.parseInt(manufacturerString);
    String macAddress=null;
    String name=null;
    if (device != null) {
      macAddress=device.getAddress();
      name=device.getName();
    }
    beacon.mIdentifiers=identifiers;
    beacon.mDataFields=dataFields;
    beacon.mRssi=rssi;
    beacon.mBeaconTypeCode=beaconTypeCode;
    if (mServiceUuid != null) {
      beacon.mServiceUuid=(int)mServiceUuid.longValue();
    }
 else {
      beacon.mServiceUuid=-1;
    }
    beacon.mBluetoothAddress=macAddress;
    beacon.mBluetoothName=name;
    beacon.mManufacturer=manufacturer;
    beacon.mParserIdentifier=mIdentifier;
  }
  return beacon;
}