Program: 156142
Project: 156142
Buggy source:
@Override protected Object decode(Channel channel,SocketAddress remoteAddress,Object msg) throws Exception {
  ChannelBuffer buf=(ChannelBuffer)msg;
  buf.readByte();
  buf.readUnsignedByte();
  buf.readUnsignedByte();
  Position position=new Position();
  position.setProtocol(getProtocolName());
  String imei=ChannelBufferTools.readHexString(buf,16).substring(1);
  if (!identify(imei,channel)) {
    return null;
  }
  position.setDeviceId(getDeviceId());
  long seconds=buf.readUnsignedInt() & 0x7fffffffl;
  seconds+=946684800l;
  seconds-=timeZone;
  position.setTime(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(Event.KEY_HDOP,buf.readUnsignedShort());
break;
case DATA_LBS:
position.set(Event.KEY_MCC,buf.readUnsignedShort());
position.set(Event.KEY_MNC,buf.readUnsignedByte());
position.set(Event.KEY_LAC,buf.readUnsignedShort());
position.set(Event.KEY_CELL,buf.readUnsignedShort());
position.set(Event.KEY_GSM,-buf.readUnsignedByte());
break;
case DATA_STATUS:
int status=buf.readUnsignedShort();
position.set(Event.KEY_IGNITION,BitUtil.check(status,6));
position.set(Event.KEY_STATUS,status);
position.set(Event.KEY_ALARM,buf.readUnsignedShort());
break;
case DATA_ODOMETER:
position.set(Event.KEY_ODOMETER,buf.readUnsignedInt());
break;
case DATA_ADC:
for (int i=0; i < length / 2; i++) {
int value=buf.readUnsignedShort();
position.set(Event.PREFIX_ADC + BitUtil.range(value,12),BitUtil.range(value,0,12));
}
break;
case DATA_GEOFENCE:
position.set("String_Node_Str",buf.readUnsignedInt());
position.set("String_Node_Str",buf.readUnsignedInt());
break;
case DATA_OBD2:
position.set("String_Node_Str",ChannelBuffers.hexDump(buf.readBytes(length)));
break;
case DATA_FUEL:
position.set("String_Node_Str",buf.readUnsignedInt() / 10000.0);
break;
case DATA_OBD2_ALARM:
position.set("String_Node_Str",ChannelBuffers.hexDump(buf.readBytes(length)));
break;
case DATA_HARSH_DRIVER:
position.set("String_Node_Str",buf.readUnsignedByte());
break;
case DATA_CANBUS:
position.set("String_Node_Str",ChannelBuffers.hexDump(buf.readBytes(length)));
break;
case DATA_J1708:
position.set("String_Node_Str",ChannelBuffers.hexDump(buf.readBytes(length)));
break;
case DATA_VIN:
position.set("String_Node_Str",buf.readBytes(length).toString(Charset.defaultCharset()));
break;
case DATA_RFID:
position.set(Event.KEY_RFID,buf.readBytes(length - 1).toString(Charset.defaultCharset()));
position.set("String_Node_Str",buf.readUnsignedByte() != 0);
break;
case DATA_EVENT:
position.set(Event.KEY_EVENT,buf.readUnsignedByte());
position.set("String_Node_Str",buf.readUnsignedInt());
break;
default :
buf.skipBytes(length);
break;
}
}
if (hasLocation) {
return position;
}
return null;
}

Fixed version (ground truth):
@Override protected Object decode(Channel channel,SocketAddress remoteAddress,Object msg) throws Exception {
  ChannelBuffer buf=(ChannelBuffer)msg;
  buf.readByte();
  buf.readUnsignedByte();
  buf.readUnsignedByte();
  Position position=new Position();
  position.setProtocol(getProtocolName());
  String imei=ChannelBufferTools.readHexString(buf,16).substring(1);
  if (!identify(imei,channel)) {
    return null;
  }
  position.setDeviceId(getDeviceId());
  long seconds=buf.readUnsignedInt() & 0x7fffffffL;
  seconds+=946684800L;
  seconds-=timeZone;
  position.setTime(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(Event.KEY_HDOP,buf.readUnsignedShort());
break;
case DATA_LBS:
position.set(Event.KEY_MCC,buf.readUnsignedShort());
position.set(Event.KEY_MNC,buf.readUnsignedByte());
position.set(Event.KEY_LAC,buf.readUnsignedShort());
position.set(Event.KEY_CELL,buf.readUnsignedShort());
position.set(Event.KEY_GSM,-buf.readUnsignedByte());
break;
case DATA_STATUS:
int status=buf.readUnsignedShort();
position.set(Event.KEY_IGNITION,BitUtil.check(status,6));
position.set(Event.KEY_STATUS,status);
position.set(Event.KEY_ALARM,buf.readUnsignedShort());
break;
case DATA_ODOMETER:
position.set(Event.KEY_ODOMETER,buf.readUnsignedInt());
break;
case DATA_ADC:
for (int i=0; i < length / 2; i++) {
int value=buf.readUnsignedShort();
position.set(Event.PREFIX_ADC + BitUtil.range(value,12),BitUtil.range(value,0,12));
}
break;
case DATA_GEOFENCE:
position.set("String_Node_Str",buf.readUnsignedInt());
position.set("String_Node_Str",buf.readUnsignedInt());
break;
case DATA_OBD2:
position.set("String_Node_Str",ChannelBuffers.hexDump(buf.readBytes(length)));
break;
case DATA_FUEL:
position.set("String_Node_Str",buf.readUnsignedInt() / 10000.0);
break;
case DATA_OBD2_ALARM:
position.set("String_Node_Str",ChannelBuffers.hexDump(buf.readBytes(length)));
break;
case DATA_HARSH_DRIVER:
position.set("String_Node_Str",buf.readUnsignedByte());
break;
case DATA_CANBUS:
position.set("String_Node_Str",ChannelBuffers.hexDump(buf.readBytes(length)));
break;
case DATA_J1708:
position.set("String_Node_Str",ChannelBuffers.hexDump(buf.readBytes(length)));
break;
case DATA_VIN:
position.set("String_Node_Str",buf.readBytes(length).toString(Charset.defaultCharset()));
break;
case DATA_RFID:
position.set(Event.KEY_RFID,buf.readBytes(length - 1).toString(Charset.defaultCharset()));
position.set("String_Node_Str",buf.readUnsignedByte() != 0);
break;
case DATA_EVENT:
position.set(Event.KEY_EVENT,buf.readUnsignedByte());
position.set("String_Node_Str",buf.readUnsignedInt());
break;
default :
buf.skipBytes(length);
break;
}
}
if (hasLocation) {
return position;
}
return null;
}