Program: 156072
Project: 156072
Buggy source:
@Override protected Object decode(Channel channel,SocketAddress remoteAddress,Object msg) throws Exception {
  ChannelBuffer buf=(ChannelBuffer)msg;
  int header=buf.readUnsignedShort();
  buf.readUnsignedShort();
  int version=-1;
  if (header == 0x4040) {
    version=buf.readUnsignedByte();
  }
  ChannelBuffer id=buf.readBytes(20);
  int type=ChannelBuffers.swapShort(buf.readShort());
  if (!identify(id.toString(Charset.defaultCharset()).trim(),channel,remoteAddress)) {
    return null;
  }
  if (version == -1) {
    if (type == 0x2001) {
      if (channel != null) {
        int length=2 + 2 + id.readableBytes()+ 2+ 4+ 8+ 2+ 2;
        ChannelBuffer response=ChannelBuffers.directBuffer(ByteOrder.LITTLE_ENDIAN,length);
        response.writeByte('@');
        response.writeByte('@');
        response.writeShort(length);
        response.writeBytes(id);
        response.writeShort(ChannelBuffers.swapShort((short)0x1001));
        response.writeInt(0);
        for (int i=0; i < 8; i++) {
          response.writeByte(0xff);
        }
        response.writeShort(Checksum.crc16(Checksum.CRC16_X25,response.toByteBuffer(0,response.writerIndex())));
        response.writeByte(0x0D);
        response.writeByte(0x0A);
        channel.write(response,remoteAddress);
      }
      buf.readUnsignedInt();
      buf.readUnsignedInt();
      buf.readUnsignedByte();
      return readPosition(buf);
    }
  }
 else   if (version == 4) {
    if (type == MSG_SC_HEARTBEAT) {
      sendResponse(channel,remoteAddress,version,id,MSG_SC_HEARTBEAT_RESPONSE,null);
    }
 else     if (type == MSG_SC_LOGIN || type == MSG_SC_LOGOUT || type == MSG_SC_GPS || type == MSG_SC_ALARM || type == MSG_SC_CURRENT_LOCATION) {
      if (type == MSG_SC_LOGIN) {
        ChannelBuffer response=ChannelBuffers.directBuffer(ByteOrder.LITTLE_ENDIAN,10);
        response.writeInt(0xFFFFFFFF);
        response.writeShort(0);
        response.writeInt((int)(System.currentTimeMillis() / 1000));
        sendResponse(channel,remoteAddress,version,id,MSG_SC_LOGIN_RESPONSE,response);
      }
      if (type == MSG_SC_GPS) {
        buf.readUnsignedByte();
      }
 else       if (type == MSG_SC_ALARM) {
        buf.readUnsignedInt();
      }
 else       if (type == MSG_SC_CURRENT_LOCATION) {
        buf.readUnsignedShort();
      }
      buf.readUnsignedInt();
      buf.readUnsignedInt();
      long odometer=buf.readUnsignedInt();
      buf.readUnsignedInt();
      buf.readUnsignedInt();
      buf.readUnsignedShort();
      long status=buf.readUnsignedInt();
      buf.skipBytes(8);
      int count=buf.readUnsignedByte();
      List<Position> positions=new LinkedList<>();
      for (int i=0; i < count; i++) {
        Position position=readPosition(buf);
        position.set(Event.KEY_ODOMETER,odometer);
        position.set(Event.KEY_STATUS,status);
        positions.add(position);
      }
      if (!positions.isEmpty()) {
        return positions;
      }
    }
 else     if (type == MSG_SC_GPS_SLEEP || type == MSG_SC_AGPS_REQUEST) {
      return readPosition(buf);
    }
  }
 else {
    if (type == MSG_CC_HEARTBEAT) {
      sendResponse(channel,remoteAddress,version,id,MSG_CC_HEARTBEAT_RESPONSE,null);
      buf.readUnsignedByte();
      int count=buf.readUnsignedByte();
      List<Position> positions=new LinkedList<>();
      for (int i=0; i < count; i++) {
        Position position=readPosition(buf);
        position.set(Event.KEY_STATUS,buf.readUnsignedInt());
        position.set(Event.KEY_BATTERY,buf.readUnsignedByte());
        position.set(Event.KEY_ODOMETER,buf.readUnsignedInt());
        buf.readUnsignedByte();
        buf.readUnsignedByte();
        buf.readUnsignedByte();
        position.set(Event.KEY_LAC,buf.readUnsignedShort());
        position.set(Event.KEY_CID,buf.readUnsignedShort());
        positions.add(position);
      }
      return positions;
    }
 else     if (type == MSG_CC_LOGIN) {
      sendResponse(channel,remoteAddress,version,id,MSG_CC_LOGIN_RESPONSE,null);
      Position position=readPosition(buf);
      position.set(Event.KEY_STATUS,buf.readUnsignedInt());
      position.set(Event.KEY_BATTERY,buf.readUnsignedByte());
      position.set(Event.KEY_ODOMETER,buf.readUnsignedInt());
      buf.readUnsignedByte();
      buf.readUnsignedByte();
      buf.readUnsignedByte();
      return position;
    }
  }
  return null;
}

Fixed version (ground truth):
@Override protected Object decode(Channel channel,SocketAddress remoteAddress,Object msg) throws Exception {
  ChannelBuffer buf=(ChannelBuffer)msg;
  int header=buf.readUnsignedShort();
  buf.readUnsignedShort();
  int version=-1;
  if (header == 0x4040) {
    version=buf.readUnsignedByte();
  }
  ChannelBuffer id=buf.readBytes(20);
  int type=ChannelBuffers.swapShort(buf.readShort());
  if (!identify(id.toString(Charset.defaultCharset()).trim(),channel,remoteAddress)) {
    return null;
  }
  if (version == -1) {
    if (type == 0x2001) {
      sendResponse(channel,remoteAddress,id,(short)0x1001);
      buf.readUnsignedInt();
      buf.readUnsignedInt();
      buf.readUnsignedByte();
      return readPosition(buf);
    }
  }
 else   if (version == 4) {
    if (type == MSG_SC_HEARTBEAT) {
      sendResponse(channel,remoteAddress,version,id,MSG_SC_HEARTBEAT_RESPONSE,null);
    }
 else     if (type == MSG_SC_LOGIN || type == MSG_SC_LOGOUT || type == MSG_SC_GPS || type == MSG_SC_ALARM || type == MSG_SC_CURRENT_LOCATION) {
      if (type == MSG_SC_LOGIN) {
        ChannelBuffer response=ChannelBuffers.directBuffer(ByteOrder.LITTLE_ENDIAN,10);
        response.writeInt(0xFFFFFFFF);
        response.writeShort(0);
        response.writeInt((int)(System.currentTimeMillis() / 1000));
        sendResponse(channel,remoteAddress,version,id,MSG_SC_LOGIN_RESPONSE,response);
      }
      if (type == MSG_SC_GPS) {
        buf.readUnsignedByte();
      }
 else       if (type == MSG_SC_ALARM) {
        buf.readUnsignedInt();
      }
 else       if (type == MSG_SC_CURRENT_LOCATION) {
        buf.readUnsignedShort();
      }
      buf.readUnsignedInt();
      buf.readUnsignedInt();
      long odometer=buf.readUnsignedInt();
      buf.readUnsignedInt();
      buf.readUnsignedInt();
      buf.readUnsignedShort();
      long status=buf.readUnsignedInt();
      buf.skipBytes(8);
      int count=buf.readUnsignedByte();
      List<Position> positions=new LinkedList<>();
      for (int i=0; i < count; i++) {
        Position position=readPosition(buf);
        position.set(Event.KEY_ODOMETER,odometer);
        position.set(Event.KEY_STATUS,status);
        positions.add(position);
      }
      if (!positions.isEmpty()) {
        return positions;
      }
    }
 else     if (type == MSG_SC_GPS_SLEEP || type == MSG_SC_AGPS_REQUEST) {
      return readPosition(buf);
    }
  }
 else {
    if (type == MSG_CC_HEARTBEAT) {
      sendResponse(channel,remoteAddress,version,id,MSG_CC_HEARTBEAT_RESPONSE,null);
      buf.readUnsignedByte();
      int count=buf.readUnsignedByte();
      List<Position> positions=new LinkedList<>();
      for (int i=0; i < count; i++) {
        Position position=readPosition(buf);
        position.set(Event.KEY_STATUS,buf.readUnsignedInt());
        position.set(Event.KEY_BATTERY,buf.readUnsignedByte());
        position.set(Event.KEY_ODOMETER,buf.readUnsignedInt());
        buf.readUnsignedByte();
        buf.readUnsignedByte();
        buf.readUnsignedByte();
        position.set(Event.KEY_LAC,buf.readUnsignedShort());
        position.set(Event.KEY_CID,buf.readUnsignedShort());
        positions.add(position);
      }
      return positions;
    }
 else     if (type == MSG_CC_LOGIN) {
      sendResponse(channel,remoteAddress,version,id,MSG_CC_LOGIN_RESPONSE,null);
      Position position=readPosition(buf);
      position.set(Event.KEY_STATUS,buf.readUnsignedInt());
      position.set(Event.KEY_BATTERY,buf.readUnsignedByte());
      position.set(Event.KEY_ODOMETER,buf.readUnsignedInt());
      buf.readUnsignedByte();
      buf.readUnsignedByte();
      buf.readUnsignedByte();
      return position;
    }
  }
  return null;
}