Program: 155950
Project: 155950
Buggy source:
@Override protected Object decode(Channel channel,SocketAddress remoteAddress,Object msg) throws Exception {
  String sentence=(String)msg;
  int beginIndex=sentence.indexOf('>');
  if (beginIndex != -1) {
    sentence=sentence.substring(beginIndex + 1);
  }
  Parser parser=new Parser(PATTERN,sentence);
  if (!parser.matches()) {
    return null;
  }
  Position position=new Position(getProtocolName());
  Boolean valid=null;
  Integer event=null;
  if (parser.hasNext(3)) {
    event=parser.nextInt();
    position.setTime(getTime(parser.nextInt(0),parser.nextInt(0),parser.nextInt(0)));
  }
 else   if (parser.hasNext()) {
    position.setTime(getTime(parser.nextInt(0)));
  }
  if (parser.hasNext()) {
    event=parser.nextInt();
  }
  if (parser.hasNext(6)) {
    position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY_HMS));
  }
  if (parser.hasNext(4)) {
    position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_DEG));
    position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_DEG));
  }
  if (parser.hasNext(6)) {
    position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG_MIN));
    position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG_MIN));
  }
  position.setSpeed(UnitsConverter.knotsFromMph(parser.nextDouble(0)));
  position.setCourse(parser.nextDouble(0));
  if (parser.hasNext(4)) {
    valid=parser.nextInt() > 0;
    int input=parser.nextHexInt();
    position.set(Position.KEY_IGNITION,BitUtil.check(input,7));
    position.set(Position.KEY_INPUT,input);
    event=parser.nextInt();
    position.set(Position.KEY_HDOP,parser.nextInt());
  }
  if (parser.hasNext(4)) {
    position.set(Position.KEY_INPUT,parser.nextHexInt(0));
    position.set(Position.KEY_SATELLITES,parser.nextHexInt(0));
    position.set(Position.KEY_BATTERY,parser.nextInt(0));
    position.set(Position.KEY_ODOMETER,parser.nextLong(16,0));
  }
  if (parser.hasNext(4)) {
    valid=parser.nextInt() > 0;
    position.set(Position.KEY_PDOP,parser.nextInt());
    position.set(Position.KEY_RSSI,parser.nextInt());
    position.set(Position.PREFIX_TEMP + 1,parser.nextInt() * 0.01);
    position.set(Position.PREFIX_TEMP + 2,parser.nextInt() * 0.01);
  }
  position.setValid(valid != null ? valid : true);
  if (event != null) {
    position.set(Position.KEY_EVENT,event);
switch (event) {
case 22:
      position.set(Position.KEY_ALARM,Position.ALARM_ACCELERATION);
    break;
case 23:
  position.set(Position.KEY_ALARM,Position.ALARM_BRAKING);
break;
case 24:
position.set(Position.KEY_ALARM,Position.ALARM_ACCIDENT);
break;
case 26:
case 28:
position.set(Position.KEY_ALARM,Position.ALARM_CORNERING);
break;
default :
break;
}
}
String[] attributes=null;
beginIndex=sentence.indexOf(';');
if (beginIndex != -1) {
int endIndex=sentence.indexOf('<',beginIndex);
if (endIndex == -1) {
endIndex=sentence.length();
}
attributes=sentence.substring(beginIndex,endIndex).split("String_Node_Str");
}
return decodeAttributes(channel,remoteAddress,position,attributes);
}

Fixed version (ground truth):
@Override protected Object decode(Channel channel,SocketAddress remoteAddress,Object msg) throws Exception {
  String sentence=(String)msg;
  int beginIndex=sentence.indexOf('>');
  if (beginIndex != -1) {
    sentence=sentence.substring(beginIndex + 1);
  }
  Parser parser=new Parser(PATTERN,sentence);
  if (!parser.matches()) {
    return null;
  }
  Position position=new Position(getProtocolName());
  Boolean valid=null;
  Integer event=null;
  if (parser.hasNext(3)) {
    event=parser.nextInt();
    position.setTime(getTime(parser.nextInt(0),parser.nextInt(0),parser.nextInt(0)));
  }
 else   if (parser.hasNext()) {
    position.setTime(getTime(parser.nextInt(0)));
  }
  if (parser.hasNext()) {
    event=parser.nextInt();
  }
  if (parser.hasNext(6)) {
    position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY_HMS));
  }
  if (parser.hasNext(4)) {
    position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_DEG));
    position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_DEG));
  }
  if (parser.hasNext(6)) {
    position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG_MIN));
    position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG_MIN));
  }
  position.setSpeed(UnitsConverter.knotsFromMph(parser.nextDouble(0)));
  position.setCourse(parser.nextDouble(0));
  if (parser.hasNext(4)) {
    valid=parser.nextInt() > 0;
    int input=parser.nextHexInt();
    position.set(Position.KEY_IGNITION,BitUtil.check(input,7));
    position.set(Position.KEY_INPUT,input);
    event=parser.nextInt();
    position.set(Position.KEY_HDOP,parser.nextInt());
  }
  if (parser.hasNext(4)) {
    position.set(Position.KEY_INPUT,parser.nextHexInt(0));
    position.set(Position.KEY_SATELLITES,parser.nextHexInt(0));
    position.set(Position.KEY_BATTERY,parser.nextInt(0));
    position.set(Position.KEY_ODOMETER,parser.nextLong(16,0));
  }
  if (parser.hasNext(4)) {
    valid=parser.nextInt() > 0;
    position.set(Position.KEY_PDOP,parser.nextInt());
    position.set(Position.KEY_RSSI,parser.nextInt());
    position.set(Position.PREFIX_TEMP + 1,parser.nextInt() * 0.01);
    position.set(Position.PREFIX_TEMP + 2,parser.nextInt() * 0.01);
  }
  position.setValid(valid == null || valid);
  if (event != null) {
    position.set(Position.KEY_EVENT,event);
switch (event) {
case 22:
      position.set(Position.KEY_ALARM,Position.ALARM_ACCELERATION);
    break;
case 23:
  position.set(Position.KEY_ALARM,Position.ALARM_BRAKING);
break;
case 24:
position.set(Position.KEY_ALARM,Position.ALARM_ACCIDENT);
break;
case 26:
case 28:
position.set(Position.KEY_ALARM,Position.ALARM_CORNERING);
break;
default :
break;
}
}
String[] attributes=null;
beginIndex=sentence.indexOf(';');
if (beginIndex != -1) {
int endIndex=sentence.indexOf('<',beginIndex);
if (endIndex == -1) {
endIndex=sentence.length();
}
attributes=sentence.substring(beginIndex,endIndex).split("String_Node_Str");
}
return decodeAttributes(channel,remoteAddress,position,attributes);
}