Program: 156033
Project: 156033
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());
  DeviceSession deviceSession=getDeviceSession(channel,remoteAddress,id.toString(StandardCharsets.US_ASCII).trim());
  if (deviceSession == null) {
    return null;
  }
  if (version == -1) {
    if (type == 0x2001) {
      sendResponse(channel,remoteAddress,id,(short)0x1001);
      buf.readUnsignedInt();
      buf.readUnsignedInt();
      buf.readUnsignedByte();
      return readPosition(deviceSession,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(deviceSession,buf);
        position.set(Position.KEY_ODOMETER,odometer);
        position.set(Position.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(deviceSession,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(deviceSession,buf);
        position.set(Position.KEY_STATUS,buf.readUnsignedInt());
        position.set(Position.KEY_BATTERY,buf.readUnsignedByte());
        position.set(Position.KEY_ODOMETER,buf.readUnsignedInt());
        buf.readUnsignedByte();
        buf.readUnsignedByte();
        buf.readUnsignedByte();
        position.set(Position.KEY_LAC,buf.readUnsignedShort());
        position.set(Position.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(deviceSession,buf);
      position.set(Position.KEY_STATUS,buf.readUnsignedInt());
      position.set(Position.KEY_BATTERY,buf.readUnsignedByte());
      position.set(Position.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());
  DeviceSession deviceSession=getDeviceSession(channel,remoteAddress,id.toString(StandardCharsets.US_ASCII).trim());
  if (deviceSession == null) {
    return null;
  }
  if (version == -1) {
    if (type == 0x2001) {
      sendResponse(channel,remoteAddress,id,(short)0x1001);
      buf.readUnsignedInt();
      buf.readUnsignedInt();
      buf.readUnsignedByte();
      return readPosition(deviceSession,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(deviceSession,buf);
        position.set(Position.KEY_ODOMETER,odometer);
        position.set(Position.KEY_STATUS,status);
        positions.add(position);
      }
      if (!positions.isEmpty()) {
        return positions;
      }
    }
 else     if (type == MSG_SC_GPS_SLEEP) {
      buf.readUnsignedInt();
      return readPosition(deviceSession,buf);
    }
 else     if (type == MSG_SC_AGPS_REQUEST) {
      return readPosition(deviceSession,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(deviceSession,buf);
        position.set(Position.KEY_STATUS,buf.readUnsignedInt());
        position.set(Position.KEY_BATTERY,buf.readUnsignedByte());
        position.set(Position.KEY_ODOMETER,buf.readUnsignedInt());
        buf.readUnsignedByte();
        buf.readUnsignedByte();
        buf.readUnsignedByte();
        position.set(Position.KEY_LAC,buf.readUnsignedShort());
        position.set(Position.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(deviceSession,buf);
      position.set(Position.KEY_STATUS,buf.readUnsignedInt());
      position.set(Position.KEY_BATTERY,buf.readUnsignedByte());
      position.set(Position.KEY_ODOMETER,buf.readUnsignedInt());
      buf.readUnsignedByte();
      buf.readUnsignedByte();
      buf.readUnsignedByte();
      return position;
    }
  }
  return null;
}