Program: 156149
Project: 156149
Buggy source:
@Override protected Object decode(Channel channel,SocketAddress remoteAddress,Object msg) throws Exception {
  ChannelBuffer buf=(ChannelBuffer)msg;
  buf.readUnsignedByte();
  int version=buf.readUnsignedByte();
  String imei;
  if ((version & 0x80) != 0) {
    imei=String.valueOf((buf.readUnsignedInt() << (3 * 8)) | buf.readUnsignedMedium());
  }
 else {
    imei=String.valueOf(imeiFromUnitId(buf.readUnsignedMedium()));
  }
  buf.readUnsignedShort();
  int selector=DEFAULT_SELECTOR;
  if ((version & 0x40) != 0) {
    selector=buf.readUnsignedMedium();
  }
  Position position=new Position();
  position.setProtocol(getProtocolName());
  if (!identify(imei,channel)) {
    return null;
  }
  position.setDeviceId(getDeviceId());
  int event=buf.readUnsignedByte();
  position.set(Event.KEY_EVENT,event);
  buf.readUnsignedByte();
  if ((selector & 0x0008) != 0) {
    position.setValid((buf.readUnsignedByte() & 0x40) != 0);
  }
 else {
    return null;
  }
  if ((selector & 0x0004) != 0) {
    buf.skipBytes(4);
  }
  if ((selector & 0x0008) != 0) {
    position.setTime(new Date(buf.readUnsignedInt() * 1000));
    position.setLatitude(buf.readInt() / 1000000.0);
    position.setLongitude(buf.readInt() / 1000000.0);
    position.set(Event.KEY_SATELLITES,buf.readUnsignedByte());
  }
  if ((selector & 0x0010) != 0) {
    position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedByte()));
    buf.readUnsignedByte();
    position.setCourse(buf.readUnsignedByte() * 2.0);
  }
  if ((selector & 0x0040) != 0) {
    position.set(Event.KEY_INPUT,buf.readUnsignedByte());
  }
  if ((selector & 0x0020) != 0) {
    position.set(Event.PREFIX_ADC + 1,buf.readUnsignedShort());
    position.set(Event.PREFIX_ADC + 2,buf.readUnsignedShort());
    position.set(Event.PREFIX_ADC + 3,buf.readUnsignedShort());
    position.set(Event.PREFIX_ADC + 4,buf.readUnsignedShort());
  }
  if ((selector & 0x8000) != 0) {
    position.set(Event.KEY_POWER,buf.readUnsignedShort() / 1000.0);
    position.set(Event.KEY_BATTERY,buf.readUnsignedShort());
  }
  if ((selector & 0x10000) != 0) {
    buf.readUnsignedShort();
    buf.readUnsignedInt();
  }
  if ((selector & 0x20000) != 0) {
    buf.readUnsignedShort();
    buf.readUnsignedInt();
  }
  if ((selector & 0x0080) != 0) {
    position.set("String_Node_Str",buf.readUnsignedInt());
  }
  if ((selector & 0x0100) != 0) {
    position.set("String_Node_Str",buf.readUnsignedInt());
  }
  if ((selector & 0x0040) != 0) {
    position.set(Event.KEY_OUTPUT,buf.readUnsignedByte());
  }
  if ((selector & 0x0200) != 0) {
    buf.skipBytes(6);
  }
  if ((selector & 0x0400) != 0) {
    buf.readUnsignedByte();
  }
  if ((selector & 0x0800) != 0) {
    position.setAltitude(buf.readShort());
  }
  if ((selector & 0x2000) != 0) {
    buf.readUnsignedShort();
  }
  if ((selector & 0x4000) != 0) {
    buf.skipBytes(8);
  }
  if ((selector & 0x80000) != 0) {
    buf.skipBytes(11);
  }
  if ((selector & 0x1000) != 0) {
switch (event) {
case 2:
case 40:
      buf.readUnsignedByte();
    break;
case 9:
  buf.readUnsignedMedium();
break;
case 31:
case 32:
buf.readUnsignedShort();
break;
case 38:
buf.skipBytes(4 * 9);
break;
case 113:
buf.readUnsignedInt();
buf.readUnsignedByte();
break;
case 121:
case 142:
buf.readLong();
break;
case 130:
buf.readUnsignedInt();
break;
}
}
if (Context.getConfig().getBoolean(getProtocolName() + "String_Node_Str") && buf.readable() && (selector & 0x1000) != 0 && event == EVENT_DATA) {
buf.readUnsignedMedium();
buf.readUnsignedByte();
int count=buf.readUnsignedByte();
buf.readUnsignedByte();
buf.readUnsignedShort();
buf.readUnsignedInt();
buf.skipBytes(8);
ArrayList<ChannelBuffer> values=new ArrayList<>(count);
for (int i=0; i < count; i++) {
values.add(buf.readBytes(8));
}
for (int i=0; i < count; i++) {
ChannelBuffer value=values.get(i);
switch (buf.readInt()) {
case 0x20D:
position.set(Event.KEY_RPM,ChannelBuffers.swapShort(value.readShort()));
position.set("String_Node_Str",ChannelBuffers.swapShort(value.readShort()) * 0.1);
position.set("String_Node_Str",ChannelBuffers.swapShort(value.readShort()) * 0.01);
position.set("String_Node_Str",ChannelBuffers.swapShort(value.readShort()) * 0.1);
break;
case 0x30D:
position.set("String_Node_Str",ChannelBufferTools.readHexString(value,16));
break;
case 0x40C:
position.set("String_Node_Str",ChannelBuffers.swapShort(value.readShort()) * 0.1);
position.set("String_Node_Str",ChannelBuffers.swapShort(value.readShort()) * 0.1);
break;
case 0x40D:
position.set("String_Node_Str",ChannelBufferTools.readHexString(value,16));
break;
case 0x50C:
position.set("String_Node_Str",ChannelBuffers.swapShort(value.readShort()) * 0.1);
position.set("String_Node_Str",ChannelBuffers.swapShort(value.readShort()) * 0.1);
break;
case 0x50D:
position.set("String_Node_Str",ChannelBuffers.swapShort(value.readShort()) * 0.1);
position.set("String_Node_Str",ChannelBuffers.swapShort(value.readShort()) * 0.1);
break;
case 0x58C:
value.readByte();
value.readShort();
switch (value.readByte()) {
case 0x01:
position.set("String_Node_Str",ChannelBuffers.swapInt(value.readInt()) * 0.1);
break;
case 0x02:
position.set("String_Node_Str",ChannelBuffers.swapInt(value.readInt()) * 0.1);
break;
case 0x05:
position.set("String_Node_Str",ChannelBuffers.swapInt(value.readInt()));
break;
case 0x13:
position.set("String_Node_Str",ChannelBuffers.swapInt(value.readInt()) / 60 / 60);
break;
case 0x14:
position.set("String_Node_Str",ChannelBuffers.swapInt(value.readInt()) / 60 / 60);
break;
case 0x17:
position.set("String_Node_Str",ChannelBuffers.swapInt(value.readInt()));
break;
case 0x18:
position.set("String_Node_Str",ChannelBuffers.swapInt(value.readInt()) * 0.01);
break;
}
break;
}
}
}
return position;
}

Fixed version (ground truth):
@Override protected Object decode(Channel channel,SocketAddress remoteAddress,Object msg) throws Exception {
  ChannelBuffer buf=(ChannelBuffer)msg;
  buf.readUnsignedByte();
  int version=buf.readUnsignedByte();
  String imei;
  if ((version & 0x80) != 0) {
    imei=String.valueOf((buf.readUnsignedInt() << (3 * 8)) | buf.readUnsignedMedium());
  }
 else {
    imei=String.valueOf(imeiFromUnitId(buf.readUnsignedMedium()));
  }
  buf.readUnsignedShort();
  int selector=DEFAULT_SELECTOR;
  if ((version & 0x40) != 0) {
    selector=buf.readUnsignedMedium();
  }
  Position position=new Position();
  position.setProtocol(getProtocolName());
  if (!identify(imei,channel)) {
    return null;
  }
  position.setDeviceId(getDeviceId());
  int event=buf.readUnsignedByte();
  position.set(Event.KEY_EVENT,event);
  buf.readUnsignedByte();
  if ((selector & 0x0008) != 0) {
    position.setValid((buf.readUnsignedByte() & 0x40) != 0);
  }
 else {
    return null;
  }
  if ((selector & 0x0004) != 0) {
    buf.skipBytes(4);
  }
  if ((selector & 0x0008) != 0) {
    position.setTime(new Date(buf.readUnsignedInt() * 1000));
    position.setLatitude(buf.readInt() / 1000000.0);
    position.setLongitude(buf.readInt() / 1000000.0);
    position.set(Event.KEY_SATELLITES,buf.readUnsignedByte());
  }
  if ((selector & 0x0010) != 0) {
    position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedByte()));
    buf.readUnsignedByte();
    position.setCourse(buf.readUnsignedByte() * 2.0);
  }
  if ((selector & 0x0040) != 0) {
    position.set(Event.KEY_INPUT,buf.readUnsignedByte());
  }
  if ((selector & 0x0020) != 0) {
    position.set(Event.PREFIX_ADC + 1,buf.readUnsignedShort());
    position.set(Event.PREFIX_ADC + 2,buf.readUnsignedShort());
    position.set(Event.PREFIX_ADC + 3,buf.readUnsignedShort());
    position.set(Event.PREFIX_ADC + 4,buf.readUnsignedShort());
  }
  if ((selector & 0x8000) != 0) {
    position.set(Event.KEY_POWER,buf.readUnsignedShort() / 1000.0);
    position.set(Event.KEY_BATTERY,buf.readUnsignedShort());
  }
  if ((selector & 0x10000) != 0) {
    buf.readUnsignedShort();
    buf.readUnsignedInt();
  }
  if ((selector & 0x20000) != 0) {
    buf.readUnsignedShort();
    buf.readUnsignedInt();
  }
  if ((selector & 0x0080) != 0) {
    position.set("String_Node_Str",buf.readUnsignedInt());
  }
  if ((selector & 0x0100) != 0) {
    position.set("String_Node_Str",buf.readUnsignedInt());
  }
  if ((selector & 0x0040) != 0) {
    position.set(Event.KEY_OUTPUT,buf.readUnsignedByte());
  }
  if ((selector & 0x0200) != 0) {
    buf.skipBytes(6);
  }
  if ((selector & 0x0400) != 0) {
    buf.readUnsignedByte();
  }
  if ((selector & 0x0800) != 0) {
    position.setAltitude(buf.readShort());
  }
  if ((selector & 0x2000) != 0) {
    buf.readUnsignedShort();
  }
  if ((selector & 0x4000) != 0) {
    buf.skipBytes(8);
  }
  if ((selector & 0x80000) != 0) {
    buf.skipBytes(11);
  }
  if ((selector & 0x1000) != 0) {
switch (event) {
case 2:
case 40:
      buf.readUnsignedByte();
    break;
case 9:
  buf.readUnsignedMedium();
break;
case 31:
case 32:
buf.readUnsignedShort();
break;
case 38:
buf.skipBytes(4 * 9);
break;
case 113:
buf.readUnsignedInt();
buf.readUnsignedByte();
break;
case 121:
case 142:
buf.readLong();
break;
case 130:
buf.readUnsignedInt();
break;
default :
break;
}
}
if (Context.getConfig().getBoolean(getProtocolName() + "String_Node_Str") && buf.readable() && (selector & 0x1000) != 0 && event == EVENT_DATA) {
buf.readUnsignedMedium();
buf.readUnsignedByte();
int count=buf.readUnsignedByte();
buf.readUnsignedByte();
buf.readUnsignedShort();
buf.readUnsignedInt();
buf.skipBytes(8);
ArrayList<ChannelBuffer> values=new ArrayList<>(count);
for (int i=0; i < count; i++) {
values.add(buf.readBytes(8));
}
for (int i=0; i < count; i++) {
ChannelBuffer value=values.get(i);
switch (buf.readInt()) {
case 0x20D:
position.set(Event.KEY_RPM,ChannelBuffers.swapShort(value.readShort()));
position.set("String_Node_Str",ChannelBuffers.swapShort(value.readShort()) * 0.1);
position.set("String_Node_Str",ChannelBuffers.swapShort(value.readShort()) * 0.01);
position.set("String_Node_Str",ChannelBuffers.swapShort(value.readShort()) * 0.1);
break;
case 0x30D:
position.set("String_Node_Str",ChannelBufferTools.readHexString(value,16));
break;
case 0x40C:
position.set("String_Node_Str",ChannelBuffers.swapShort(value.readShort()) * 0.1);
position.set("String_Node_Str",ChannelBuffers.swapShort(value.readShort()) * 0.1);
break;
case 0x40D:
position.set("String_Node_Str",ChannelBufferTools.readHexString(value,16));
break;
case 0x50C:
position.set("String_Node_Str",ChannelBuffers.swapShort(value.readShort()) * 0.1);
position.set("String_Node_Str",ChannelBuffers.swapShort(value.readShort()) * 0.1);
break;
case 0x50D:
position.set("String_Node_Str",ChannelBuffers.swapShort(value.readShort()) * 0.1);
position.set("String_Node_Str",ChannelBuffers.swapShort(value.readShort()) * 0.1);
break;
case 0x58C:
value.readByte();
value.readShort();
switch (value.readByte()) {
case 0x01:
position.set("String_Node_Str",ChannelBuffers.swapInt(value.readInt()) * 0.1);
break;
case 0x02:
position.set("String_Node_Str",ChannelBuffers.swapInt(value.readInt()) * 0.1);
break;
case 0x05:
position.set("String_Node_Str",ChannelBuffers.swapInt(value.readInt()));
break;
case 0x13:
position.set("String_Node_Str",ChannelBuffers.swapInt(value.readInt()) / 60 / 60);
break;
case 0x14:
position.set("String_Node_Str",ChannelBuffers.swapInt(value.readInt()) / 60 / 60);
break;
case 0x17:
position.set("String_Node_Str",ChannelBuffers.swapInt(value.readInt()));
break;
case 0x18:
position.set("String_Node_Str",ChannelBuffers.swapInt(value.readInt()) * 0.01);
break;
default :
break;
}
break;
}
}
}
return position;
}