Program: 156095
Project: 156095
Buggy source:
@Override protected Object decode(Channel channel,SocketAddress remoteAddress,Object msg) throws Exception {
  ChannelBuffer buf=(ChannelBuffer)msg;
  int type=buf.getUnsignedByte(0);
  if (type == MSG_LOGIN) {
    byte[] bytes=new byte[19];
    buf.readBytes(bytes);
    String imei=ChannelBufferTools.readHexString(ChannelBuffers.wrappedBuffer(bytes,1,16),16).substring(1);
    if (!identify(imei,channel)) {
      return null;
    }
    if (channel != null) {
      byte[] response="String_Node_Str".getBytes("String_Node_Str");
      response=Arrays.copyOf(response,response.length + 1);
      response[response.length - 1]=crc(bytes,0,18);
      channel.write(ChannelBuffers.wrappedBuffer(response));
    }
  }
 else   if (type == MSG_LOCATION) {
    buf.readUnsignedByte();
    Position position=new Position();
    position.setProtocol(getProtocolName());
    position.setDeviceId(getDeviceId());
    short status=buf.readUnsignedByte();
    position.set(Event.KEY_ALARM,(status & 0x80) != 0);
    position.set(Event.KEY_BATTERY,status & 0x7F);
    buf.skipBytes(2);
    position.set(Event.PREFIX_TEMP + 1,buf.readByte());
    buf.skipBytes(2);
    buf.readByte();
    buf.readByte();
    buf.skipBytes(6);
    int valid=buf.readUnsignedByte();
    position.setValid((valid & 0xc0) != 0);
    position.set(Event.KEY_SATELLITES,valid & 0x3f);
    int timeOfDay=buf.readUnsignedByte() << 16 | buf.readUnsignedByte() << 8 | buf.readUnsignedByte();
    int date=buf.readUnsignedByte() << 16 | buf.readUnsignedByte() << 8 | buf.readUnsignedByte();
    Calendar time=Calendar.getInstance(TimeZone.getTimeZone("String_Node_Str"));
    time.clear();
    time.set(Calendar.HOUR_OF_DAY,timeOfDay / 10000);
    time.set(Calendar.MINUTE,(timeOfDay - time.get(Calendar.HOUR_OF_DAY) * 10000) / 100);
    time.set(Calendar.SECOND,(timeOfDay - time.get(Calendar.HOUR_OF_DAY) * 10000 - time.get(Calendar.MINUTE) * 100));
    time.set(Calendar.DAY_OF_MONTH,date / 10000);
    time.set(Calendar.MONTH,(date - time.get(Calendar.DAY_OF_MONTH) * 10000) / 100 - 1);
    time.set(Calendar.YEAR,2000 + (date - time.get(Calendar.DAY_OF_MONTH) * 10000 - (time.get(Calendar.MONTH) + 1) * 100));
    position.setTime(time.getTime());
    position.setLatitude(convertCoordinate(buf.readUnsignedByte(),buf.readUnsignedByte() << 16 | buf.readUnsignedByte() << 8 | buf.readUnsignedByte()));
    position.setLongitude(convertCoordinate(buf.readUnsignedByte(),buf.readUnsignedByte() << 16 | buf.readUnsignedByte() << 8 | buf.readUnsignedByte()));
    position.setSpeed(buf.readUnsignedByte());
    position.setCourse(buf.readUnsignedByte() << 8 | 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 type=buf.getUnsignedByte(0);
  if (type == MSG_LOGIN) {
    byte[] bytes=new byte[19];
    buf.readBytes(bytes);
    String imei=ChannelBufferTools.readHexString(ChannelBuffers.wrappedBuffer(bytes,1,16),16).substring(1);
    if (!identify(imei,channel)) {
      return null;
    }
    if (channel != null) {
      byte[] response="String_Node_Str".getBytes("String_Node_Str");
      response=Arrays.copyOf(response,response.length + 1);
      response[response.length - 1]=checksum(bytes,0,18);
      channel.write(ChannelBuffers.wrappedBuffer(response));
    }
  }
 else   if (type == MSG_LOCATION) {
    buf.readUnsignedByte();
    Position position=new Position();
    position.setProtocol(getProtocolName());
    position.setDeviceId(getDeviceId());
    short status=buf.readUnsignedByte();
    position.set(Event.KEY_ALARM,(status & 0x80) != 0);
    position.set(Event.KEY_BATTERY,status & 0x7F);
    buf.skipBytes(2);
    position.set(Event.PREFIX_TEMP + 1,buf.readByte());
    buf.skipBytes(2);
    buf.readByte();
    buf.readByte();
    buf.skipBytes(6);
    int valid=buf.readUnsignedByte();
    position.setValid((valid & 0xc0) != 0);
    position.set(Event.KEY_SATELLITES,valid & 0x3f);
    int timeOfDay=buf.readUnsignedByte() << 16 | buf.readUnsignedByte() << 8 | buf.readUnsignedByte();
    int date=buf.readUnsignedByte() << 16 | buf.readUnsignedByte() << 8 | buf.readUnsignedByte();
    Calendar time=Calendar.getInstance(TimeZone.getTimeZone("String_Node_Str"));
    time.clear();
    time.set(Calendar.HOUR_OF_DAY,timeOfDay / 10000);
    time.set(Calendar.MINUTE,(timeOfDay - time.get(Calendar.HOUR_OF_DAY) * 10000) / 100);
    time.set(Calendar.SECOND,(timeOfDay - time.get(Calendar.HOUR_OF_DAY) * 10000 - time.get(Calendar.MINUTE) * 100));
    time.set(Calendar.DAY_OF_MONTH,date / 10000);
    time.set(Calendar.MONTH,(date - time.get(Calendar.DAY_OF_MONTH) * 10000) / 100 - 1);
    time.set(Calendar.YEAR,2000 + (date - time.get(Calendar.DAY_OF_MONTH) * 10000 - (time.get(Calendar.MONTH) + 1) * 100));
    position.setTime(time.getTime());
    position.setLatitude(convertCoordinate(buf.readUnsignedByte(),buf.readUnsignedByte() << 16 | buf.readUnsignedByte() << 8 | buf.readUnsignedByte()));
    position.setLongitude(convertCoordinate(buf.readUnsignedByte(),buf.readUnsignedByte() << 16 | buf.readUnsignedByte() << 8 | buf.readUnsignedByte()));
    position.setSpeed(buf.readUnsignedByte());
    position.setCourse(buf.readUnsignedByte() << 8 | buf.readUnsignedByte());
    buf.readUnsignedByte();
    return position;
  }
  return null;
}