nus-yam/ex-repair huggingface dataset:
Program: 11814
Project: 11814
Buggy source:
public <T extends Entity>T build(Class<T> entityType,ParameterValue<?>... parameterValues){
  int paramLen=parameterValues.length;
  Class[] params=new Class[paramLen];
  Object[] args=new Object[paramLen];
  for (int i=0; i < paramLen; i++) {
    ParameterValue<?> value=parameterValues[i];
    params[i]=value.clazz();
    args[i]=value.value();
  }
  TridentEntity entity=null;
  try {
    Constructor<? extends TridentEntity> constructor=(Constructor<? extends TridentEntity>)entityType.getConstructor(params);
    entity=constructor.newInstance(args);
    entity.executor=executor != null ? executor : ThreadsHandler.entityExecutor();
    entity.godMode=god;
    entity.passenger=passenger;
    entity.displayName=displayName;
    entity.nameVisible=displayName != null;
    entity.silent=silent;
    entity.spawn();
  }
 catch (  NoSuchMethodException|InvocationTargetException|IllegalAccessException|InstantiationException e) {
    TridentLogger.error(e);
  }
  return (T)entity;
}

Fixed version (ground truth):
public <T extends Entity>T build(Class<T> entityType,ParameterValue<?>... parameterValues){
  int paramLen=parameterValues.length;
  Class[] params=new Class[paramLen];
  Object[] args=new Object[paramLen];
  for (int i=0; i < paramLen; i++) {
    ParameterValue<?> value=parameterValues[i];
    params[i]=value.clazz();
    args[i]=value.value();
  }
  TridentEntity entity=null;
  if (entityType == TridentPlayer.class) {
    entity=new TridentPlayer((CompoundTag)parameterValues[0].value(),(TridentWorld)parameterValues[1].value(),(ClientConnection)parameterValues[2].value());
    entity.executor=executor != null ? executor : ThreadsHandler.entityExecutor();
    entity.godMode=god;
    entity.passenger=passenger;
    entity.displayName=displayName;
    entity.nameVisible=displayName != null;
    entity.silent=silent;
    entity.spawn();
    return (T)entity;
  }
  try {
    Constructor<? extends TridentEntity> constructor=(Constructor<? extends TridentEntity>)entityType.getConstructor(params);
    entity=constructor.newInstance(args);
    entity.executor=executor != null ? executor : ThreadsHandler.entityExecutor();
    entity.godMode=god;
    entity.passenger=passenger;
    entity.displayName=displayName;
    entity.nameVisible=displayName != null;
    entity.silent=silent;
    entity.spawn();
  }
 catch (  NoSuchMethodException|InvocationTargetException|IllegalAccessException|InstantiationException e) {
    TridentLogger.error(e);
  }
  return (T)entity;
}
Program: 11815
Project: 11815
Buggy source:
/** 
 * Removes the client's server side client handler
 */
public void logout(){
  TridentPlayer player=((PlayerConnection)this).player();
  if (this instanceof PlayerConnection)   ThreadsHandler.remove(player);
  player.remove();
  clientData.remove(this.address);
  this.channel.close();
}

Fixed version (ground truth):
/** 
 * Removes the client's server side client handler
 */
public void logout(){
  if (this instanceof PlayerConnection) {
    TridentPlayer player=((PlayerConnection)this).player();
    ThreadsHandler.remove(player);
    player.remove();
  }
  clientData.remove(this.address);
  this.channel.close();
}
Program: 11820
Project: 11820
Buggy source:
protected void loadBlocks(World world){
  if (add == null) {
    add=new byte[LENGTH];
  }
  NibbleArray add=new NibbleArray(this.add);
  NibbleArray data=new NibbleArray(this.data);
  types=new byte[rawTypes.length];
  for (int i=0; i < LENGTH; i+=1) {
    Block block;
    byte b;
    byte bData;
    int bAdd;
    b=rawTypes[i];
    bAdd=add.get(i) << 8;
    b+=bAdd;
    bData=data.get(i);
    Substance material=Substance.fromId(b);
    if (material == null) {
      material=Substance.AIR;
    }
    block=new TridentBlock(Coordinates.create(world,0,0,0),material,bData);
switch (block.substance()) {
default :
      break;
  }
  types[i]=(byte)(bAdd | ((b & 0xff) << 4) | bData);
}
}

Fixed version (ground truth):
protected void loadBlocks(World world){
  if (add == null) {
    add=new byte[LENGTH];
  }
  types=new byte[rawTypes.length];
  for (int i=0; i < LENGTH; i+=1) {
    Block block;
    byte b;
    byte bData;
    int bAdd;
    b=rawTypes[i];
    bAdd=NibbleArray.get(this.add,i) << 8;
    b+=bAdd;
    bData=NibbleArray.get(this.data,i);
    Substance material=Substance.fromId(b);
    if (material == null) {
      material=Substance.AIR;
    }
    block=new TridentBlock(Coordinates.create(world,0,0,0),material,bData);
switch (block.substance()) {
default :
      break;
  }
  types[i]=(byte)(bAdd | ((b & 0xff) << 4) | bData);
}
}
Program: 11821
Project: 11821
Buggy source:
@Override public Block tileAt(int relX,int y,int relZ){
  int index=WorldUtils.blockArrayIndex(relX,y % 16,relZ);
  ChunkSection section=sections[WorldUtils.section(y)];
  NibbleArray add=new NibbleArray(section.add);
  NibbleArray data=new NibbleArray(section.data);
  byte b=section.rawTypes[index];
  int bAdd=add.get(index) << 8;
  byte meta=data.get(index);
  b+=bAdd;
  Substance material=Substance.fromId(b);
  if (material == null) {
    material=Substance.AIR;
  }
  return new TridentBlock(Coordinates.create(this.world,relX + this.x() * 16,y,relZ + this.z() * 16),material,meta);
}

Fixed version (ground truth):
@Override public Block tileAt(int relX,int y,int relZ){
  int index=WorldUtils.blockArrayIndex(relX,y % 16,relZ);
  ChunkSection section=sections[WorldUtils.section(y)];
  byte b=section.rawTypes[index];
  int bAdd=NibbleArray.get(section.add,index) << 8;
  byte meta=NibbleArray.get(section.data,index);
  b+=bAdd;
  Substance material=Substance.fromId(b);
  if (material == null) {
    material=Substance.AIR;
  }
  return new TridentBlock(Coordinates.create(this.world,relX + this.x() * 16,y,relZ + this.z() * 16),material,meta);
}
Program: 11823
Project: 11823
Buggy source:
/** 
 * Gets the index of a block in a section
 * @param x the specified x
 * @param y the y height specified
 * @param z the specified z
 * @return the index of the block array containing the coordinates given
 */
public static int blockArrayIndex(int x,int y,int z){
  return (y << 8) + (z << 4) + x;
}

Fixed version (ground truth):
/** 
 * Gets the index of a block in a section
 * @param x the specified x
 * @param y the y height specified
 * @param z the specified z
 * @return the index of the block array containing the coordinates given
 */
public static int blockArrayIndex(int x,int y,int z){
  if (x < 0) {
    x++;
    x=-x;
  }
  if (z < 0) {
    z++;
    z=-z;
  }
  return (y << 8) + (z << 4) + x;
}
Program: 11824
Project: 11824
Buggy source:
/** 
 * Converts the PacketData to a Packet depending on the ConnectionStage of the Client    {@inheritDoc}
 */
@Override protected void messageReceived(ChannelHandlerContext context,PacketData data) throws Exception {
  if (this.connection.isEncryptionEnabled()) {
    data.decrypt(this.connection);
  }
  Packet packet=this.protocol.getPacket(data.getId(),this.connection.getStage(),PacketDirection.IN);
  if (packet.getId() == -1) {
    this.connection.logout();
    return;
  }
  if (!(packet instanceof PacketPlayInPlayerMove)) {
    TridentLogger.log("String_Node_Str" + packet.getClass().getSimpleName().replaceAll("String_Node_Str","String_Node_Str").replaceAll("String_Node_Str","String_Node_Str"));
  }
  packet.decode(data.getData());
  try {
    packet.handleReceived(this.connection);
    if (connection instanceof PlayerConnection) {
      ((PlayerConnection)connection).resetReadCounter();
    }
  }
 catch (  Exception ex) {
    TridentLogger.error(ex);
switch (this.connection.getStage()) {
case LOGIN:
      PacketLoginOutDisconnect disconnect=new PacketLoginOutDisconnect();
    disconnect.setJsonMessage(ex.getMessage());
  this.connection.sendPacket(disconnect);
this.connection.logout();
case PLAY:
PacketPlayOutDisconnect quit=new PacketPlayOutDisconnect();
quit.set("String_Node_Str","String_Node_Str" + ex.getClass().getName() + ((ex.getMessage() != null) ? "String_Node_Str" + ex.getMessage() : "String_Node_Str")+ "String_Node_Str");
this.connection.sendPacket(quit);
this.connection.logout();
default :
break;
}
}
}

Fixed version (ground truth):
/** 
 * Converts the PacketData to a Packet depending on the ConnectionStage of the Client    {@inheritDoc}
 */
@Override protected void messageReceived(ChannelHandlerContext context,PacketData data) throws Exception {
  if (this.connection.isEncryptionEnabled()) {
    data.decrypt(this.connection);
  }
  Packet packet=this.protocol.getPacket(data.getId(),this.connection.getStage(),PacketDirection.IN);
  if (packet.getId() == -1) {
    this.connection.logout();
    return;
  }
  packet.decode(data.getData());
  try {
    packet.handleReceived(this.connection);
    if (connection instanceof PlayerConnection) {
      ((PlayerConnection)connection).resetReadCounter();
    }
  }
 catch (  Exception ex) {
    TridentLogger.error(ex);
switch (this.connection.getStage()) {
case LOGIN:
      PacketLoginOutDisconnect disconnect=new PacketLoginOutDisconnect();
    disconnect.setJsonMessage(ex.getMessage());
  this.connection.sendPacket(disconnect);
this.connection.logout();
case PLAY:
PacketPlayOutDisconnect quit=new PacketPlayOutDisconnect();
quit.set("String_Node_Str","String_Node_Str" + ex.getClass().getName() + ((ex.getMessage() != null) ? "String_Node_Str" + ex.getMessage() : "String_Node_Str")+ "String_Node_Str");
this.connection.sendPacket(quit);
this.connection.logout();
default :
break;
}
}
}
Program: 11825
Project: 11825
Buggy source:
@InternalUseOnly public synchronized void sendKeepAlive(){
  int oldId=keepAliveId;
  if (oldId != -1)   return;
  int id=ThreadLocalRandom.current().nextInt();
  OutPacket packet=new PacketPlayOutKeepAlive();
  packet.set("String_Node_Str",id);
  keepAliveId=id;
  sendPacket(packet);
}

Fixed version (ground truth):
@InternalUseOnly public synchronized void sendKeepAlive(){
  int oldId=keepAliveId;
  if (oldId != -1)   return;
  int id=ThreadLocalRandom.current().nextInt(0x230000);
  OutPacket packet=new PacketPlayOutKeepAlive();
  packet.set("String_Node_Str",id);
  keepAliveId=id;
  sendPacket(packet);
}
Program: 11826
Project: 11826
Buggy source:
@InternalUseOnly public void resumeLogin(){
  if (!loggingIn)   return;
  sendChunks(7);
  connection.sendPacket(PacketPlayOutStatistics.DEFAULT_STATISTIC);
  TridentWindow window=new TridentWindow("String_Node_Str",9,InventoryType.CHEST);
  window.setSlot(0,new Item(Substance.DIAMOND_PICKAXE));
  window.sendTo(this);
  for (  Entity entity : world().entities()) {
  }
  loggingIn=false;
}

Fixed version (ground truth):
@InternalUseOnly public void resumeLogin(){
  if (!loggingIn)   return;
  connection.sendPacket(PacketPlayOutStatistics.DEFAULT_STATISTIC);
  sendChunks(7);
  connection.sendPacket(new PacketPlayOutPlayerCompleteMove().set("String_Node_Str",location()).set("String_Node_Str",(byte)0));
  TridentWindow window=new TridentWindow("String_Node_Str",9,InventoryType.CHEST);
  window.setSlot(0,new Item(Substance.DIAMOND_PICKAXE));
  window.sendTo(this);
  for (  Entity entity : world().entities()) {
  }
  loggingIn=false;
}
Program: 11827
Project: 11827
Buggy source:
@Override public void tick(){
  this.executor.execute(new Runnable(){
    @Override public void run(){
      TridentPlayer.super.tick();
      if (!chunkQueue.isEmpty())       connection.sendPacket(chunkQueue.poll());
      connection.tick();
      ticksExisted.incrementAndGet();
    }
  }
);
}

Fixed version (ground truth):
@Override public void tick(){
  this.executor.execute(new Runnable(){
    @Override public void run(){
      TridentPlayer.super.tick();
      if (!isLoggingIn())       sendChunks(7);
      if (!chunkQueue.isEmpty())       connection.sendPacket(chunkQueue.poll());
      connection.tick();
      ticksExisted.incrementAndGet();
    }
  }
);
}
Program: 11828
Project: 11828
Buggy source:
public static Player spawnPlayer(ClientConnection connection,UUID id){
  CompoundTag offlinePlayer=(OfflinePlayer.getOfflinePlayer(id) == null) ? null : OfflinePlayer.getOfflinePlayer(id).asNbt();
  if (offlinePlayer == null) {
    offlinePlayer=OfflinePlayer.generatePlayer(id);
  }
  final TridentPlayer p=TridentEntityBuilder.create().uuid(id).spawn(TridentServer.WORLD.spawnLocation()).executor(ThreadsHandler.playerExecutor()).build(TridentPlayer.class,ParameterValue.from(CompoundTag.class,offlinePlayer),ParameterValue.from(TridentWorld.class,TridentServer.WORLD),ParameterValue.from(ClientConnection.class,connection));
  p.executor.execute(new Runnable(){
    @Override public void run(){
      p.connection.sendPacket(new PacketPlayOutJoinGame().set("String_Node_Str",p.entityId()).set("String_Node_Str",GameMode.CREATIVE).set("String_Node_Str",p.world().dimension()).set("String_Node_Str",p.world().difficulty()).set("String_Node_Str",(short)10).set("String_Node_Str",LevelType.DEFAULT));
      p.connection.sendPacket(PacketPlayOutPluginMessage.VANILLA_CHANNEL);
      p.connection.sendPacket(new PacketPlayOutServerDifficulty().set("String_Node_Str",p.world().difficulty()));
      p.connection.sendPacket(new PacketPlayOutSpawnPosition().set("String_Node_Str",p.getSpawnLocation()));
      p.connection.sendPacket(p.abilities.asPacket());
      p.connection.sendPacket(new PacketPlayOutPlayerCompleteMove().set("String_Node_Str",p.getSpawnLocation().add(new Vector(0,80,0))).set("String_Node_Str",(byte)0));
    }
  }
);
  return p;
}

Fixed version (ground truth):
public static Player spawnPlayer(ClientConnection connection,UUID id){
  CompoundTag offlinePlayer=(OfflinePlayer.getOfflinePlayer(id) == null) ? null : OfflinePlayer.getOfflinePlayer(id).asNbt();
  if (offlinePlayer == null) {
    offlinePlayer=OfflinePlayer.generatePlayer(id);
  }
  final TridentPlayer p=TridentEntityBuilder.create().uuid(id).spawn(TridentServer.WORLD.spawnLocation()).executor(ThreadsHandler.playerExecutor()).build(TridentPlayer.class,ParameterValue.from(CompoundTag.class,offlinePlayer),ParameterValue.from(TridentWorld.class,TridentServer.WORLD),ParameterValue.from(ClientConnection.class,connection));
  p.executor.execute(new Runnable(){
    @Override public void run(){
      p.connection.sendPacket(new PacketPlayOutJoinGame().set("String_Node_Str",p.entityId()).set("String_Node_Str",GameMode.CREATIVE).set("String_Node_Str",p.world().dimension()).set("String_Node_Str",p.world().difficulty()).set("String_Node_Str",(short)10).set("String_Node_Str",LevelType.DEFAULT));
      p.connection.sendPacket(PacketPlayOutPluginMessage.VANILLA_CHANNEL);
      p.connection.sendPacket(new PacketPlayOutServerDifficulty().set("String_Node_Str",p.world().difficulty()));
      p.connection.sendPacket(new PacketPlayOutSpawnPosition().set("String_Node_Str",p.getSpawnLocation()));
      p.connection.sendPacket(p.abilities.asPacket());
      p.connection.sendPacket(new PacketPlayOutPlayerCompleteMove().set("String_Node_Str",p.getSpawnLocation()).set("String_Node_Str",(byte)0));
    }
  }
);
  return p;
}
Program: 11829
Project: 11829
Buggy source:
public void sendChunks(int viewDistance){
  int centX=((int)Math.floor(loc.getX())) >> 4;
  int centZ=((int)Math.floor(loc.getZ())) >> 4;
  PacketPlayOutMapChunkBulk bulk=new PacketPlayOutMapChunkBulk();
  int length=0;
  for (int x=(centX - viewDistance / 2); x <= (centX + viewDistance / 2); x+=1) {
    for (int z=(centZ - viewDistance / 2); z <= (centZ + viewDistance / 2); z+=1) {
      ChunkLocation location=ChunkLocation.create(x,z);
      if (knownChunks.contains(location))       continue;
      PacketPlayOutChunkData data=((TridentChunk)world().chunkAt(x,z,true)).asPacket();
      length+=(10 + data.getData().length);
      bulk.addEntry(data);
      knownChunks.add(location);
      if (length >= 0x1DAE40) {
        connection.sendPacket(bulk);
        bulk=new PacketPlayOutMapChunkBulk();
        length=0;
      }
    }
  }
  connection.sendPacket(bulk);
}

Fixed version (ground truth):
public void sendChunks(int viewDistance){
  int centX=((int)Math.floor(loc.getX())) >> 4;
  int centZ=((int)Math.floor(loc.getZ())) >> 4;
  PacketPlayOutMapChunkBulk bulk=new PacketPlayOutMapChunkBulk();
  int length=0;
  int chunks=0;
  for (int x=(centX - viewDistance / 2); x <= (centX + viewDistance / 2); x+=1) {
    for (int z=(centZ - viewDistance / 2); z <= (centZ + viewDistance / 2); z+=1) {
      ChunkLocation location=ChunkLocation.create(x,z);
      boolean contains=false;
      for (      ChunkLocation loc : knownChunks) {
        if (loc.equals(location)) {
          contains=true;
          break;
        }
      }
      if (contains) {
        continue;
      }
      PacketPlayOutChunkData data=((TridentChunk)world().chunkAt(x,z,true)).asPacket();
      knownChunks.add(location);
      bulk.addEntry(data);
      length+=(10 + data.getData().length);
      if (length >= 0x1DAE40) {
        connection.sendPacket(bulk);
        bulk=new PacketPlayOutMapChunkBulk();
        length=0;
      }
      chunks++;
    }
  }
  if (bulk.hasEntries())   connection.sendPacket(bulk);
}
Program: 11831
Project: 11831
Buggy source:
@Override protected void decode(ChannelHandlerContext context,ByteBuf buf,List<Object> objects) throws Exception {
  boolean compressed=connection.isCompressionEnabled();
  int fullLength=-1;
  if (compressed) {
    fullLength=Codec.readVarInt32(buf);
  }
  this.rawLength=Codec.readVarInt32(buf);
  if (rawLength == 0)   compressed=false;
  if (!(compressed) && rawLength < TridentServer.instance().getCompressionThreshold()) {
    ByteBuf data=buf.readBytes((fullLength == -1) ? rawLength : (fullLength - Codec.sizeOf(0)));
    objects.add(new PacketData(data));
    return;
  }
  byte[] compressedData=new byte[buf.readableBytes()];
  byte[] decompressed=new byte[rawLength];
  buf.readBytes(compressedData);
  inflater.setInput(compressedData);
  inflater.inflate(decompressed);
  objects.add(new PacketData(Unpooled.wrappedBuffer(decompressed)));
  inflater.reset();
}

Fixed version (ground truth):
@Override protected void decode(ChannelHandlerContext context,ByteBuf buf,List<Object> objects) throws Exception {
  boolean compressed=connection.isCompressionEnabled();
  int fullLength=-1;
  if (compressed) {
    fullLength=Codec.readVarInt32(buf);
  }
  this.rawLength=Codec.readVarInt32(buf);
  if (rawLength == 0)   compressed=false;
  if (!(compressed) || rawLength < TridentServer.instance().getCompressionThreshold()) {
    ByteBuf data=buf.readBytes((fullLength == -1) ? rawLength : (fullLength - Codec.sizeOf(0)));
    objects.add(new PacketData(data));
    return;
  }
  byte[] compressedData=new byte[buf.readableBytes()];
  byte[] decompressed=new byte[rawLength];
  buf.readBytes(compressedData);
  inflater.setInput(compressedData);
  inflater.inflate(decompressed);
  objects.add(new PacketData(Unpooled.wrappedBuffer(decompressed)));
  inflater.reset();
}
Program: 11832
Project: 11832
Buggy source:
@Override protected void encode(ChannelHandlerContext channelHandlerContext,ByteBuf msg,ByteBuf out) throws Exception {
  int threshold=TridentServer.instance().getCompressionThreshold();
  boolean underThreshold=msg.readableBytes() < threshold && threshold != -1;
  if (underThreshold && connection.isCompressionEnabled()) {
    sendDecompressed(msg,out);
  }
 else   if (!(underThreshold) && connection.isCompressionEnabled()) {
    sendCompressed(msg,out);
  }
 else {
    Codec.writeVarInt32(out,msg.readableBytes());
    out.writeBytes(msg);
  }
  Files.write(Paths.get("String_Node_Str"),Arrays.asList(DatatypeConverter.printHexBinary(Codec.asArray(out.copy()))),Charset.defaultCharset());
}

Fixed version (ground truth):
@Override protected void encode(ChannelHandlerContext channelHandlerContext,ByteBuf msg,ByteBuf out) throws Exception {
  int threshold=TridentServer.instance().getCompressionThreshold();
  boolean underThreshold=msg.readableBytes() < threshold && threshold != -1;
  if (underThreshold && connection.isCompressionEnabled()) {
    sendDecompressed(msg,out);
  }
 else   if (!(underThreshold) && connection.isCompressionEnabled()) {
    sendCompressed(msg,out);
  }
 else {
    Codec.writeVarInt32(out,msg.readableBytes());
    out.writeBytes(msg);
  }
}
Program: 11833
Project: 11833
Buggy source:
/** 
 * Converts the PacketData to a Packet depending on the ConnectionStage of the Client    {@inheritDoc}
 */
@Override protected void messageReceived(ChannelHandlerContext context,PacketData data) throws Exception {
  if (this.connection.isEncryptionEnabled()) {
    data.decrypt(this.connection);
  }
  Packet packet=this.protocol.getPacket(data.getId(),this.connection.getStage(),PacketDirection.IN);
  if (packet.getId() == -1) {
    this.connection.logout();
    return;
  }
  TridentLogger.log("String_Node_Str" + packet.getClass().getSimpleName().replaceAll("String_Node_Str","String_Node_Str").replaceAll("String_Node_Str","String_Node_Str"));
  packet.decode(data.getData());
  try {
    packet.handleReceived(this.connection);
    if (connection instanceof PlayerConnection) {
      ((PlayerConnection)connection).resetReadCounter();
    }
  }
 catch (  Exception ex) {
    TridentLogger.error(ex);
switch (this.connection.getStage()) {
case LOGIN:
      PacketLoginOutDisconnect disconnect=new PacketLoginOutDisconnect();
    disconnect.setJsonMessage(ex.getMessage());
  this.connection.sendPacket(disconnect);
this.connection.logout();
case PLAY:
PacketPlayOutDisconnect quit=new PacketPlayOutDisconnect();
quit.set("String_Node_Str","String_Node_Str" + ex.getClass().getName() + ((ex.getMessage() != null) ? "String_Node_Str" + ex.getMessage() : "String_Node_Str")+ "String_Node_Str");
this.connection.sendPacket(quit);
this.connection.logout();
default :
break;
}
}
}

Fixed version (ground truth):
/** 
 * Converts the PacketData to a Packet depending on the ConnectionStage of the Client    {@inheritDoc}
 */
@Override protected void messageReceived(ChannelHandlerContext context,PacketData data) throws Exception {
  if (this.connection.isEncryptionEnabled()) {
    data.decrypt(this.connection);
  }
  Packet packet=this.protocol.getPacket(data.getId(),this.connection.getStage(),PacketDirection.IN);
  if (packet.getId() == -1) {
    this.connection.logout();
    return;
  }
  if (!(packet instanceof PacketPlayInPlayerMove)) {
    TridentLogger.log("String_Node_Str" + packet.getClass().getSimpleName().replaceAll("String_Node_Str","String_Node_Str").replaceAll("String_Node_Str","String_Node_Str"));
  }
  packet.decode(data.getData());
  try {
    packet.handleReceived(this.connection);
    if (connection instanceof PlayerConnection) {
      ((PlayerConnection)connection).resetReadCounter();
    }
  }
 catch (  Exception ex) {
    TridentLogger.error(ex);
switch (this.connection.getStage()) {
case LOGIN:
      PacketLoginOutDisconnect disconnect=new PacketLoginOutDisconnect();
    disconnect.setJsonMessage(ex.getMessage());
  this.connection.sendPacket(disconnect);
this.connection.logout();
case PLAY:
PacketPlayOutDisconnect quit=new PacketPlayOutDisconnect();
quit.set("String_Node_Str","String_Node_Str" + ex.getClass().getName() + ((ex.getMessage() != null) ? "String_Node_Str" + ex.getMessage() : "String_Node_Str")+ "String_Node_Str");
this.connection.sendPacket(quit);
this.connection.logout();
default :
break;
}
}
}
Program: 11834
Project: 11834
Buggy source:
@Override public void tick(){
  this.executor.execute(new Runnable(){
    @Override public void run(){
      TridentPlayer.super.tick();
      sendChunks(TridentServer.instance().viewDistance());
      connection.tick();
      ticksExisted.incrementAndGet();
    }
  }
);
}

Fixed version (ground truth):
@Override public void tick(){
  this.executor.execute(new Runnable(){
    @Override public void run(){
      TridentPlayer.super.tick();
      if (!chunkQueue.isEmpty())       connection.sendPacket(chunkQueue.poll());
      connection.tick();
      ticksExisted.incrementAndGet();
    }
  }
);
}
Program: 11835
Project: 11835
Buggy source:
public void sendChunks(int viewDistance){
  int centX=((int)Math.floor(loc.getX())) >> 4;
  int centZ=((int)Math.floor(loc.getZ())) >> 4;
  PacketPlayOutMapChunkBulk bulk=new PacketPlayOutMapChunkBulk();
  int length=0;
  for (int x=(centX - (int)Math.floor(viewDistance / 2)); x <= (centX + (int)Math.floor(viewDistance / 2)); x+=1) {
    for (int z=(centZ - (int)Math.floor(viewDistance / 2)); z <= (centZ + (int)Math.floor(viewDistance / 2)); z+=1) {
      ChunkLocation location=ChunkLocation.create(x,z);
      if (knownChunks.contains(location))       continue;
      PacketPlayOutChunkData data=((TridentChunk)world().chunkAt(x,z,true)).asPacket();
      length+=(10 + data.getData().length);
      bulk.addEntry(data);
      knownChunks.add(location);
      if (length >= 0x1DAE40) {
        connection.sendPacket(bulk);
        bulk=new PacketPlayOutMapChunkBulk();
        length=0;
      }
    }
  }
  connection.sendPacket(bulk);
}

Fixed version (ground truth):
public void sendChunks(int viewDistance){
  int centX=((int)Math.floor(loc.getX())) >> 4;
  int centZ=((int)Math.floor(loc.getZ())) >> 4;
  PacketPlayOutMapChunkBulk bulk=new PacketPlayOutMapChunkBulk();
  int length=0;
  for (int x=(centX - viewDistance / 2); x <= (centX + viewDistance / 2); x+=1) {
    for (int z=(centZ - viewDistance / 2); z <= (centZ + viewDistance / 2); z+=1) {
      ChunkLocation location=ChunkLocation.create(x,z);
      if (knownChunks.contains(location))       continue;
      PacketPlayOutChunkData data=((TridentChunk)world().chunkAt(x,z,true)).asPacket();
      length+=(10 + data.getData().length);
      bulk.addEntry(data);
      knownChunks.add(location);
      if (length >= 0x1DAE40) {
        connection.sendPacket(bulk);
        bulk=new PacketPlayOutMapChunkBulk();
        length=0;
      }
    }
  }
  connection.sendPacket(bulk);
}
Program: 11837
Project: 11837
Buggy source:
/** 
 * Gets the location of the raw offset of the chunk
 * @param c chunk
 * @return offsetLoc in bytes
 */
private int getOffsetLoc(Chunk c){
  return mod(c.getX()) + mod(c.getZ()) * 32;
}

Fixed version (ground truth):
/** 
 * Gets the location of the raw offset of the chunk
 * @param c chunk
 * @return offsetLoc in bytes
 */
private int getOffsetLoc(Chunk c){
  return (c.getX() & 31) + (c.getZ() & 31) * 32;
}
Program: 11838
Project: 11838
Buggy source:
public PacketPlayOutChunkData asPacket(){
  PacketPlayOutChunkData packet=new PacketPlayOutChunkData();
  int bitmask=(1 << sections.length) - 1;
  int count=sections.length;
  int size=0;
  int sectionSize=ChunkSection.LENGTH * 5 / 2;
  if (world.dimension() == Dimension.OVERWORLD)   sectionSize+=ChunkSection.LENGTH / 2;
  size+=count * sectionSize + 256;
  for (  ChunkSection section : sections) {
    if (section == null)     continue;
    for (    byte b : section.getTypes()) {
      data.write(b & 0xff);
      data.write(b >> 8);
    }
  }
  for (  ChunkSection section : sections) {
    try {
      data.write(section.blockLight);
    }
 catch (    IOException e) {
      TridentLogger.error(e);
    }
  }
  for (  ChunkSection section : sections) {
    try {
      data.write(section.skyLight);
    }
 catch (    IOException e) {
      TridentLogger.error(e);
    }
  }
  for (int i=0; i < 256; i+=1) {
    data.write(0);
  }
  packet.set("String_Node_Str",location);
  packet.set("String_Node_Str",(short)bitmask);
  packet.set("String_Node_Str",data.toByteArray());
  data.reset();
  return packet;
}

Fixed version (ground truth):
public PacketPlayOutChunkData asPacket(){
  PacketPlayOutChunkData packet=new PacketPlayOutChunkData();
  if (sections == null) {
    try {
      RegionFile.fromPath(world.name(),location).loadChunkData(this);
    }
 catch (    Exception e) {
      TridentLogger.error(e);
    }
  }
  int bitmask=(1 << sections.length) - 1;
  int count=sections.length;
  int size=0;
  int sectionSize=ChunkSection.LENGTH * 5 / 2;
  if (world.dimension() == Dimension.OVERWORLD)   sectionSize+=ChunkSection.LENGTH / 2;
  size+=count * sectionSize + 256;
  for (  ChunkSection section : sections) {
    if (section == null)     continue;
    for (    byte b : section.getTypes()) {
      data.write(b & 0xff);
      data.write(b >> 8);
    }
  }
  for (  ChunkSection section : sections) {
    try {
      data.write(section.blockLight);
    }
 catch (    IOException e) {
      TridentLogger.error(e);
    }
  }
  for (  ChunkSection section : sections) {
    try {
      data.write(section.skyLight);
    }
 catch (    IOException e) {
      TridentLogger.error(e);
    }
  }
  for (int i=0; i < 256; i+=1) {
    data.write(0);
  }
  packet.set("String_Node_Str",location);
  packet.set("String_Node_Str",(short)bitmask);
  packet.set("String_Node_Str",data.toByteArray());
  data.reset();
  return packet;
}
Program: 11841
Project: 11841
Buggy source:
@Override public void handleReceived(ClientConnection connection){
  TridentPlayer player=((PlayerConnection)connection).player();
  DigStatus digStatus=DigStatus.getStatus(this.status);
  BlockOrientation face=null;
  MassChange change=new DefaultMassChange(player.world());
  for (int y=(int)player.location().y() + 2; y < 50; y++) {
    change.setBlock((int)player.location().x(),y,(int)player.location().z(),Substance.DIRT);
  }
  change.commitChanges();
  TridentLogger.log("String_Node_Str");
switch (this.blockFace) {
case 0:
    face=BlockOrientation.BOTTOM;
  break;
case 1:
face=BlockOrientation.TOP;
break;
case 2:
break;
case 3:
break;
case 4:
break;
case 5:
break;
default :
TridentLogger.error(new IllegalArgumentException("String_Node_Str"));
}
Cancellable event=null;
switch (digStatus) {
case DIG_START:
case DIG_CANCEL:
case DIG_FINISH:
event=new PlayerDigEvent(player,face,this.status);
break;
case DROP_ITEMSTACK:
event=new PlayerDropItemEvent(player,null);
break;
case DROP_ITEM:
event=new PlayerDropItemEvent(player,null);
break;
case SHOOT_ARROW:
break;
}
TridentServer.instance().eventHandler().fire((Event)event);
if (event == null || event.isIgnored()) return;
this.location.setWorld(player.world());
}

Fixed version (ground truth):
@Override public void handleReceived(ClientConnection connection){
  TridentPlayer player=((PlayerConnection)connection).player();
  DigStatus digStatus=DigStatus.getStatus(this.status);
  BlockOrientation face=null;
switch (this.blockFace) {
case 0:
    face=BlockOrientation.BOTTOM;
  break;
case 1:
face=BlockOrientation.TOP;
break;
case 2:
break;
case 3:
break;
case 4:
break;
case 5:
break;
default :
TridentLogger.error(new IllegalArgumentException("String_Node_Str"));
}
Cancellable event=null;
switch (digStatus) {
case DIG_START:
case DIG_CANCEL:
case DIG_FINISH:
event=new PlayerDigEvent(player,face,this.status);
break;
case DROP_ITEMSTACK:
event=new PlayerDropItemEvent(player,null);
break;
case DROP_ITEM:
event=new PlayerDropItemEvent(player,null);
break;
case SHOOT_ARROW:
break;
}
TridentServer.instance().eventHandler().fire((Event)event);
if (event == null || event.isIgnored()) return;
this.location.setWorld(player.world());
}
Program: 11842
Project: 11842
Buggy source:
@InternalUseOnly public void resumeLogin(){
  if (!loggingIn)   return;
  connection.sendPacket(PacketPlayOutStatistics.DEFAULT_STATISTIC);
  sendChunks(TridentServer.instance().viewDistance());
  connection.sendPacket(new PacketPlayOutPlayerCompleteMove().set("String_Node_Str",location()).set("String_Node_Str",(byte)0));
  TridentWindow window=new TridentWindow("String_Node_Str",9,InventoryType.CHEST);
  window.setSlot(0,new Item(Substance.DIAMOND_PICKAXE));
  window.sendTo(this);
  for (  Entity entity : world().entities()) {
  }
  loggingIn=false;
}

Fixed version (ground truth):
@InternalUseOnly public void resumeLogin(){
  if (!loggingIn)   return;
  connection.sendPacket(PacketPlayOutStatistics.DEFAULT_STATISTIC);
  sendChunks(TridentServer.instance().viewDistance());
  connection.sendPacket(new PacketPlayOutPlayerCompleteMove().set("String_Node_Str",location()).set("String_Node_Str",(byte)1));
  TridentWindow window=new TridentWindow("String_Node_Str",9,InventoryType.CHEST);
  window.setSlot(0,new Item(Substance.DIAMOND_PICKAXE));
  window.sendTo(this);
  for (  Entity entity : world().entities()) {
  }
  loggingIn=false;
  connection.sendPacket(new PacketPlayOutEntityVelocity().set("String_Node_Str",entityId()).set("String_Node_Str",new Vector(0,-0.1,0)));
}
Program: 11843
Project: 11843
Buggy source:
public static Player spawnPlayer(ClientConnection connection,UUID id){
  CompoundTag offlinePlayer=(OfflinePlayer.getOfflinePlayer(id) == null) ? null : OfflinePlayer.getOfflinePlayer(id).asNbt();
  if (offlinePlayer == null) {
    offlinePlayer=OfflinePlayer.generatePlayer(id);
  }
  final TridentPlayer p=TridentEntityBuilder.create().uuid(id).spawn(TridentServer.WORLD.spawnLocation()).executor(ThreadsHandler.playerExecutor()).build(TridentPlayer.class,ParameterValue.from(CompoundTag.class,offlinePlayer),ParameterValue.from(TridentWorld.class,TridentServer.WORLD),ParameterValue.from(ClientConnection.class,connection));
  p.executor.execute(new Runnable(){
    @Override public void run(){
      p.connection.sendPacket(new PacketPlayOutJoinGame().set("String_Node_Str",p.entityId()).set("String_Node_Str",GameMode.CREATIVE).set("String_Node_Str",p.world().dimension()).set("String_Node_Str",p.world().difficulty()).set("String_Node_Str",(short)10).set("String_Node_Str",LevelType.DEFAULT));
      p.connection.sendPacket(PacketPlayOutPluginMessage.VANILLA_CHANNEL);
      p.connection.sendPacket(new PacketPlayOutServerDifficulty().set("String_Node_Str",p.world().difficulty()));
      p.connection.sendPacket(new PacketPlayOutSpawnPosition().set("String_Node_Str",p.spawnLocation()));
      p.connection.sendPacket(p.abilities.asPacket());
      p.connection.sendPacket(new PacketPlayOutPlayerCompleteMove().set("String_Node_Str",p.spawnLocation()).set("String_Node_Str",(byte)0));
    }
  }
);
  return p;
}

Fixed version (ground truth):
public static Player spawnPlayer(ClientConnection connection,UUID id){
  CompoundTag offlinePlayer=(OfflinePlayer.getOfflinePlayer(id) == null) ? null : OfflinePlayer.getOfflinePlayer(id).asNbt();
  if (offlinePlayer == null) {
    offlinePlayer=OfflinePlayer.generatePlayer(id);
  }
  final TridentPlayer p=TridentEntityBuilder.create().uuid(id).spawn(TridentServer.WORLD.spawnLocation()).executor(ThreadsHandler.playerExecutor()).build(TridentPlayer.class,ParameterValue.from(CompoundTag.class,offlinePlayer),ParameterValue.from(TridentWorld.class,TridentServer.WORLD),ParameterValue.from(ClientConnection.class,connection));
  p.executor.execute(new Runnable(){
    @Override public void run(){
      p.connection.sendPacket(new PacketPlayOutJoinGame().set("String_Node_Str",p.entityId()).set("String_Node_Str",GameMode.CREATIVE).set("String_Node_Str",p.world().dimension()).set("String_Node_Str",p.world().difficulty()).set("String_Node_Str",(short)10).set("String_Node_Str",LevelType.DEFAULT));
      p.connection.sendPacket(PacketPlayOutPluginMessage.VANILLA_CHANNEL);
      p.connection.sendPacket(new PacketPlayOutServerDifficulty().set("String_Node_Str",p.world().difficulty()));
      p.connection.sendPacket(new PacketPlayOutSpawnPosition().set("String_Node_Str",p.spawnLocation()));
      p.connection.sendPacket(p.abilities.asPacket());
      p.connection.sendPacket(new PacketPlayOutPlayerCompleteMove().set("String_Node_Str",p.spawnLocation()).set("String_Node_Str",(byte)1));
    }
  }
);
  return p;
}
Program: 11845
Project: 11845
Buggy source:
@Override public TridentChunk generateChunk(ChunkLocation location){
  if (location == null) {
    TridentLogger.error(new NullPointerException("String_Node_Str"));
    return null;
  }
  int x=location.x();
  int z=location.z();
  if (x > MAX_CHUNKS || x < -MAX_CHUNKS) {
    return null;
  }
  if (z > MAX_CHUNKS || z < -MAX_CHUNKS) {
    return null;
  }
  if (this.chunkAt(location,false) == null) {
    if (this.loader.chunkExists(this,x,z)) {
      this.addChunkAt(location,this.loader.loadChunk(this,x,z));
    }
 else {
      TridentChunk chunk=new TridentChunk(this,x,z);
      this.addChunkAt(location,chunk);
      chunk.generate();
    }
  }
  return this.chunkAt(location,false);
}

Fixed version (ground truth):
@Override public TridentChunk generateChunk(ChunkLocation location){
  if (location == null) {
    TridentLogger.error(new NullPointerException("String_Node_Str"));
    return null;
  }
  int x=location.x();
  int z=location.z();
  if (x > MAX_CHUNKS || x < -MAX_CHUNKS) {
    return null;
  }
  if (z > MAX_CHUNKS || z < -MAX_CHUNKS) {
    return null;
  }
  if (this.chunkAt(location,false) == null) {
    Chunk c=this.loader.loadChunk(this,x,z);
    if (this.loader.chunkExists(this,x,z) && c != null) {
      this.addChunkAt(location,c);
      return (TridentChunk)c;
    }
 else {
      TridentChunk chunk=new TridentChunk(this,x,z);
      this.addChunkAt(location,chunk);
      chunk.generate();
      TridentLogger.log("String_Node_Str" + x + "String_Node_Str"+ z+ "String_Node_Str");
      return chunk;
    }
  }
  return this.chunkAt(location,false);
}
Program: 11846
Project: 11846
Buggy source:
public void stop(){
  taskExecutor.shutdown();
}

Fixed version (ground truth):
public void stop(){
  taskExecutor.shutdown();
  taskList.clear();
}
Program: 11848
Project: 11848
Buggy source:
private ConcurrentTaskExecutor(int scale){
  this.scale=scale;
  executors=new AtomicReferenceArray<>(scale + EMERGENCY_MARGIN);
  for (int i=0; i < scale; i++) {
    executors.set(i,new ThreadWorker(i).startWorker());
  }
  state=RUNNING;
}

Fixed version (ground truth):
private ConcurrentTaskExecutor(int scale,String name){
  this.scale=scale;
  this.name=name;
  executors=new AtomicReferenceArray<>(scale + EMERGENCY_MARGIN);
  for (int i=0; i < scale; i++) {
    executors.set(i,new ThreadWorker(i,name).startWorker());
  }
  state=RUNNING;
}
Program: 11849
Project: 11849
Buggy source:
@Override public void run(){
  while (!isInterrupted()) {
    try {
      Runnable task=tasks.take();
      task.run();
      int cycles=0;
      while (tasks.peek() == null)       if (cycles++ == 1024) {
        interrupt();
        break;
      }
    }
 catch (    InterruptedException e) {
      return;
    }
catch (    Exception e) {
      TridentLogger.error(e);
      handleShutdown(((ThreadWorker)scaledThread()).index,tasks);
      return;
    }
  }
  emergencyScale.decrementAndGet();
}

Fixed version (ground truth):
@Override public void run(){
  while (!isInterrupted()) {
    try {
      Runnable task=tasks.take();
      task.run();
      int cycles=0;
      while (tasks.peek() == null) {
        Thread.yield();
        if (cycles++ == 1024) {
          interrupt();
          break;
        }
      }
    }
 catch (    InterruptedException e) {
      return;
    }
catch (    Exception e) {
      TridentLogger.error(e);
      handleShutdown(((ThreadWorker)scaledThread()).index,tasks);
      return;
    }
  }
  emergencyScale.decrementAndGet();
}
Program: 11850
Project: 11850
Buggy source:
private OverflowWorker(int index){
  super(index);
}

Fixed version (ground truth):
private OverflowWorker(int index){
  super(index,name + "String_Node_Str");
}
Program: 11851
Project: 11851
Buggy source:
/** 
 * Create a new executor using the number of threads to scale
 * @param scale the threads to use
 * @return a new concurrent task executor pool
 */
public static <E>ConcurrentTaskExecutor<E> create(int scale){
  ConcurrentTaskExecutor<E> executor=new ConcurrentTaskExecutor<>(scale);
  EXECUTORS.add(executor);
  return executor;
}

Fixed version (ground truth):
/** 
 * Create a new executor using the number of threads to scale
 * @param scale the threads to use
 * @return a new concurrent task executor pool
 */
public static <E>ConcurrentTaskExecutor<E> create(int scale,String name){
  ConcurrentTaskExecutor<E> executor=new ConcurrentTaskExecutor<>(scale,name);
  EXECUTORS.add(executor);
  return executor;
}
Program: 11852
Project: 11852
Buggy source:
private ThreadWorker(int index){
  this.index=index;
}

Fixed version (ground truth):
private ThreadWorker(int index,String name){
  super("String_Node_Str" + EXECUTORS.size() + "String_Node_Str"+ index+ "String_Node_Str"+ name);
  this.index=index;
}
Program: 11853
Project: 11853
Buggy source:
private static int calcTaskLen(){
  int objectSize=4;
  if (ARCH_64)   objectSize=8;
  long max=(Runtime.getRuntime().freeMemory() / objectSize) / 13;
  int len;
  if (max > (long)Integer.MAX_VALUE)   len=Integer.MAX_VALUE - 8;
 else   len=(int)max;
  return len;
}

Fixed version (ground truth):
private static int calcTaskLen(){
  int objectSize=4;
  if (ARCH_64)   objectSize=8;
  long max=(Runtime.getRuntime().freeMemory() / objectSize) / 15;
  int len;
  if (max > (long)Integer.MAX_VALUE)   len=Integer.MAX_VALUE - 8;
 else   len=(int)max;
  return len;
}
Program: 11854
Project: 11854
Buggy source:
public void handleShutdown(int index,Queue<Runnable> remaining){
  if (state < SHUTTING_DOWN) {
    if (index > this.scale) {
      executors.set(index,new OverflowWorker(index).startWorker(remaining));
    }
 else     executors.set(index,new ThreadWorker(index).startWorker(remaining));
  }
 else   executors.set(index,null);
  remaining.clear();
}

Fixed version (ground truth):
public void handleShutdown(int index,Queue<Runnable> remaining){
  if (state < SHUTTING_DOWN) {
    if (index > this.scale) {
      executors.set(index,new OverflowWorker(index).startWorker(remaining));
    }
 else     executors.set(index,new ThreadWorker(index,name).startWorker(remaining));
  }
 else   executors.set(index,null);
  remaining.clear();
}
Program: 11855
Project: 11855
Buggy source:
/** 
 * Creates the MainThread runner from the amount of heartbeats the server should take per second the server runs
 * @param ticksPerSecond the amount of heartbeats per second
 */
public MainThread(int ticksPerSecond){
  this.zeroBase=System.currentTimeMillis();
  instance=this;
  this.ticksPerSecond=ticksPerSecond;
  this.tickLength=1000 / ticksPerSecond;
}

Fixed version (ground truth):
/** 
 * Creates the MainThread runner from the amount of heartbeats the server should take per second the server runs
 * @param ticksPerSecond the amount of heartbeats per second
 */
public MainThread(int ticksPerSecond){
  super("String_Node_Str");
  this.zeroBase=System.currentTimeMillis();
  instance=this;
  this.ticksPerSecond=ticksPerSecond;
  this.tickLength=1000 / ticksPerSecond;
}
Program: 11856
Project: 11856
Buggy source:
/** 
 * Stops all the executors and clears all caches of concurrent threads
 */
@InternalUseOnly public static void stopAll(){
  BackgroundTaskExecutor.SERVICE.shutdownNow();
  MainThread.getInstance().interrupt();
  entityExecutor().shutdown();
  playerExecutor().shutdown();
  worldExecutor().shutdown();
}

Fixed version (ground truth):
/** 
 * Stops all the executors and clears all caches of concurrent threads
 */
@InternalUseOnly public static void stopAll(){
  MainThread.getInstance().interrupt();
  entityExecutor().shutdown();
  playerExecutor().shutdown();
  worldExecutor().shutdown();
}
Program: 11857
Project: 11857
Buggy source:
@Override public <T>ExecutorFactory<T> executor(int threads){
  return ConcurrentTaskExecutor.create(threads);
}

Fixed version (ground truth):
@Override public <T>ExecutorFactory<T> executor(int threads,String name){
  return ConcurrentTaskExecutor.create(threads,name);
}
Program: 11858
Project: 11858
Buggy source:
public PacketPlayOutMapChunkBulk asPacket(){
  PacketPlayOutMapChunkBulk chunkBulk=new PacketPlayOutMapChunkBulk();
  int bitmask=(1 << sections.length) - 1;
  int count=sections.length;
  int size=0;
  int sectionSize=ChunkSection.LENGTH * 5 / 2;
  if (world.dimension() == Dimension.OVERWORLD)   sectionSize+=ChunkSection.LENGTH / 2;
  size+=count * sectionSize + 256;
  byte[] data=new byte[size];
  int pos=0;
  for (  ChunkSection section : sections) {
    for (    byte b : section.getTypes()) {
      data[pos++]=(byte)(b & 0xff);
      data[pos++]=(byte)(b >> 8);
    }
  }
  for (  ChunkSection section : sections) {
    System.arraycopy(section.blockLight,0,data,pos,section.blockLight.length);
    pos+=section.blockLight.length;
  }
  for (int i=0; i < 256; i+=1) {
    data[pos++]=0;
  }
  chunkBulk.set("String_Node_Str",new ChunkMetaBuilder().bitmap((short)bitmask).location(location));
  chunkBulk.set("String_Node_Str",data);
  chunkBulk.set("String_Node_Str",true);
  chunkBulk.set("String_Node_Str",sections.length);
  return chunkBulk;
}

Fixed version (ground truth):
public PacketPlayOutMapChunkBulk asPacket(){
  PacketPlayOutMapChunkBulk chunkBulk=new PacketPlayOutMapChunkBulk();
  int bitmask=(1 << sections.length) - 1;
  int count=sections.length;
  int size=0;
  int sectionSize=ChunkSection.LENGTH * 5 / 2;
  if (world.dimension() == Dimension.OVERWORLD)   sectionSize+=ChunkSection.LENGTH / 2;
  size+=count * sectionSize + 256;
  byte[] data=new byte[size];
  int pos=0;
  for (  ChunkSection section : sections) {
    for (    byte b : section.getTypes()) {
      data[pos++]=(byte)(b & 0xff);
      data[pos++]=(byte)(b >> 8);
    }
  }
  for (  ChunkSection section : sections) {
    System.arraycopy(section.blockLight,0,data,pos,section.blockLight.length);
    pos+=section.blockLight.length;
  }
  for (int i=0; i < 256; i+=1) {
    data[pos++]=0;
  }
  if (pos != size) {
    TridentLogger.error(new IllegalArgumentException("String_Node_Str" + pos + "String_Node_Str"+ size));
    return null;
  }
  chunkBulk.set("String_Node_Str",new ChunkMetaBuilder().bitmap((short)bitmask).location(location));
  chunkBulk.set("String_Node_Str",data);
  chunkBulk.set("String_Node_Str",true);
  chunkBulk.set("String_Node_Str",sections.length);
  return chunkBulk;
}
Program: 11859
Project: 11859
Buggy source:
@Override public void handleReceived(ClientConnection connection){
  TridentPlayer player=((PlayerConnection)connection).getPlayer();
  super.location.setWorld(player.getWorld());
  Cancellable event=new PlayerMoveEvent(player,player.getLocation(),super.location);
  if (event.isIgnored()) {
    PacketPlayOutEntityTeleport packet=new PacketPlayOutEntityTeleport();
    packet.set("String_Node_Str",player.getId());
    packet.set("String_Node_Str",player.getLocation());
    packet.set("String_Node_Str",player.isOnGround());
    connection.sendPacket(packet);
  }
}

Fixed version (ground truth):
@Override public void handleReceived(ClientConnection connection){
  TridentPlayer player=((PlayerConnection)connection).getPlayer();
  super.location.setWorld(player.getWorld());
  Cancellable event=new PlayerMoveEvent(player,player.getLocation(),super.location);
  if (event.isIgnored()) {
    PacketPlayOutEntityTeleport packet=new PacketPlayOutEntityTeleport();
    packet.set("String_Node_Str",player.getId());
    packet.set("String_Node_Str",player.getLocation());
    packet.set("String_Node_Str",player.isOnGround());
    connection.sendPacket(packet);
  }
  if (player.isLoggingIn())   player.resumeLogin();
}
Program: 11861
Project: 11861
Buggy source:
public void sendChunks(int viewDistance){
  int centX=((int)Math.floor(loc.getX())) >> 4;
  int centZ=((int)Math.floor(loc.getZ())) >> 4;
  PacketPlayOutMapChunkBulk bulk=new PacketPlayOutMapChunkBulk();
  int i=0;
  for (int x=(centX - (viewDistance / 2)); x <= (centX + (viewDistance / 2)); x+=1) {
    for (int z=(centZ - (viewDistance / 2)); z <= (centZ + (viewDistance / 2)); z+=1) {
      bulk.addEntry(((TridentChunk)getWorld().chunkAt(x,z,true)).asPacket());
      ++i;
      if (i >= 30) {
        connection.sendPacket(bulk);
        bulk=new PacketPlayOutMapChunkBulk();
        i=0;
      }
    }
  }
  connection.sendPacket(bulk);
}

Fixed version (ground truth):
public void sendChunks(int viewDistance){
  int centX=((int)Math.floor(loc.getX())) >> 4;
  int centZ=((int)Math.floor(loc.getZ())) >> 4;
  PacketPlayOutMapChunkBulk bulk=new PacketPlayOutMapChunkBulk();
  int i=0;
  for (int x=(centX - (int)Math.floor(viewDistance / 2)); x <= (centX + (int)Math.floor(viewDistance / 2)); x+=1) {
    for (int z=(centZ - (int)Math.floor(viewDistance / 2)); z <= (centZ + (int)Math.floor(viewDistance / 2)); z+=1) {
      bulk.addEntry(((TridentChunk)getWorld().chunkAt(x,z,true)).asPacket());
      ++i;
      if (i >= 30) {
        connection.sendPacket(bulk);
        bulk=new PacketPlayOutMapChunkBulk();
        i=0;
      }
    }
  }
  connection.sendPacket(bulk);
}
Program: 11862
Project: 11862
Buggy source:
/** 
 * Gets the location of the raw offset of the chunk
 * @param c chunk
 * @return offsetLoc in bytes
 */
private int getOffsetLoc(Chunk c){
  return c.getX() + c.getZ() * 32;
}

Fixed version (ground truth):
/** 
 * Gets the location of the raw offset of the chunk
 * @param c chunk
 * @return offsetLoc in bytes
 */
private int getOffsetLoc(Chunk c){
  return mod(c.getX()) + mod(c.getZ()) * 32;
}