Program: 156019
Project: 156019
Buggy source:
@Override protected Object decode(Channel channel,SocketAddress remoteAddress,Object msg) throws Exception {
  ChannelBuffer buf=(ChannelBuffer)msg;
  if (buf.readUnsignedByte() != 0xF8) {
    return null;
  }
  buf.readUnsignedByte();
  buf.readUnsignedByte();
  Position position=new Position();
  position.setProtocol(getProtocolName());
  String imei=ChannelBuffers.hexDump(buf.readBytes(8)).substring(1);
  DeviceSession deviceSession=getDeviceSession(channel,remoteAddress,imei);
  if (deviceSession == null) {
    return null;
  }
  position.setDeviceId(deviceSession.getDeviceId());
  long seconds=buf.readUnsignedInt() & 0x7fffffffL;
  seconds+=946684800L;
  seconds-=timeZone;
  Date time=new Date(seconds * 1000);
  boolean hasLocation=false;
  while (buf.readableBytes() > 3) {
    short type=buf.readUnsignedByte();
    short length=buf.readUnsignedByte();
switch (type) {
case DATA_GPS:
      hasLocation=true;
    position.setValid(true);
  position.setLatitude(buf.readInt() / 1000000.0);
position.setLongitude(buf.readInt() / 1000000.0);
position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedShort()));
position.setCourse(buf.readUnsignedShort());
position.set(Position.KEY_HDOP,buf.readUnsignedShort());
break;
case DATA_LBS:
position.set(Position.KEY_MCC,buf.readUnsignedShort());
position.set(Position.KEY_MNC,buf.readUnsignedShort());
position.set(Position.KEY_LAC,buf.readUnsignedShort());
if (length == 11) {
position.set(Position.KEY_CID,buf.readUnsignedInt());
}
 else {
position.set(Position.KEY_CID,buf.readUnsignedShort());
}
position.set(Position.KEY_GSM,-buf.readUnsignedByte());
if (length > 9 && length != 11) {
buf.skipBytes(length - 9);
}
break;
case DATA_STATUS:
int status=buf.readUnsignedShort();
position.set(Position.KEY_IGNITION,BitUtil.check(status,9));
position.set(Position.KEY_STATUS,status);
position.set(Position.KEY_ALARM,decodeAlarm(buf.readUnsignedShort()));
break;
case DATA_ODOMETER:
position.set(Position.KEY_ODOMETER,buf.readUnsignedInt());
break;
case DATA_ADC:
for (int i=0; i < length / 2; i++) {
int value=buf.readUnsignedShort();
position.set(Position.PREFIX_ADC + BitUtil.from(value,12),BitUtil.to(value,12));
}
break;
case DATA_GEOFENCE:
position.set("String_Node_Str",buf.readUnsignedInt());
position.set("String_Node_Str",buf.readUnsignedInt());
break;
case DATA_OBD2:
decodeObd(position,buf,length);
break;
case DATA_FUEL:
position.set("String_Node_Str",buf.readUnsignedInt() / 10000.0);
break;
case DATA_OBD2_ALARM:
decodeObd(position,buf,length);
break;
case DATA_HARSH_DRIVER:
decodeDriverBehavior(position,buf);
break;
case DATA_CANBUS:
position.set("String_Node_Str",ChannelBuffers.hexDump(buf.readBytes(length)));
break;
case DATA_J1708:
decodeJ1708(position,buf,length);
break;
case DATA_VIN:
position.set(Position.KEY_VIN,buf.readBytes(length).toString(StandardCharsets.US_ASCII));
break;
case DATA_RFID:
position.set(Position.KEY_RFID,buf.readBytes(length - 1).toString(StandardCharsets.US_ASCII));
position.set("String_Node_Str",buf.readUnsignedByte() != 0);
break;
case DATA_EVENT:
position.set(Position.KEY_EVENT,buf.readUnsignedByte());
if (length > 1) {
position.set("String_Node_Str",buf.readUnsignedInt());
}
break;
default :
buf.skipBytes(length);
break;
}
}
if (!hasLocation) {
getLastLocation(position,time);
}
 else {
position.setTime(time);
}
return position;
}

Fixed version (ground truth):
@Override protected Object decode(Channel channel,SocketAddress remoteAddress,Object msg) throws Exception {
  ChannelBuffer buf=(ChannelBuffer)msg;
  if (buf.readUnsignedByte() != 0xF8) {
    return null;
  }
  buf.readUnsignedByte();
  buf.readUnsignedByte();
  Position position=new Position();
  position.setProtocol(getProtocolName());
  String imei=ChannelBuffers.hexDump(buf.readBytes(8)).substring(1);
  DeviceSession deviceSession=getDeviceSession(channel,remoteAddress,imei);
  if (deviceSession == null) {
    return null;
  }
  position.setDeviceId(deviceSession.getDeviceId());
  long seconds=buf.readUnsignedInt() & 0x7fffffffL;
  seconds+=946684800L;
  seconds-=timeZone;
  Date time=new Date(seconds * 1000);
  boolean hasLocation=false;
  while (buf.readableBytes() > 3) {
    int type=buf.readUnsignedByte();
    int length=type == DATA_CANBUS ? buf.readUnsignedShort() : buf.readUnsignedByte();
switch (type) {
case DATA_GPS:
      hasLocation=true;
    position.setValid(true);
  position.setLatitude(buf.readInt() / 1000000.0);
position.setLongitude(buf.readInt() / 1000000.0);
position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedShort()));
position.setCourse(buf.readUnsignedShort());
position.set(Position.KEY_HDOP,buf.readUnsignedShort());
break;
case DATA_LBS:
position.set(Position.KEY_MCC,buf.readUnsignedShort());
position.set(Position.KEY_MNC,buf.readUnsignedShort());
position.set(Position.KEY_LAC,buf.readUnsignedShort());
if (length == 11) {
position.set(Position.KEY_CID,buf.readUnsignedInt());
}
 else {
position.set(Position.KEY_CID,buf.readUnsignedShort());
}
position.set(Position.KEY_GSM,-buf.readUnsignedByte());
if (length > 9 && length != 11) {
buf.skipBytes(length - 9);
}
break;
case DATA_STATUS:
int status=buf.readUnsignedShort();
position.set(Position.KEY_IGNITION,BitUtil.check(status,9));
position.set(Position.KEY_STATUS,status);
position.set(Position.KEY_ALARM,decodeAlarm(buf.readUnsignedShort()));
break;
case DATA_ODOMETER:
position.set(Position.KEY_ODOMETER,buf.readUnsignedInt());
break;
case DATA_ADC:
for (int i=0; i < length / 2; i++) {
int value=buf.readUnsignedShort();
position.set(Position.PREFIX_ADC + BitUtil.from(value,12),BitUtil.to(value,12));
}
break;
case DATA_GEOFENCE:
position.set("String_Node_Str",buf.readUnsignedInt());
position.set("String_Node_Str",buf.readUnsignedInt());
break;
case DATA_OBD2:
decodeObd(position,buf,length);
break;
case DATA_FUEL:
position.set("String_Node_Str",buf.readUnsignedInt() / 10000.0);
break;
case DATA_OBD2_ALARM:
decodeObd(position,buf,length);
break;
case DATA_HARSH_DRIVER:
decodeDriverBehavior(position,buf);
break;
case DATA_CANBUS:
position.set("String_Node_Str",ChannelBuffers.hexDump(buf.readBytes(length)));
break;
case DATA_J1708:
decodeJ1708(position,buf,length);
break;
case DATA_VIN:
position.set(Position.KEY_VIN,buf.readBytes(length).toString(StandardCharsets.US_ASCII));
break;
case DATA_RFID:
position.set(Position.KEY_RFID,buf.readBytes(length - 1).toString(StandardCharsets.US_ASCII));
position.set("String_Node_Str",buf.readUnsignedByte() != 0);
break;
case DATA_EVENT:
position.set(Position.KEY_EVENT,buf.readUnsignedByte());
if (length > 1) {
position.set("String_Node_Str",buf.readUnsignedInt());
}
break;
default :
buf.skipBytes(length);
break;
}
}
if (!hasLocation) {
getLastLocation(position,time);
}
 else {
position.setTime(time);
}
return position;
}