Program: 155976
Project: 155976
Buggy source:
private List<Position> decodeBinary(ChannelBuffer buf,Channel channel,SocketAddress remoteAddress){
  List<Position> positions=new LinkedList<>();
  buf.readByte();
  boolean longFormat=buf.getUnsignedByte(buf.readerIndex()) == 0x75;
  String id=String.valueOf(Long.parseLong(ChannelBuffers.hexDump(buf.readBytes(5))));
  DeviceSession deviceSession=getDeviceSession(channel,remoteAddress,id);
  if (deviceSession == null) {
    return null;
  }
  if (longFormat) {
    buf.readUnsignedByte();
  }
  int version=BitUtil.from(buf.readUnsignedByte(),4);
  buf.readUnsignedShort();
  while (buf.readableBytes() > 1) {
    Position position=new Position();
    position.setProtocol(getProtocolName());
    position.setDeviceId(deviceSession.getDeviceId());
    DateBuilder dateBuilder=new DateBuilder().setDateReverse(BcdUtil.readInteger(buf,2),BcdUtil.readInteger(buf,2),BcdUtil.readInteger(buf,2)).setTime(BcdUtil.readInteger(buf,2),BcdUtil.readInteger(buf,2),BcdUtil.readInteger(buf,2));
    position.setTime(dateBuilder.getDate());
    double latitude=convertCoordinate(BcdUtil.readInteger(buf,8));
    double longitude=convertCoordinate(BcdUtil.readInteger(buf,9));
    byte flags=buf.readByte();
    position.setValid((flags & 0x1) == 0x1);
    if ((flags & 0x2) == 0) {
      latitude=-latitude;
    }
    position.setLatitude(latitude);
    if ((flags & 0x4) == 0) {
      longitude=-longitude;
    }
    position.setLongitude(longitude);
    position.setSpeed(BcdUtil.readInteger(buf,2));
    position.setCourse(buf.readUnsignedByte() * 2.0);
    if (longFormat) {
      position.set(Position.KEY_ODOMETER,buf.readUnsignedInt() * 1000);
      position.set(Position.KEY_SATELLITES,buf.readUnsignedByte());
      buf.readUnsignedInt();
      position.set(Position.KEY_STATUS,buf.readUnsignedShort());
      int battery=buf.readUnsignedByte();
      if (battery == 0xff) {
        position.set(Position.KEY_CHARGE,true);
      }
 else {
        position.set(Position.KEY_BATTERY_LEVEL,battery);
      }
      CellTower cellTower=CellTower.fromCidLac(buf.readUnsignedShort(),buf.readUnsignedShort());
      cellTower.setSignalStrength((int)buf.readUnsignedByte());
      position.setNetwork(new Network(cellTower));
    }
 else     if (version == 1) {
      position.set(Position.KEY_SATELLITES,buf.readUnsignedByte());
      position.set(Position.KEY_POWER,buf.readUnsignedByte());
      buf.readByte();
      position.setAltitude(buf.readUnsignedShort());
      int cid=buf.readUnsignedShort();
      int lac=buf.readUnsignedShort();
      int rssi=buf.readUnsignedByte();
      if (cid != 0 && lac != 0) {
        CellTower cellTower=CellTower.fromCidLac(cid,lac);
        cellTower.setSignalStrength(rssi);
        position.setNetwork(new Network(cellTower));
      }
 else {
        position.set(Position.KEY_RSSI,rssi);
      }
    }
 else     if (version == 2) {
      int fuel=buf.readUnsignedByte() << 8;
      position.set(Position.KEY_STATUS,buf.readUnsignedInt());
      position.set(Position.KEY_ODOMETER,buf.readUnsignedInt() * 1000);
      fuel+=buf.readUnsignedByte();
      position.set(Position.KEY_FUEL_LEVEL,fuel);
    }
    positions.add(position);
  }
  buf.readUnsignedByte();
  return positions;
}

Fixed version (ground truth):
private List<Position> decodeBinary(ChannelBuffer buf,Channel channel,SocketAddress remoteAddress){
  List<Position> positions=new LinkedList<>();
  buf.readByte();
  boolean longFormat=buf.getUnsignedByte(buf.readerIndex()) == 0x75;
  String id=String.valueOf(Long.parseLong(ChannelBuffers.hexDump(buf.readBytes(5))));
  DeviceSession deviceSession=getDeviceSession(channel,remoteAddress,id);
  if (deviceSession == null) {
    return null;
  }
  if (longFormat) {
    buf.readUnsignedByte();
  }
  int version=BitUtil.from(buf.readUnsignedByte(),4);
  buf.readUnsignedShort();
  while (buf.readableBytes() > 1) {
    Position position=new Position();
    position.setProtocol(getProtocolName());
    position.setDeviceId(deviceSession.getDeviceId());
    DateBuilder dateBuilder=new DateBuilder().setDay(BcdUtil.readInteger(buf,2)).setMonth(BcdUtil.readInteger(buf,2)).setYear(BcdUtil.readInteger(buf,2)).setHour(BcdUtil.readInteger(buf,2)).setMinute(BcdUtil.readInteger(buf,2)).setSecond(BcdUtil.readInteger(buf,2));
    position.setTime(dateBuilder.getDate());
    double latitude=convertCoordinate(BcdUtil.readInteger(buf,8));
    double longitude=convertCoordinate(BcdUtil.readInteger(buf,9));
    byte flags=buf.readByte();
    position.setValid((flags & 0x1) == 0x1);
    if ((flags & 0x2) == 0) {
      latitude=-latitude;
    }
    position.setLatitude(latitude);
    if ((flags & 0x4) == 0) {
      longitude=-longitude;
    }
    position.setLongitude(longitude);
    position.setSpeed(BcdUtil.readInteger(buf,2));
    position.setCourse(buf.readUnsignedByte() * 2.0);
    if (longFormat) {
      position.set(Position.KEY_ODOMETER,buf.readUnsignedInt() * 1000);
      position.set(Position.KEY_SATELLITES,buf.readUnsignedByte());
      buf.readUnsignedInt();
      position.set(Position.KEY_STATUS,buf.readUnsignedShort());
      int battery=buf.readUnsignedByte();
      if (battery == 0xff) {
        position.set(Position.KEY_CHARGE,true);
      }
 else {
        position.set(Position.KEY_BATTERY_LEVEL,battery);
      }
      CellTower cellTower=CellTower.fromCidLac(buf.readUnsignedShort(),buf.readUnsignedShort());
      cellTower.setSignalStrength((int)buf.readUnsignedByte());
      position.setNetwork(new Network(cellTower));
    }
 else     if (version == 1) {
      position.set(Position.KEY_SATELLITES,buf.readUnsignedByte());
      position.set(Position.KEY_POWER,buf.readUnsignedByte());
      buf.readByte();
      position.setAltitude(buf.readUnsignedShort());
      int cid=buf.readUnsignedShort();
      int lac=buf.readUnsignedShort();
      int rssi=buf.readUnsignedByte();
      if (cid != 0 && lac != 0) {
        CellTower cellTower=CellTower.fromCidLac(cid,lac);
        cellTower.setSignalStrength(rssi);
        position.setNetwork(new Network(cellTower));
      }
 else {
        position.set(Position.KEY_RSSI,rssi);
      }
    }
 else     if (version == 2) {
      int fuel=buf.readUnsignedByte() << 8;
      position.set(Position.KEY_STATUS,buf.readUnsignedInt());
      position.set(Position.KEY_ODOMETER,buf.readUnsignedInt() * 1000);
      fuel+=buf.readUnsignedByte();
      position.set(Position.KEY_FUEL_LEVEL,fuel);
    }
    positions.add(position);
  }
  buf.readUnsignedByte();
  return positions;
}