Program: 162698
Project: 162698
Buggy source:
/** 
 * <p>Defines a beacon field parsing algorithm based on a string designating the zero-indexed offsets to bytes within a BLE advertisement.</p> <p>If you want to see examples of how other folks have set up BeaconParsers for different kinds of beacons, try doing a Google search for "getBeaconParsers" (include the quotes in the search.)</p> <p>Four prefixes are allowed in the string:</p> <pre> m - matching byte sequence for this beacon type to parse (one allowed) i - identifier (multiple allowed) p - power calibration field (one allowed) d - data field (multiple allowed) </pre> <p>Each prefix is followed by a colon, then an inclusive decimal byte offset for the field from the beginning of the advertisement.  In the case of the m prefix, an = sign follows the byte offset, followed by a big endian hex representation of the bytes that must be matched for this beacon type.  When multiple i or d entries exist in the string, they will be added in order of definition to the identifier or data array for the beacon when parsing the beacon advertisement.  Terms are separated by commas.</p> <p>All offsets from the start of the advertisement are relative to the first byte of the two byte manufacturer code.  The manufacturer code is therefore always at position 0-1</p> <p>If the expression cannot be parsed, a <code>BeaconLayoutException</code> is thrown.</p> <p>Example of a parser string for AltBeacon:</p> </pre> "m:2-3:beac,i:4-19,i:20-21,i:22-23,p:24-24,d:25-25" </pre> <p>This signifies that the beacon type will be decoded when an advertisement is found with 0xbeac in bytes 2-3, and a three-part identifier will be pulled out of bytes 4-19, bytes 20-21 and bytes 22-23, respectively.  A signed power calibration value will be pulled out of byte 24, and a data field will be pulled out of byte 25.</p> Note: bytes 0-1 of the BLE manufacturer advertisements are the two byte manufacturer code. Generally you should not match on these two bytes when using a BeaconParser, because it will limit your parser to matching only a transmitter made by a specific manufacturer.  Software and operating systems that scan for beacons typically ignore these two bytes, allowing beacon manufacturers to use their own company code assigned by Bluetooth SIG.  The default parser implementation will already pull out this company code and store it in the beacon.mManufacturer field.  Matcher expressions should therefore start with "m2-3:" followed by the multi-byte hex value that signifies the beacon type.
 * @param beaconLayout
 * @return the BeaconParser instance
 */
public BeaconParser setBeaconLayout(String beaconLayout){
  String[] terms=beaconLayout.split("String_Node_Str");
  for (  String term : terms) {
    boolean found=false;
    Matcher matcher=I_PATTERN.matcher(term);
    while (matcher.find()) {
      found=true;
      try {
        int startOffset=Integer.parseInt(matcher.group(1));
        int endOffset=Integer.parseInt(matcher.group(2));
        Boolean littleEndian=matcher.group(3).equals("String_Node_Str");
        mIdentifierLittleEndianFlags.add(littleEndian);
        mIdentifierStartOffsets.add(startOffset);
        mIdentifierEndOffsets.add(endOffset);
      }
 catch (      NumberFormatException e) {
        throw new BeaconLayoutException("String_Node_Str" + term);
      }
    }
    matcher=D_PATTERN.matcher(term);
    while (matcher.find()) {
      found=true;
      try {
        int startOffset=Integer.parseInt(matcher.group(1));
        int endOffset=Integer.parseInt(matcher.group(2));
        Boolean littleEndian=matcher.group(3).equals("String_Node_Str");
        mDataLittleEndianFlags.add(littleEndian);
        mDataStartOffsets.add(startOffset);
        mDataEndOffsets.add(endOffset);
      }
 catch (      NumberFormatException e) {
        throw new BeaconLayoutException("String_Node_Str" + term);
      }
    }
    matcher=P_PATTERN.matcher(term);
    while (matcher.find()) {
      found=true;
      try {
        int startOffset=Integer.parseInt(matcher.group(1));
        int endOffset=Integer.parseInt(matcher.group(2));
        mPowerStartOffset=startOffset;
        mPowerEndOffset=endOffset;
      }
 catch (      NumberFormatException e) {
        throw new BeaconLayoutException("String_Node_Str" + term);
      }
    }
    matcher=M_PATTERN.matcher(term);
    while (matcher.find()) {
      found=true;
      try {
        int startOffset=Integer.parseInt(matcher.group(1));
        int endOffset=Integer.parseInt(matcher.group(2));
        mMatchingBeaconTypeCodeStartOffset=startOffset;
        mMatchingBeaconTypeCodeEndOffset=endOffset;
      }
 catch (      NumberFormatException e) {
        throw new BeaconLayoutException("String_Node_Str" + term);
      }
      String hexString=matcher.group(3);
      try {
        mMatchingBeaconTypeCode=Long.decode("String_Node_Str" + hexString);
      }
 catch (      NumberFormatException e) {
        throw new BeaconLayoutException("String_Node_Str" + hexString + "String_Node_Str"+ term);
      }
    }
    if (!found) {
      BeaconManager.logDebug(TAG,"String_Node_Str" + term);
      throw new BeaconLayoutException("String_Node_Str" + term);
    }
  }
  if (mPowerStartOffset == null || mPowerEndOffset == null) {
    throw new BeaconLayoutException("String_Node_Str");
  }
  if (mMatchingBeaconTypeCodeStartOffset == null || mMatchingBeaconTypeCodeEndOffset == null) {
    throw new BeaconLayoutException("String_Node_Str");
  }
  if (mIdentifierStartOffsets.size() == 0 || mIdentifierEndOffsets.size() == 0) {
    throw new BeaconLayoutException("String_Node_Str");
  }
  return this;
}

Fixed version (ground truth):
/** 
 * <p>Defines a beacon field parsing algorithm based on a string designating the zero-indexed offsets to bytes within a BLE advertisement.</p> <p>If you want to see examples of how other folks have set up BeaconParsers for different kinds of beacons, try doing a Google search for "getBeaconParsers" (include the quotes in the search.)</p> <p>Four prefixes are allowed in the string:</p> <pre> m - matching byte sequence for this beacon type to parse (exactly one required) i - identifier (at least one required, multiple allowed) p - power calibration field (exactly one required) d - data field (optional, multiple allowed) </pre> <p>Each prefix is followed by a colon, then an inclusive decimal byte offset for the field from the beginning of the advertisement.  In the case of the m prefix, an = sign follows the byte offset, followed by a big endian hex representation of the bytes that must be matched for this beacon type.  When multiple i or d entries exist in the string, they will be added in order of definition to the identifier or data array for the beacon when parsing the beacon advertisement.  Terms are separated by commas.</p> <p>All offsets from the start of the advertisement are relative to the first byte of the two byte manufacturer code.  The manufacturer code is therefore always at position 0-1</p> <p>All data field and identifier expressions may be optionally suffixed with the letter l, which indicates the field should be parsed as little endian.  If not present, the field will be presumed to be big endian. <p>If the expression cannot be parsed, a <code>BeaconLayoutException</code> is thrown.</p> <p>Example of a parser string for AltBeacon:</p> </pre> "m:2-3=beac,i:4-19,i:20-21,i:22-23,p:24-24,d:25-25" </pre> <p>This signifies that the beacon type will be decoded when an advertisement is found with 0xbeac in bytes 2-3, and a three-part identifier will be pulled out of bytes 4-19, bytes 20-21 and bytes 22-23, respectively.  A signed power calibration value will be pulled out of byte 24, and a data field will be pulled out of byte 25.</p> Note: bytes 0-1 of the BLE manufacturer advertisements are the two byte manufacturer code. Generally you should not match on these two bytes when using a BeaconParser, because it will limit your parser to matching only a transmitter made by a specific manufacturer.  Software and operating systems that scan for beacons typically ignore these two bytes, allowing beacon manufacturers to use their own company code assigned by Bluetooth SIG.  The default parser implementation will already pull out this company code and store it in the beacon.mManufacturer field.  Matcher expressions should therefore start with "m2-3:" followed by the multi-byte hex value that signifies the beacon type.
 * @param beaconLayout
 * @return the BeaconParser instance
 */
public BeaconParser setBeaconLayout(String beaconLayout){
  String[] terms=beaconLayout.split("String_Node_Str");
  for (  String term : terms) {
    boolean found=false;
    Matcher matcher=I_PATTERN.matcher(term);
    while (matcher.find()) {
      found=true;
      try {
        int startOffset=Integer.parseInt(matcher.group(1));
        int endOffset=Integer.parseInt(matcher.group(2));
        Boolean littleEndian=matcher.group(3).equals("String_Node_Str");
        mIdentifierLittleEndianFlags.add(littleEndian);
        mIdentifierStartOffsets.add(startOffset);
        mIdentifierEndOffsets.add(endOffset);
      }
 catch (      NumberFormatException e) {
        throw new BeaconLayoutException("String_Node_Str" + term);
      }
    }
    matcher=D_PATTERN.matcher(term);
    while (matcher.find()) {
      found=true;
      try {
        int startOffset=Integer.parseInt(matcher.group(1));
        int endOffset=Integer.parseInt(matcher.group(2));
        Boolean littleEndian=matcher.group(3).equals("String_Node_Str");
        mDataLittleEndianFlags.add(littleEndian);
        mDataStartOffsets.add(startOffset);
        mDataEndOffsets.add(endOffset);
      }
 catch (      NumberFormatException e) {
        throw new BeaconLayoutException("String_Node_Str" + term);
      }
    }
    matcher=P_PATTERN.matcher(term);
    while (matcher.find()) {
      found=true;
      try {
        int startOffset=Integer.parseInt(matcher.group(1));
        int endOffset=Integer.parseInt(matcher.group(2));
        mPowerStartOffset=startOffset;
        mPowerEndOffset=endOffset;
      }
 catch (      NumberFormatException e) {
        throw new BeaconLayoutException("String_Node_Str" + term);
      }
    }
    matcher=M_PATTERN.matcher(term);
    while (matcher.find()) {
      found=true;
      try {
        int startOffset=Integer.parseInt(matcher.group(1));
        int endOffset=Integer.parseInt(matcher.group(2));
        mMatchingBeaconTypeCodeStartOffset=startOffset;
        mMatchingBeaconTypeCodeEndOffset=endOffset;
      }
 catch (      NumberFormatException e) {
        throw new BeaconLayoutException("String_Node_Str" + term);
      }
      String hexString=matcher.group(3);
      try {
        mMatchingBeaconTypeCode=Long.decode("String_Node_Str" + hexString);
      }
 catch (      NumberFormatException e) {
        throw new BeaconLayoutException("String_Node_Str" + hexString + "String_Node_Str"+ term);
      }
    }
    if (!found) {
      BeaconManager.logDebug(TAG,"String_Node_Str" + term);
      throw new BeaconLayoutException("String_Node_Str" + term);
    }
  }
  if (mPowerStartOffset == null || mPowerEndOffset == null) {
    throw new BeaconLayoutException("String_Node_Str");
  }
  if (mMatchingBeaconTypeCodeStartOffset == null || mMatchingBeaconTypeCodeEndOffset == null) {
    throw new BeaconLayoutException("String_Node_Str");
  }
  if (mIdentifierStartOffsets.size() == 0 || mIdentifierEndOffsets.size() == 0) {
    throw new BeaconLayoutException("String_Node_Str");
  }
  return this;
}