Program: 156108
Project: 156108
Buggy source:
@Override protected Object decode(Channel channel,SocketAddress remoteAddress,Object msg) throws Exception {
  ChannelBuffer buf=(ChannelBuffer)msg;
  buf.readUnsignedShort();
  int type=buf.readUnsignedShort();
  if (type == MSG_SHAKE_HAND && channel != null) {
    ChannelBuffer response=ChannelBuffers.dynamicBuffer(ByteOrder.LITTLE_ENDIAN,13);
    response.writeBytes(ChannelBuffers.copiedBuffer(ByteOrder.LITTLE_ENDIAN,"String_Node_Str",Charset.defaultCharset()));
    response.writeByte(0);
    response.writeShort(response.capacity());
    response.writeShort(MSG_SHAKE_HAND_RESPONSE);
    response.writeByte(1);
    response.writeBytes(ChannelBuffers.copiedBuffer(ByteOrder.LITTLE_ENDIAN,"String_Node_Str",Charset.defaultCharset()));
    channel.write(response,remoteAddress);
  }
 else   if (type == MSG_UPLOAD_POSITION || type == MSG_UPLOAD_POSITION_NEW || type == MSG_CONTROL_RESPONSE || type == MSG_ALARM) {
    boolean newFormat=false;
    if (type == MSG_UPLOAD_POSITION && buf.readableBytes() == 48 || type == MSG_ALARM && buf.readableBytes() == 48 || type == MSG_CONTROL_RESPONSE && buf.readableBytes() == 57 || type == MSG_UPLOAD_POSITION_NEW) {
      newFormat=true;
    }
    Position position=new Position();
    position.setProtocol(getProtocolName());
    if (type == MSG_CONTROL_RESPONSE) {
      buf.readUnsignedInt();
      buf.readUnsignedInt();
    }
    int flags=buf.readUnsignedByte();
    position.setValid((flags & 0x01) != 0);
    position.set(Event.KEY_ALARM,buf.readUnsignedByte());
    if (newFormat) {
      position.setSpeed(buf.readUnsignedInt());
      position.setCourse(buf.readFloat());
    }
 else {
      position.setSpeed(buf.readUnsignedByte());
      position.setCourse(buf.readUnsignedShort());
    }
    position.setLongitude(buf.readFloat());
    position.setLatitude(buf.readFloat());
    if (!newFormat) {
      long timeValue=buf.readUnsignedInt();
      Calendar time=Calendar.getInstance(TimeZone.getTimeZone("String_Node_Str"));
      time.clear();
      time.set(Calendar.YEAR,2000 + (int)(timeValue >> 26));
      time.set(Calendar.MONTH,(int)(timeValue >> 22 & 0x0f) - 1);
      time.set(Calendar.DAY_OF_MONTH,(int)(timeValue >> 17 & 0x1f));
      time.set(Calendar.HOUR_OF_DAY,(int)(timeValue >> 12 & 0x1f));
      time.set(Calendar.MINUTE,(int)(timeValue >> 6 & 0x3f));
      time.set(Calendar.SECOND,(int)(timeValue & 0x3f));
      position.setTime(time.getTime());
    }
    String id=buf.readBytes(newFormat ? 12 : 11).toString(Charset.defaultCharset()).replaceAll("String_Node_Str","String_Node_Str");
    if (!identify(id,channel,remoteAddress)) {
      return null;
    }
    position.setDeviceId(getDeviceId());
    if (newFormat) {
      DateFormat dateFormat=new SimpleDateFormat("String_Node_Str");
      position.setTime(dateFormat.parse(buf.readBytes(17).toString(Charset.defaultCharset())));
      buf.readByte();
    }
    if (!newFormat) {
      position.set(Event.PREFIX_IO + 1,buf.readUnsignedByte());
      position.set(Event.KEY_FUEL,buf.readUnsignedByte());
    }
 else     if (type == MSG_UPLOAD_POSITION_NEW) {
      position.set(Event.PREFIX_TEMP + 1,buf.readShort());
      position.set(Event.KEY_ODOMETER,buf.readFloat());
    }
    return position;
  }
  return null;
}

Fixed version (ground truth):
@Override protected Object decode(Channel channel,SocketAddress remoteAddress,Object msg) throws Exception {
  ChannelBuffer buf=(ChannelBuffer)msg;
  buf.readUnsignedShort();
  int type=buf.readUnsignedShort();
  if (type == MSG_SHAKE_HAND && channel != null) {
    ChannelBuffer response=ChannelBuffers.dynamicBuffer(ByteOrder.LITTLE_ENDIAN,13);
    response.writeBytes(ChannelBuffers.copiedBuffer(ByteOrder.LITTLE_ENDIAN,"String_Node_Str",Charset.defaultCharset()));
    response.writeByte(0);
    response.writeShort(response.capacity());
    response.writeShort(MSG_SHAKE_HAND_RESPONSE);
    response.writeByte(1);
    response.writeBytes(ChannelBuffers.copiedBuffer(ByteOrder.LITTLE_ENDIAN,"String_Node_Str",Charset.defaultCharset()));
    channel.write(response,remoteAddress);
  }
 else   if (type == MSG_UPLOAD_POSITION || type == MSG_UPLOAD_POSITION_NEW || type == MSG_CONTROL_RESPONSE || type == MSG_ALARM) {
    boolean newFormat=false;
    if (type == MSG_UPLOAD_POSITION && buf.readableBytes() == 48 || type == MSG_ALARM && buf.readableBytes() == 48 || type == MSG_CONTROL_RESPONSE && buf.readableBytes() == 57 || type == MSG_UPLOAD_POSITION_NEW) {
      newFormat=true;
    }
    Position position=new Position();
    position.setProtocol(getProtocolName());
    if (type == MSG_CONTROL_RESPONSE) {
      buf.readUnsignedInt();
      buf.readUnsignedInt();
    }
    int flags=buf.readUnsignedByte();
    position.setValid((flags & 0x01) != 0);
    position.set(Event.KEY_ALARM,buf.readUnsignedByte());
    if (newFormat) {
      position.setSpeed(buf.readUnsignedInt());
      position.setCourse(buf.readFloat());
    }
 else {
      position.setSpeed(buf.readUnsignedByte());
      position.setCourse(buf.readUnsignedShort());
    }
    position.setLongitude(buf.readFloat());
    position.setLatitude(buf.readFloat());
    if (!newFormat) {
      long timeValue=buf.readUnsignedInt();
      Calendar time=Calendar.getInstance(TimeZone.getTimeZone("String_Node_Str"));
      time.clear();
      time.set(Calendar.YEAR,2000 + (int)(timeValue >> 26));
      time.set(Calendar.MONTH,(int)(timeValue >> 22 & 0x0f) - 1);
      time.set(Calendar.DAY_OF_MONTH,(int)(timeValue >> 17 & 0x1f));
      time.set(Calendar.HOUR_OF_DAY,(int)(timeValue >> 12 & 0x1f));
      time.set(Calendar.MINUTE,(int)(timeValue >> 6 & 0x3f));
      time.set(Calendar.SECOND,(int)(timeValue & 0x3f));
      position.setTime(time.getTime());
    }
    ChannelBuffer rawId;
    if (newFormat) {
      rawId=buf.readBytes(12);
    }
 else {
      rawId=buf.readBytes(11);
    }
    String id=rawId.toString(Charset.defaultCharset()).replaceAll("String_Node_Str","String_Node_Str");
    if (!identify(id,channel,remoteAddress)) {
      return null;
    }
    position.setDeviceId(getDeviceId());
    if (newFormat) {
      DateFormat dateFormat=new SimpleDateFormat("String_Node_Str");
      position.setTime(dateFormat.parse(buf.readBytes(17).toString(Charset.defaultCharset())));
      buf.readByte();
    }
    if (!newFormat) {
      position.set(Event.PREFIX_IO + 1,buf.readUnsignedByte());
      position.set(Event.KEY_FUEL,buf.readUnsignedByte());
    }
 else     if (type == MSG_UPLOAD_POSITION_NEW) {
      position.set(Event.PREFIX_TEMP + 1,buf.readShort());
      position.set(Event.KEY_ODOMETER,buf.readFloat());
    }
    return position;
  }
  return null;
}