Program: 156040
Project: 156040
Buggy source:
private Position decodeOld(Channel channel,SocketAddress remoteAddress,String sentence){
  boolean simple=sentence.charAt(3) == ',' || sentence.charAt(6) == ',';
  String id;
  String location;
  String status;
  if (simple) {
    int beginIndex=sentence.indexOf(',') + 1;
    int endIndex=sentence.indexOf(',',beginIndex);
    id=sentence.substring(beginIndex,endIndex);
    beginIndex=endIndex + 1;
    endIndex=sentence.indexOf('*',beginIndex);
    if (endIndex != -1) {
      endIndex+=3;
    }
 else {
      endIndex=sentence.length();
    }
    location=sentence.substring(beginIndex,endIndex);
    beginIndex=endIndex + 1;
    if (beginIndex > sentence.length()) {
      beginIndex=endIndex;
    }
    status=sentence.substring(beginIndex);
  }
 else {
    int beginIndex=3;
    int endIndex=beginIndex + 16;
    id=sentence.substring(beginIndex,endIndex).trim();
    beginIndex=endIndex + 2;
    endIndex=sentence.indexOf('*',beginIndex) + 3;
    location=sentence.substring(beginIndex,endIndex);
    beginIndex=endIndex + 1;
    status=sentence.substring(beginIndex);
  }
  Position position=new Position();
  position.setProtocol(getProtocolName());
  if (!parseLocation(location,position)) {
    return null;
  }
  if (simple) {
    Parser parser=new Parser(PATTERN_SIMPLE,status);
    if (parser.matches()) {
      position.set(Position.KEY_ALARM,parser.next());
      if (!identify(parser.next(),channel,remoteAddress,false) && !identify(id,channel,remoteAddress)) {
        return null;
      }
      position.setDeviceId(getDeviceId());
      position.set(Position.KEY_SATELLITES,parser.next());
      position.setAltitude(parser.nextDouble());
      position.set(Position.KEY_POWER,parser.nextDouble());
      String charger=parser.next();
      if (charger != null) {
        position.set(Position.KEY_CHARGE,Integer.parseInt(charger) == 1);
      }
      if (parser.hasNext(3)) {
        position.set(Position.KEY_MCC,parser.nextInt());
        position.set(Position.KEY_MNC,parser.nextInt());
        position.set(Position.KEY_LAC,parser.nextInt(16));
        position.set(Position.KEY_CID,parser.nextInt(16));
      }
    }
 else {
      if (!identify(id,channel,remoteAddress)) {
        return null;
      }
      position.setDeviceId(getDeviceId());
    }
  }
 else {
    Parser parser=new Parser(PATTERN_ALTERNATIVE,status);
    if (parser.matches()) {
      if (!identify(id,channel,remoteAddress)) {
        return null;
      }
      position.setDeviceId(getDeviceId());
      position.set(Position.KEY_MCC,parser.nextInt());
      position.set(Position.KEY_MNC,parser.nextInt());
      position.set(Position.KEY_LAC,parser.nextInt(16));
      position.set(Position.KEY_CID,parser.nextInt(16));
      position.set(Position.KEY_GSM,parser.next());
      position.set(Position.KEY_BATTERY,Double.parseDouble(parser.next()));
      position.set(Position.KEY_FLAGS,parser.next());
      position.set(Position.KEY_INPUT,parser.next());
      position.set(Position.KEY_OUTPUT,parser.next());
      position.set(Position.PREFIX_ADC + 1,parser.next());
      position.set(Position.PREFIX_ADC + 2,parser.next());
      position.set(Position.PREFIX_ADC + 3,parser.next());
      position.set(Position.KEY_ALARM,parser.next());
    }
  }
  return position;
}

Fixed version (ground truth):
private Position decodeOld(Channel channel,SocketAddress remoteAddress,String sentence){
  boolean simple=sentence.charAt(3) == ',' || sentence.charAt(6) == ',';
  String id;
  String location;
  String status;
  if (simple) {
    int beginIndex=sentence.indexOf(',') + 1;
    int endIndex=sentence.indexOf(',',beginIndex);
    id=sentence.substring(beginIndex,endIndex);
    beginIndex=endIndex + 1;
    endIndex=sentence.indexOf('*',beginIndex);
    if (endIndex != -1) {
      endIndex+=3;
    }
 else {
      endIndex=sentence.length();
    }
    location=sentence.substring(beginIndex,endIndex);
    beginIndex=endIndex + 1;
    if (beginIndex > sentence.length()) {
      beginIndex=endIndex;
    }
    status=sentence.substring(beginIndex);
  }
 else {
    int beginIndex=3;
    int endIndex=beginIndex + 16;
    id=sentence.substring(beginIndex,endIndex).trim();
    beginIndex=endIndex + 2;
    endIndex=sentence.indexOf('*',beginIndex) + 3;
    location=sentence.substring(beginIndex,endIndex);
    beginIndex=endIndex + 1;
    status=sentence.substring(beginIndex);
  }
  Position position=new Position();
  position.setProtocol(getProtocolName());
  if (!parseLocation(location,position)) {
    return null;
  }
  if (simple) {
    Parser parser=new Parser(PATTERN_SIMPLE,status);
    if (parser.matches()) {
      position.set(Position.KEY_ALARM,parser.next());
      if (!identify(parser.next(),channel,remoteAddress,false) && !identify(id,channel,remoteAddress)) {
        return null;
      }
      position.setDeviceId(getDeviceId());
      position.set(Position.KEY_SATELLITES,parser.next());
      position.setAltitude(parser.nextDouble());
      position.set(Position.KEY_POWER,parser.nextDouble());
      String charger=parser.next();
      if (charger != null) {
        position.set(Position.KEY_CHARGE,Integer.parseInt(charger) == 1);
      }
      if (parser.hasNext(4)) {
        position.set(Position.KEY_MCC,parser.nextInt());
        position.set(Position.KEY_MNC,parser.nextInt());
        position.set(Position.KEY_LAC,parser.nextInt(16));
        position.set(Position.KEY_CID,parser.nextInt(16));
      }
    }
 else {
      if (!identify(id,channel,remoteAddress)) {
        return null;
      }
      position.setDeviceId(getDeviceId());
    }
  }
 else {
    Parser parser=new Parser(PATTERN_ALTERNATIVE,status);
    if (parser.matches()) {
      if (!identify(id,channel,remoteAddress)) {
        return null;
      }
      position.setDeviceId(getDeviceId());
      position.set(Position.KEY_MCC,parser.nextInt());
      position.set(Position.KEY_MNC,parser.nextInt());
      position.set(Position.KEY_LAC,parser.nextInt(16));
      position.set(Position.KEY_CID,parser.nextInt(16));
      position.set(Position.KEY_GSM,parser.next());
      position.set(Position.KEY_BATTERY,Double.parseDouble(parser.next()));
      position.set(Position.KEY_FLAGS,parser.next());
      position.set(Position.KEY_INPUT,parser.next());
      position.set(Position.KEY_OUTPUT,parser.next());
      position.set(Position.PREFIX_ADC + 1,parser.next());
      position.set(Position.PREFIX_ADC + 2,parser.next());
      position.set(Position.PREFIX_ADC + 3,parser.next());
      position.set(Position.KEY_ALARM,parser.next());
    }
  }
  return position;
}