Program: 156216
Project: 156216
Buggy source:
@Override protected Object decode(ChannelHandlerContext ctx,Channel channel,Object msg) throws Exception {
  ChannelBuffer buf=(ChannelBuffer)msg;
  if (buf.readByte() != 0x78 || buf.readByte() != 0x78) {
    return null;
  }
  int length=buf.readUnsignedByte();
  int dataLength=length - 5;
  int type=buf.readUnsignedByte();
  if (type == MSG_LOGIN) {
    String imei=readImei(buf);
    buf.readUnsignedShort();
    if (dataLength > 10) {
      int extensionBits=buf.readUnsignedShort();
      int offset=(extensionBits >> 4) * 36000;
      if ((extensionBits & 0x8) != 0) {
        offset=-offset;
      }
      timeZone.setRawOffset(offset);
    }
    try {
      deviceId=getDataManager().getDeviceByImei(imei).getId();
      buf.skipBytes(dataLength - 8);
      sendResponse(channel,type,buf.readUnsignedShort());
    }
 catch (    Exception error) {
      Log.warning("String_Node_Str" + imei);
    }
  }
 else   if (deviceId != null && (type == MSG_GPS || type == MSG_GPS_LBS_1 || type == MSG_GPS_LBS_2 || type == MSG_GPS_LBS_STATUS_1 || type == MSG_GPS_LBS_STATUS_2 || type == MSG_GPS_PHONE || type == MSG_GPS_LBS_EXTEND)) {
    Position position=new Position();
    position.setDeviceId(deviceId);
    ExtendedInfoFormatter extendedInfo=new ExtendedInfoFormatter(getProtocol());
    Calendar time=Calendar.getInstance(timeZone);
    time.clear();
    time.set(Calendar.YEAR,2000 + buf.readUnsignedByte());
    time.set(Calendar.MONTH,buf.readUnsignedByte() - 1);
    time.set(Calendar.DAY_OF_MONTH,buf.readUnsignedByte());
    time.set(Calendar.HOUR_OF_DAY,buf.readUnsignedByte());
    time.set(Calendar.MINUTE,buf.readUnsignedByte());
    time.set(Calendar.SECOND,buf.readUnsignedByte());
    position.setTime(time.getTime());
    int gpsLength=buf.readUnsignedByte();
    extendedInfo.set("String_Node_Str",gpsLength & 0xf);
    gpsLength>>=4;
    double latitude=buf.readUnsignedInt() / (60.0 * 30000.0);
    double longitude=buf.readUnsignedInt() / (60.0 * 30000.0);
    position.setSpeed(buf.readUnsignedByte() * 0.539957);
    int union=buf.readUnsignedShort();
    position.setCourse((double)(union & 0x03FF));
    position.setValid((union & 0x1000) != 0);
    if ((union & 0x0400) == 0)     latitude=-latitude;
    if ((union & 0x0800) != 0)     longitude=-longitude;
    position.setLatitude(latitude);
    position.setLongitude(longitude);
    position.setAltitude(0.0);
    if ((union & 0x4000) != 0) {
      extendedInfo.set("String_Node_Str",(union & 0x8000) != 0);
    }
    buf.skipBytes(gpsLength - 12);
    if (type == MSG_GPS_LBS_1 || type == MSG_GPS_LBS_2 || type == MSG_GPS_LBS_STATUS_1 || type == MSG_GPS_LBS_STATUS_2) {
      int lbsLength=0;
      if (type == MSG_GPS_LBS_STATUS_1 || type == MSG_GPS_LBS_STATUS_2) {
        lbsLength=buf.readUnsignedByte();
      }
      extendedInfo.set("String_Node_Str",buf.readUnsignedShort());
      extendedInfo.set("String_Node_Str",buf.readUnsignedByte());
      extendedInfo.set("String_Node_Str",buf.readUnsignedShort());
      extendedInfo.set("String_Node_Str",buf.readUnsignedShort() << 8 + buf.readUnsignedByte());
      buf.skipBytes(lbsLength - 9);
      if (type == MSG_GPS_LBS_STATUS_1 || type == MSG_GPS_LBS_STATUS_2) {
        extendedInfo.set("String_Node_Str",true);
        int flags=buf.readUnsignedByte();
        extendedInfo.set("String_Node_Str",(flags & 0x2) != 0);
        extendedInfo.set("String_Node_Str",buf.readUnsignedByte());
        extendedInfo.set("String_Node_Str",buf.readUnsignedByte());
      }
    }
    if (buf.readableBytes() > 6) {
      buf.skipBytes(buf.readableBytes() - 6);
    }
    int index=buf.readUnsignedShort();
    extendedInfo.set("String_Node_Str",index);
    sendResponse(channel,type,index);
    position.setExtendedInfo(extendedInfo.toString());
    return position;
  }
 else {
    buf.skipBytes(dataLength);
    if (type != MSG_COMMAND_0 && type != MSG_COMMAND_1 && type != MSG_COMMAND_2) {
      sendResponse(channel,type,buf.readUnsignedShort());
    }
  }
  return null;
}

Fixed version (ground truth):
@Override protected Object decode(ChannelHandlerContext ctx,Channel channel,Object msg) throws Exception {
  ChannelBuffer buf=(ChannelBuffer)msg;
  if (buf.readByte() != 0x78 || buf.readByte() != 0x78) {
    return null;
  }
  int length=buf.readUnsignedByte();
  int dataLength=length - 5;
  int type=buf.readUnsignedByte();
  if (type == MSG_LOGIN) {
    String imei=readImei(buf);
    buf.readUnsignedShort();
    if (dataLength > 10) {
      int extensionBits=buf.readUnsignedShort();
      int offset=(extensionBits >> 4) * 36000;
      if ((extensionBits & 0x8) != 0) {
        offset=-offset;
      }
      timeZone.setRawOffset(offset);
    }
    try {
      deviceId=getDataManager().getDeviceByImei(imei).getId();
      buf.skipBytes(buf.readableBytes() - 6);
      sendResponse(channel,type,buf.readUnsignedShort());
    }
 catch (    Exception error) {
      Log.warning("String_Node_Str" + imei);
    }
  }
 else   if (deviceId != null && (type == MSG_GPS || type == MSG_GPS_LBS_1 || type == MSG_GPS_LBS_2 || type == MSG_GPS_LBS_STATUS_1 || type == MSG_GPS_LBS_STATUS_2 || type == MSG_GPS_PHONE || type == MSG_GPS_LBS_EXTEND)) {
    Position position=new Position();
    position.setDeviceId(deviceId);
    ExtendedInfoFormatter extendedInfo=new ExtendedInfoFormatter(getProtocol());
    Calendar time=Calendar.getInstance(timeZone);
    time.clear();
    time.set(Calendar.YEAR,2000 + buf.readUnsignedByte());
    time.set(Calendar.MONTH,buf.readUnsignedByte() - 1);
    time.set(Calendar.DAY_OF_MONTH,buf.readUnsignedByte());
    time.set(Calendar.HOUR_OF_DAY,buf.readUnsignedByte());
    time.set(Calendar.MINUTE,buf.readUnsignedByte());
    time.set(Calendar.SECOND,buf.readUnsignedByte());
    position.setTime(time.getTime());
    int gpsLength=buf.readUnsignedByte();
    extendedInfo.set("String_Node_Str",gpsLength & 0xf);
    gpsLength>>=4;
    double latitude=buf.readUnsignedInt() / (60.0 * 30000.0);
    double longitude=buf.readUnsignedInt() / (60.0 * 30000.0);
    position.setSpeed(buf.readUnsignedByte() * 0.539957);
    int union=buf.readUnsignedShort();
    position.setCourse((double)(union & 0x03FF));
    position.setValid((union & 0x1000) != 0);
    if ((union & 0x0400) == 0)     latitude=-latitude;
    if ((union & 0x0800) != 0)     longitude=-longitude;
    position.setLatitude(latitude);
    position.setLongitude(longitude);
    position.setAltitude(0.0);
    if ((union & 0x4000) != 0) {
      extendedInfo.set("String_Node_Str",(union & 0x8000) != 0);
    }
    buf.skipBytes(gpsLength - 12);
    if (type == MSG_GPS_LBS_1 || type == MSG_GPS_LBS_2 || type == MSG_GPS_LBS_STATUS_1 || type == MSG_GPS_LBS_STATUS_2) {
      int lbsLength=0;
      if (type == MSG_GPS_LBS_STATUS_1 || type == MSG_GPS_LBS_STATUS_2) {
        lbsLength=buf.readUnsignedByte();
      }
      extendedInfo.set("String_Node_Str",buf.readUnsignedShort());
      extendedInfo.set("String_Node_Str",buf.readUnsignedByte());
      extendedInfo.set("String_Node_Str",buf.readUnsignedShort());
      extendedInfo.set("String_Node_Str",buf.readUnsignedShort() << 8 + buf.readUnsignedByte());
      buf.skipBytes(lbsLength - 9);
      if (type == MSG_GPS_LBS_STATUS_1 || type == MSG_GPS_LBS_STATUS_2) {
        extendedInfo.set("String_Node_Str",true);
        int flags=buf.readUnsignedByte();
        extendedInfo.set("String_Node_Str",(flags & 0x2) != 0);
        extendedInfo.set("String_Node_Str",buf.readUnsignedByte());
        extendedInfo.set("String_Node_Str",buf.readUnsignedByte());
      }
    }
    if (buf.readableBytes() > 6) {
      buf.skipBytes(buf.readableBytes() - 6);
    }
    int index=buf.readUnsignedShort();
    extendedInfo.set("String_Node_Str",index);
    sendResponse(channel,type,index);
    position.setExtendedInfo(extendedInfo.toString());
    return position;
  }
 else {
    buf.skipBytes(dataLength);
    if (type != MSG_COMMAND_0 && type != MSG_COMMAND_1 && type != MSG_COMMAND_2) {
      sendResponse(channel,type,buf.readUnsignedShort());
    }
  }
  return null;
}