Program: 156035
Project: 156035
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);
  }
  if (channel != null) {
    String id=sentence.substring(0,12);
    String type=sentence.substring(12,16);
    if (type.equals("String_Node_Str")) {
      String content=sentence.substring(sentence.length() - 3);
      channel.write("String_Node_Str" + id + "String_Node_Str"+ content+ "String_Node_Str");
    }
 else     if (type.equals("String_Node_Str")) {
      channel.write("String_Node_Str" + id + "String_Node_Str");
    }
  }
  Position position=new Position();
  position.setProtocol(getProtocolName());
  Parser parser=new Parser(PATTERN_BATTERY,sentence);
  if (parser.matches()) {
    if (!identify(parser.next(),channel,remoteAddress)) {
      return null;
    }
    position.setDeviceId(getDeviceId());
    DateBuilder dateBuilder=new DateBuilder().setDateReverse(parser.nextInt(),parser.nextInt(),parser.nextInt()).setTime(parser.nextInt(),parser.nextInt(),parser.nextInt());
    getLastLocation(position,dateBuilder.getDate());
    int battery=parser.nextInt();
    if (battery != 65535) {
      position.set(Position.KEY_BATTERY,battery);
    }
    int power=parser.nextInt();
    if (power != 65535) {
      position.set(Position.KEY_POWER,battery);
    }
    return position;
  }
  parser=new Parser(PATTERN_NETWORK,sentence);
  if (parser.matches()) {
    if (!identify(parser.next(),channel,remoteAddress)) {
      return null;
    }
    position.setDeviceId(getDeviceId());
    getLastLocation(position,null);
    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));
    return position;
  }
  parser=new Parser(PATTERN,sentence);
  if (!parser.matches()) {
    return null;
  }
  if (!identify(parser.next(),channel,remoteAddress)) {
    return null;
  }
  position.setDeviceId(getDeviceId());
  int alarm=sentence.indexOf("String_Node_Str");
  if (alarm != -1) {
    position.set(Position.KEY_ALARM,Integer.parseInt(sentence.substring(alarm + 4,alarm + 5)));
  }
  DateBuilder dateBuilder=new DateBuilder();
  if (parser.next() == null) {
    dateBuilder.setDate(parser.nextInt(),parser.nextInt(),parser.nextInt());
  }
 else {
    dateBuilder.setDateReverse(parser.nextInt(),parser.nextInt(),parser.nextInt());
  }
  position.setValid(parser.next().equals("String_Node_Str"));
  position.setLatitude(parser.nextCoordinate());
  position.setLongitude(parser.nextCoordinate());
switch (Context.getConfig().getString(getProtocolName() + "String_Node_Str","String_Node_Str")) {
case "String_Node_Str":
    position.setSpeed(parser.nextDouble());
  break;
case "String_Node_Str":
position.setSpeed(UnitsConverter.knotsFromMph(parser.nextDouble()));
break;
default :
position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble()));
break;
}
dateBuilder.setTime(parser.nextInt(),parser.nextInt(),parser.nextInt());
position.setTime(dateBuilder.getDate());
position.setCourse(parser.nextDouble());
String status=parser.next();
if (status != null) {
position.set(Position.KEY_STATUS,status);
int value=Integer.parseInt(new StringBuilder(status).reverse().toString(),2);
position.set(Position.KEY_CHARGE,!BitUtil.check(value,0));
position.set(Position.KEY_IGNITION,BitUtil.check(value,1));
}
position.set(Position.KEY_STATUS,parser.next());
if (parser.hasNext()) {
position.set(Position.KEY_ODOMETER,parser.nextLong(16));
}
return position;
}

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);
  }
  if (channel != null) {
    String id=sentence.substring(0,12);
    String type=sentence.substring(12,16);
    if (type.equals("String_Node_Str")) {
      String content=sentence.substring(sentence.length() - 3);
      channel.write("String_Node_Str" + id + "String_Node_Str"+ content+ "String_Node_Str");
    }
 else     if (type.equals("String_Node_Str")) {
      channel.write("String_Node_Str" + id + "String_Node_Str");
    }
  }
  Position position=new Position();
  position.setProtocol(getProtocolName());
  Parser parser=new Parser(PATTERN_BATTERY,sentence);
  if (parser.matches()) {
    if (!identify(parser.next(),channel,remoteAddress)) {
      return null;
    }
    position.setDeviceId(getDeviceId());
    DateBuilder dateBuilder=new DateBuilder().setDateReverse(parser.nextInt(),parser.nextInt(),parser.nextInt()).setTime(parser.nextInt(),parser.nextInt(),parser.nextInt());
    getLastLocation(position,dateBuilder.getDate());
    int battery=parser.nextInt();
    if (battery != 65535) {
      position.set(Position.KEY_BATTERY,battery);
    }
    int power=parser.nextInt();
    if (power != 65535) {
      position.set(Position.KEY_POWER,power);
    }
    return position;
  }
  parser=new Parser(PATTERN_NETWORK,sentence);
  if (parser.matches()) {
    if (!identify(parser.next(),channel,remoteAddress)) {
      return null;
    }
    position.setDeviceId(getDeviceId());
    getLastLocation(position,null);
    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));
    return position;
  }
  parser=new Parser(PATTERN,sentence);
  if (!parser.matches()) {
    return null;
  }
  if (!identify(parser.next(),channel,remoteAddress)) {
    return null;
  }
  position.setDeviceId(getDeviceId());
  int alarm=sentence.indexOf("String_Node_Str");
  if (alarm != -1) {
    position.set(Position.KEY_ALARM,Integer.parseInt(sentence.substring(alarm + 4,alarm + 5)));
  }
  DateBuilder dateBuilder=new DateBuilder();
  if (parser.next() == null) {
    dateBuilder.setDate(parser.nextInt(),parser.nextInt(),parser.nextInt());
  }
 else {
    dateBuilder.setDateReverse(parser.nextInt(),parser.nextInt(),parser.nextInt());
  }
  position.setValid(parser.next().equals("String_Node_Str"));
  position.setLatitude(parser.nextCoordinate());
  position.setLongitude(parser.nextCoordinate());
switch (Context.getConfig().getString(getProtocolName() + "String_Node_Str","String_Node_Str")) {
case "String_Node_Str":
    position.setSpeed(parser.nextDouble());
  break;
case "String_Node_Str":
position.setSpeed(UnitsConverter.knotsFromMph(parser.nextDouble()));
break;
default :
position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble()));
break;
}
dateBuilder.setTime(parser.nextInt(),parser.nextInt(),parser.nextInt());
position.setTime(dateBuilder.getDate());
position.setCourse(parser.nextDouble());
String status=parser.next();
if (status != null) {
position.set(Position.KEY_STATUS,status);
int value=Integer.parseInt(new StringBuilder(status).reverse().toString(),2);
position.set(Position.KEY_CHARGE,!BitUtil.check(value,0));
position.set(Position.KEY_IGNITION,BitUtil.check(value,1));
}
position.set(Position.KEY_STATUS,parser.next());
if (parser.hasNext()) {
position.set(Position.KEY_ODOMETER,parser.nextLong(16));
}
return position;
}