nus-yam/ex-repair huggingface dataset:
Program: 59895
Project: 59895
Buggy source:
/** 
 * Adds a variation to this group.
 * @param variation An  {@link ICarvingVariation} to add to this group
 */
void addVariation(ICarvingVariation variation);

Fixed version (ground truth):
/** 
 * Adds a variation to this group. Do not call this from external code, as it will fail to remove the inverse lookup from the registry.
 * @param variation An  {@link ICarvingVariation} to add to this group
 */
void addVariation(ICarvingVariation variation);
Program: 59896
Project: 59896
Buggy source:
@Override public ICarvingVariation removeVariation(Block block,int metadata){
  ICarvingVariation toRemove=null;
  for (  ICarvingVariation v : variations) {
    if (v.getBlock() == block && v.getBlockMeta() == metadata) {
      toRemove=v;
    }
  }
  return toRemove == null ? null : variations.remove(toRemove) ? toRemove : null;
}

Fixed version (ground truth):
@Override public boolean removeVariation(ICarvingVariation variation){
  ICarvingVariation toRemove=null;
  for (  ICarvingVariation v : variations) {
    if (v.getBlock() == variation.getBlock() && v.getBlockMeta() == variation.getBlockMeta()) {
      toRemove=v;
    }
  }
  return toRemove == null ? false : variations.remove(toRemove);
}
Program: 59898
Project: 59898
Buggy source:
@EventHandler public void init(FMLInitializationEvent event){
  Features.init();
  NetworkRegistry.INSTANCE.registerGuiHandler(this,new ChiselGuiHandler());
  registerWorldgen(Features.MARBLE,ChiselBlocks.marble,Configurations.marbleAmount);
  registerWorldgen(Features.LIMESTONE,ChiselBlocks.limestone,Configurations.limestoneAmount);
  registerWorldgen(Features.ANDESITE,ChiselBlocks.andesite,Configurations.andesiteAmount);
  registerWorldgen(Features.GRANITE,ChiselBlocks.granite,Configurations.graniteAmount);
  registerWorldgen(Features.DIORITE,ChiselBlocks.diorite,Configurations.dioriteAmount);
  proxy.init();
  MinecraftForge.EVENT_BUS.register(this);
  FMLCommonHandler.instance().bus().register(instance);
  FMLInterModComms.sendMessage("String_Node_Str","String_Node_Str","String_Node_Str");
}

Fixed version (ground truth):
@EventHandler public void init(FMLInitializationEvent event){
  Features.init();
  NetworkRegistry.INSTANCE.registerGuiHandler(this,new ChiselGuiHandler());
  addWorldgen(Features.MARBLE,ChiselBlocks.marble,Configurations.marbleAmount);
  addWorldgen(Features.LIMESTONE,ChiselBlocks.limestone,Configurations.limestoneAmount);
  addWorldgen(Features.ANDESITE,ChiselBlocks.andesite,Configurations.andesiteAmount,40,100,0.5);
  addWorldgen(Features.GRANITE,ChiselBlocks.granite,Configurations.graniteAmount,40,100,0.5);
  addWorldgen(Features.DIORITE,ChiselBlocks.diorite,Configurations.dioriteAmount,40,100,0.5);
  GameRegistry.registerWorldGenerator(GeneratorChisel.INSTANCE,1000);
  proxy.init();
  MinecraftForge.EVENT_BUS.register(this);
  FMLCommonHandler.instance().bus().register(instance);
  FMLInterModComms.sendMessage("String_Node_Str","String_Node_Str","String_Node_Str");
}
Program: 59899
Project: 59899
Buggy source:
protected void genStandardOre(World world,Random random,int x,int z,int bot,int top){
  for (int l=0; l < amount; ++l) {
    int i1=x + random.nextInt(16);
    int j1=bot + random.nextInt(top - bot);
    int k1=z + random.nextInt(16);
    gen.generate(world,random,i1,j1,k1);
  }
}

Fixed version (ground truth):
protected void genStandardOre(WorldGenMinable gen,WorldGenInfo info,World world,Random random,int x,int z){
  for (int l=0; l < info.amount; ++l) {
    if (random.nextDouble() < info.chance) {
      int avgX=x + random.nextInt(16);
      int avgY=info.minY + random.nextInt(info.maxY - info.minY) + 1;
      int avgZ=z + random.nextInt(16);
      gen.generate(world,random,avgX,avgY,avgZ);
    }
  }
}
Program: 59900
Project: 59900
Buggy source:
@Override public void generate(Random random,int chunkX,int chunkZ,World world,IChunkProvider chunkGenerator,IChunkProvider chunkProvider){
  genStandardOre(world,random,chunkX * 16,chunkZ * 16,40,128);
}

Fixed version (ground truth):
@Override public void generate(Random random,int chunkX,int chunkZ,World world,IChunkProvider chunkGenerator,IChunkProvider chunkProvider){
  for (  WorldGenMinable gen : map.keySet()) {
    genStandardOre(gen,map.get(gen),world,random,chunkX * 16,chunkZ * 16);
  }
}
Program: 59901
Project: 59901
Buggy source:
/** 
 * Called when an item is chiseled using this chisel
 * @param world {@link World} object
 * @param inv The inventory this chisel is currently in
 * @param slot The slot index of the chisel in the inventory
 * @param chisel The  {@link ItemStack} representing the chisel
 * @param target The  {@link ItemStack} representing the target item
 */
void onChisel(World world,IInventory inv,int slot,ItemStack chisel,ICarvingVariation target);

Fixed version (ground truth):
/** 
 * Called when an item is chiseled using this chisel
 * @param world {@link World} object
 * @param inv The inventory this chisel is currently in
 * @param slot The slot index of the chisel in the inventory
 * @param chisel The  {@link ItemStack} representing the chisel
 * @param target The  {@link ItemStack} representing the target item
 * @return True if the chisel should be damaged. False otherwise.
 */
boolean onChisel(World world,IInventory inv,int slot,ItemStack chisel,ICarvingVariation target);
Program: 59902
Project: 59902
Buggy source:
/** 
 * Calls IChiselItem#onChisel() and sends the chisel packet for sound/animation 
 */
private void chiselItem(int chiseled){
  if (!worldObj.isRemote) {
    ((IChiselItem)inventory[CHISEL].getItem()).onChisel(worldObj,this,CHISEL,inventory[CHISEL],General.getVariation(inventory[TARGET]));
    PacketHandler.INSTANCE.sendToDimension(new MessageAutoChisel(this,chiseled,true),worldObj.provider.dimensionId);
  }
 else {
    GeneralChiselClient.spawnAutoChiselFX(this,lastBase != null ? lastBase : inventory[BASE]);
    chiseling=false;
    if (lastBase != null) {
      lastBase.stackSize-=toChisel;
      if (lastBase.stackSize <= 0) {
        lastBase=null;
      }
    }
  }
}

Fixed version (ground truth):
/** 
 * Calls IChiselItem#onChisel() and sends the chisel packet for sound/animation 
 */
private void chiselItem(int chiseled){
  if (!worldObj.isRemote) {
    if (((IChiselItem)inventory[CHISEL].getItem()).onChisel(worldObj,this,CHISEL,inventory[CHISEL],General.getVariation(inventory[TARGET]))) {
      inventory[CHISEL].setItemDamage(inventory[CHISEL].getItemDamage() - 1);
      if (inventory[CHISEL].getItemDamage() >= inventory[CHISEL].getMaxDamage()) {
        inventory[CHISEL]=null;
      }
    }
    PacketHandler.INSTANCE.sendToDimension(new MessageAutoChisel(this,chiseled,true),worldObj.provider.dimensionId);
  }
 else {
    GeneralChiselClient.spawnAutoChiselFX(this,lastBase != null ? lastBase : inventory[BASE]);
    chiseling=false;
    if (lastBase != null) {
      lastBase.stackSize-=toChisel;
      if (lastBase.stackSize <= 0) {
        lastBase=null;
      }
    }
  }
}
Program: 59903
Project: 59903
Buggy source:
@Override public void onPickupFromSlot(EntityPlayer player,ItemStack itemstack){
  ItemStack stack=player.inventory.getItemStack();
  ItemStack crafted=selInventory.inventory[InventoryChiselSelection.normalSlots];
  if (stack == null) {
    if (crafted != null && crafted.stackSize > 0)     crafted.stackSize--;
    if (crafted.stackSize == 0)     crafted=null;
    selInventory.setInventorySlotContents(InventoryChiselSelection.normalSlots,crafted);
  }
 else {
    putStack(new ItemStack(itemstack.getItem(),itemstack.stackSize,itemstack.getItemDamage()));
    player.inventory.setItemStack(null);
    if (selInventory.inventory[InventoryChiselSelection.normalSlots] == null)     return;
    player.inventory.setItemStack(new ItemStack(itemstack.getItem(),selInventory.inventory[InventoryChiselSelection.normalSlots].stackSize,itemstack.getItemDamage()));
    selInventory.setInventorySlotContents(InventoryChiselSelection.normalSlots,null);
  }
  selInventory.updateItems();
  ((IChiselItem)container.chisel.getItem()).onChisel(player.worldObj,player.inventory,player.inventory.currentItem,container.chisel,General.getVariation(crafted));
  if (player.worldObj.isRemote) {
    String sound=Carving.chisel.getVariationSound(crafted.getItem(),crafted.getItemDamage());
    GeneralClient.playChiselSound(player.worldObj,MathHelper.floor_double(player.posX),MathHelper.floor_double(player.posY),MathHelper.floor_double(player.posZ),sound);
  }
}

Fixed version (ground truth):
@Override public void onPickupFromSlot(EntityPlayer player,ItemStack itemstack){
  ItemStack stack=player.inventory.getItemStack();
  ItemStack crafted=selInventory.inventory[InventoryChiselSelection.normalSlots];
  if (stack == null) {
    if (crafted != null && crafted.stackSize > 0)     crafted.stackSize--;
    if (crafted.stackSize == 0)     crafted=null;
    selInventory.setInventorySlotContents(InventoryChiselSelection.normalSlots,crafted);
  }
 else {
    putStack(new ItemStack(itemstack.getItem(),itemstack.stackSize,itemstack.getItemDamage()));
    player.inventory.setItemStack(null);
    if (selInventory.inventory[InventoryChiselSelection.normalSlots] == null)     return;
    player.inventory.setItemStack(new ItemStack(itemstack.getItem(),selInventory.inventory[InventoryChiselSelection.normalSlots].stackSize,itemstack.getItemDamage()));
    selInventory.setInventorySlotContents(InventoryChiselSelection.normalSlots,null);
  }
  selInventory.updateItems();
  if (((IChiselItem)container.chisel.getItem()).onChisel(player.worldObj,player.inventory,player.inventory.currentItem,container.chisel,General.getVariation(crafted))) {
    container.chisel.damageItem(1,player);
    if (container.chisel.stackSize <= 0) {
      player.inventory.mainInventory[player.inventory.currentItem]=null;
    }
  }
  if (player.worldObj.isRemote) {
    String sound=Carving.chisel.getVariationSound(crafted.getItem(),crafted.getItemDamage());
    GeneralClient.playChiselSound(player.worldObj,MathHelper.floor_double(player.posX),MathHelper.floor_double(player.posY),MathHelper.floor_double(player.posZ),sound);
  }
}
Program: 59905
Project: 59905
Buggy source:
@Override public void onChisel(World world,IInventory inv,int slot,ItemStack chisel,ICarvingVariation target){
  if (Configurations.allowChiselDamage) {
    chisel.setItemDamage(chisel.getItemDamage() + 1);
    if (chisel.getItemDamage() >= chisel.getMaxDamage()) {
      inv.decrStackSize(slot,1);
    }
  }
}

Fixed version (ground truth):
@Override public boolean onChisel(World world,IInventory inv,int slot,ItemStack chisel,ICarvingVariation target){
  return Configurations.allowChiselDamage;
}
Program: 59906
Project: 59906
Buggy source:
public MessageChiselSound(int x,int y,int z,ICarvingVariation v){
  super(x,y,z);
  this.block=Block.getIdFromBlock(v.getBlock());
  this.meta=(byte)v.getBlockMeta();
}

Fixed version (ground truth):
public MessageChiselSound(int x,int y,int z,ICarvingVariation v,boolean breakChisel){
  super(x,y,z);
  this.block=Block.getIdFromBlock(v.getBlock());
  this.meta=(byte)v.getBlockMeta();
  this.breakChisel=breakChisel;
}
Program: 59907
Project: 59907
Buggy source:
@Override public void toBytes(ByteBuf buf){
  super.toBytes(buf);
  buf.writeInt(block);
  buf.writeByte(meta);
}

Fixed version (ground truth):
@Override public void toBytes(ByteBuf buf){
  super.toBytes(buf);
  buf.writeInt(block);
  buf.writeByte(meta);
  buf.writeBoolean(breakChisel);
}
Program: 59908
Project: 59908
Buggy source:
@Override public void fromBytes(ByteBuf buf){
  super.fromBytes(buf);
  block=buf.readInt();
  meta=buf.readByte();
}

Fixed version (ground truth):
@Override public void fromBytes(ByteBuf buf){
  super.fromBytes(buf);
  block=buf.readInt();
  meta=buf.readByte();
  breakChisel=buf.readBoolean();
}
Program: 59909
Project: 59909
Buggy source:
@Override public IMessage onMessage(MessageChiselSound message,MessageContext ctx){
  String sound=ItemChisel.carving.getVariationSound(Block.getBlockById(message.block),message.meta);
  GeneralChiselClient.spawnChiselEffect(message.x,message.y,message.z,sound);
  return null;
}

Fixed version (ground truth):
@Override public IMessage onMessage(MessageChiselSound message,MessageContext ctx){
  String sound=ItemChisel.carving.getVariationSound(Block.getBlockById(message.block),message.meta);
  GeneralChiselClient.spawnChiselEffect(message.x,message.y,message.z,sound);
  if (message.breakChisel) {
    EntityPlayer player=Chisel.proxy.getClientPlayer();
    player.renderBrokenItemStack(player.getCurrentEquippedItem());
  }
  return null;
}
Program: 59910
Project: 59910
Buggy source:
@Override public void setInventorySlotContents(int slot,ItemStack stack){
  inventory[slot]=stack;
  if (stack != null && stack.stackSize > getInventoryStackLimit()) {
    stack.stackSize=getInventoryStackLimit();
  }
  if (worldObj.isRemote && slot == BASE && stack != null) {
    lastBase=stack.copy();
    lastBase.stackSize++;
  }
  if (!worldObj.isRemote) {
    slotChanged(slot);
  }
}

Fixed version (ground truth):
@Override public void setInventorySlotContents(int slot,ItemStack stack){
  inventory[slot]=stack;
  if (stack != null && stack.stackSize > getInventoryStackLimit()) {
    stack.stackSize=getInventoryStackLimit();
  }
  if (worldObj.isRemote && slot == BASE && stack != null) {
    lastBase=stack.copy();
  }
  if (!worldObj.isRemote) {
    slotChanged(slot);
  }
}
Program: 59911
Project: 59911
Buggy source:
public ContainerAutoChisel(InventoryPlayer player,TileEntityAutoChisel tileEntityAutoChisel){
  ContainerAutoChisel.player=player.player;
  autoChisel=tileEntityAutoChisel;
  addSlot(tileEntityAutoChisel,0,53,15);
  addSlot(tileEntityAutoChisel,1,78,51);
  addSlot(tileEntityAutoChisel,2,103,15);
  addSlot(tileEntityAutoChisel,3,8,62);
  addSlot(tileEntityAutoChisel,4,151,11);
  addSlot(tileEntityAutoChisel,5,151,31);
  addSlot(tileEntityAutoChisel,6,151,51);
  bindPlayerInventory(player);
}

Fixed version (ground truth):
public ContainerAutoChisel(InventoryPlayer player,TileEntityAutoChisel tileEntityAutoChisel){
  this.player=player.player;
  autoChisel=tileEntityAutoChisel;
  addSlot(tileEntityAutoChisel,0,53,15);
  addSlot(tileEntityAutoChisel,1,78,51);
  addSlot(tileEntityAutoChisel,2,103,15);
  addSlot(tileEntityAutoChisel,3,8,62);
  addSlot(tileEntityAutoChisel,4,151,11);
  addSlot(tileEntityAutoChisel,5,151,31);
  addSlot(tileEntityAutoChisel,6,151,51);
  bindPlayerInventory(player);
}
Program: 59913
Project: 59913
Buggy source:
public BlockCarvable(Material m){
  super(m);
  carverHelper=new CarvableHelper();
  setCreativeTab(ModTabs.tabChiselBlocks);
}

Fixed version (ground truth):
public BlockCarvable(Material m){
  super(m);
  carverHelper=new CarvableHelper();
  setResistance(10.0F);
  setHardness(2.0F);
  setCreativeTab(ModTabs.tabChiselBlocks);
}
Program: 59916
Project: 59916
Buggy source:
void registerBlock(Block block,String name,Class cl){
  block.setBlockName(name);
  GameRegistry.registerBlock(block,cl,name);
  chiselBlocks.add(block);
}

Fixed version (ground truth):
void registerBlock(Block block,String name,Class<? extends ItemCarvable> cl){
  block.setBlockName(name);
  GameRegistry.registerBlock(block,cl,name);
  chiselBlocks.add(block);
}
Program: 59917
Project: 59917
Buggy source:
public void register(Block block,String name,Class cl){
  registerBlock(block,name,cl);
  if (block instanceof BlockMarbleSlab) {
    BlockMarbleSlab slab=(BlockMarbleSlab)block;
  }
  for (  CarvableVariation variation : variations) {
    registerVariation(name,variation,block,variation.metadata);
    if (block instanceof BlockMarbleSlab && ((BlockMarbleSlab)block).isBottom) {
      BlockMarbleSlab slab=(BlockMarbleSlab)block;
      slab.top.setHarvestLevel("String_Node_Str",0,variation.metadata);
      if (!forbidChiseling) {
        Carving.chisel.addVariation(name + "String_Node_Str",slab.top,variation.metadata,0);
        Carving.chisel.setGroupClass(name + "String_Node_Str",name);
      }
    }
  }
}

Fixed version (ground truth):
public void register(Block block,String name,Class<? extends ItemCarvable> cl){
  registerBlock(block,name,cl);
  if (block instanceof BlockMarbleSlab) {
    BlockMarbleSlab slab=(BlockMarbleSlab)block;
  }
  for (  CarvableVariation variation : variations) {
    registerVariation(name,variation,block,variation.metadata);
    if (block instanceof BlockMarbleSlab && ((BlockMarbleSlab)block).isBottom) {
      BlockMarbleSlab slab=(BlockMarbleSlab)block;
      slab.top.setHarvestLevel("String_Node_Str",0,variation.metadata);
      if (!forbidChiseling) {
        Carving.chisel.addVariation(name + "String_Node_Str",slab.top,variation.metadata,0);
        Carving.chisel.setGroupClass(name + "String_Node_Str",name);
      }
    }
  }
}
Program: 59918
Project: 59918
Buggy source:
public void registerSubBlocks(Block block,CreativeTabs tabs,List list){
  for (  CarvableVariation variation : variations) {
    list.add(new ItemStack(block,1,variation.metadata));
  }
}

Fixed version (ground truth):
public void registerSubBlocks(Block block,CreativeTabs tabs,List<ItemStack> list){
  for (  CarvableVariation variation : variations) {
    list.add(new ItemStack(block,1,variation.metadata));
  }
}
Program: 59919
Project: 59919
Buggy source:
public ContainerPresent(IInventory player,IInventory chest){
  super(player,chest);
  lower=chest;
  rows=chest.getSizeInventory() / 9;
  chest.openInventory();
  int a=(rows - 4) * 18, b, c;
  for (int d=0; d < rows; d++) {
    for (int e=0; e < 9; e++) {
      addSlotToContainer(new Slot(chest,e + d * 9,8 + e * 18,18 + d * 18));
    }
  }
  for (int d=0; d < 3; d++) {
    for (int e=0; e < 9; e++) {
      addSlotToContainer(new Slot(player,e + d * 9 + 9,8 + e * 18,103 + d * 18 + a));
    }
  }
  for (int d=0; d < 9; d++) {
    addSlotToContainer(new Slot(player,d,8 + d * 18,161 + a));
  }
}

Fixed version (ground truth):
public ContainerPresent(IInventory player,IInventory chest){
  super(player,chest);
  lower=chest;
  rows=chest.getSizeInventory() / 9;
  chest.openInventory();
  int a=(rows - 4) * 18;
  for (int d=0; d < rows; d++) {
    for (int e=0; e < 9; e++) {
      addSlotToContainer(new Slot(chest,e + d * 9,8 + e * 18,18 + d * 18));
    }
  }
  for (int d=0; d < 3; d++) {
    for (int e=0; e < 9; e++) {
      addSlotToContainer(new Slot(player,e + d * 9 + 9,8 + e * 18,103 + d * 18 + a));
    }
  }
  for (int d=0; d < 9; d++) {
    addSlotToContainer(new Slot(player,d,8 + d * 18,161 + a));
  }
}
Program: 59920
Project: 59920
Buggy source:
@Override public boolean onItemUseFirst(ItemStack stack,EntityPlayer player,World world,int x,int y,int z,int size,float hitX,float hitY,float hitZ){
  if (world.isRemote)   return false;
  TileEntity tile=world.getTileEntity(x,y,z);
  TileEntityAutoChisel autoChisel;
  if (tile != null && tile instanceof TileEntityAutoChisel) {
    TileEntityAutoChisel autoChisel1=(TileEntityAutoChisel)tile;
  }
  return true;
}

Fixed version (ground truth):
@Override public boolean onItemUseFirst(ItemStack stack,EntityPlayer player,World world,int x,int y,int z,int size,float hitX,float hitY,float hitZ){
  if (world.isRemote)   return false;
  TileEntity tile=world.getTileEntity(x,y,z);
  if (tile != null && tile instanceof TileEntityAutoChisel) {
  }
  return true;
}
Program: 59921
Project: 59921
Buggy source:
public synchronized void moveToUpdating(){
  updated.left=(int)GameMath.gate(0,updated.left,mapWidth);
  updated.right=(int)GameMath.gate(0,updated.right,mapWidth);
  updated.top=(int)GameMath.gate(0,updated.top,mapHeight);
  updated.bottom=(int)GameMath.gate(0,updated.bottom,mapHeight);
  updating=new Rect(updated);
  updated.setEmpty();
}

Fixed version (ground truth):
public synchronized void moveToUpdating(){
  updating=new Rect(updated);
  updated.setEmpty();
}
Program: 59922
Project: 59922
Buggy source:
public synchronized void updateFogArea(int x,int y,int w,int h){
  updated.union(x,y);
  updated.union(x + w,y + h);
}

Fixed version (ground truth):
public synchronized void updateFogArea(int x,int y,int w,int h){
  updated.union(x,y);
  updated.union(x + w,y + h);
  updated=updated.intersect(new Rect(0,0,mapWidth,mapHeight));
}
Program: 59923
Project: 59923
Buggy source:
protected void onClick(){
  text.destroy();
  onClose();
}

Fixed version (ground truth):
protected void onClick(){
  onClose();
}
Program: 59924
Project: 59924
Buggy source:
@Override protected void createChildren(){
  super.createChildren();
  bg=Chrome.get(Chrome.Type.TOAST_TR);
  add(bg);
  close=new SimpleButton(Icons.get(Icons.CLOSE)){
    protected void onClick(){
      text.destroy();
      onClose();
    }
  }
;
  add(close);
  text=PixelScene.renderMultiline(8);
  add(text);
}

Fixed version (ground truth):
@Override protected void createChildren(){
  super.createChildren();
  bg=Chrome.get(Chrome.Type.TOAST_TR);
  add(bg);
  close=new SimpleButton(Icons.get(Icons.CLOSE)){
    protected void onClick(){
      onClose();
    }
  }
;
  add(close);
  text=PixelScene.renderMultiline(8);
  add(text);
}
Program: 59925
Project: 59925
Buggy source:
@Override public void filter(int minMode,int maxMode){
  fModeMin=minMode;
  fModeMax=maxMode;
  if (id != -1)   super.filter(fModeMin=minMode,fModeMax=maxMode);
}

Fixed version (ground truth):
@Override public void filter(int minMode,int maxMode){
  if (fModeMin == minMode && fModeMax == maxMode)   return;
  fModeMin=minMode;
  fModeMax=maxMode;
  if (id != -1)   super.filter(fModeMin,fModeMax);
}
Program: 59926
Project: 59926
Buggy source:
@Override protected void generate(){
  super.generate();
  bitmap(bitmap);
  filter(fModeMin,fModeMax);
  wrap(wModeH,wModeV);
}

Fixed version (ground truth):
@Override protected void generate(){
  super.generate();
  bitmap(bitmap);
  super.filter(fModeMin,fModeMax);
  super.wrap(wModeH,wModeV);
}
Program: 59927
Project: 59927
Buggy source:
@Override public void wrap(int s,int t){
  wModeH=s;
  wModeV=t;
  if (id != -1)   super.wrap(wModeH=s,wModeV=t);
}

Fixed version (ground truth):
@Override public void wrap(int s,int t){
  if (wModeH == s && wModeV == t)   return;
  wModeH=s;
  wModeV=t;
  if (id != -1)   super.wrap(wModeH,wModeV);
}
Program: 59928
Project: 59928
Buggy source:
@Override protected void updateMatrix(){
  float sx=scroll.x + shakeX;
  float sy=scroll.y + shakeY;
  matrix[0]=+zoom * invW2;
  matrix[5]=-zoom * invH2;
  matrix[12]=-1 + x * invW2 - sx * matrix[0];
  matrix[13]=+1 - y * invH2 - sy * matrix[5];
}

Fixed version (ground truth):
@Override protected void updateMatrix(){
  float sx=Math.round(scroll.x + shakeX);
  float sy=Math.round(scroll.y + shakeY);
  matrix[0]=+zoom * invW2;
  matrix[5]=-zoom * invH2;
  matrix[12]=-1 + x * invW2 - sx * matrix[0];
  matrix[13]=+1 - y * invH2 - sy * matrix[5];
}
Program: 59929
Project: 59929
Buggy source:
@Override public boolean touchUp(int screenX,int screenY,int pointer,int button){
  eventTouch.dispatch(pointers.remove(button).up());
  return true;
}

Fixed version (ground truth):
@Override public boolean touchUp(int screenX,int screenY,int pointer,int button){
  Touch touch=pointers.remove(button);
  if (touch != null) {
    eventTouch.dispatch(touch.up());
    return true;
  }
  return false;
}
Program: 59930
Project: 59930
Buggy source:
@Override protected void createChildren(){
  super.createChildren();
  slot=new ItemSlot(){
    @Override protected void onClick(){
      if (NoosaInputProcessor.modifier) {
        onLongClick();
        return;
      }
      if (targeting) {
        GameScene.handleCell(lastTarget.pos);
      }
 else {
        Item item=select(slotNum);
        if (item.stackable || item instanceof Wand || item instanceof Boomerang)         useTargeting();
        item.execute(Dungeon.hero);
      }
    }
    @Override protected boolean onLongClick(){
      return QuickSlotButton.this.onLongClick();
    }
    @Override protected void onTouchDown(){
      icon.lightness(0.7f);
    }
    @Override protected void onTouchUp(){
      icon.resetColor();
    }
  }
;
  add(slot);
  crossB=Icons.TARGET.get();
  crossB.visible=false;
  add(crossB);
  crossM=new Image();
  crossM.copy(crossB);
}

Fixed version (ground truth):
@Override protected void createChildren(){
  super.createChildren();
  slot=new ItemSlot(){
    @Override protected void onClick(){
      if (!Dungeon.hero.isAlive())       return;
      if (NoosaInputProcessor.modifier) {
        onLongClick();
        return;
      }
      if (targeting) {
        GameScene.handleCell(lastTarget.pos);
      }
 else {
        Item item=select(slotNum);
        if (item.stackable || item instanceof Wand || item instanceof Boomerang)         useTargeting();
        item.execute(Dungeon.hero);
      }
    }
    @Override protected boolean onLongClick(){
      return QuickSlotButton.this.onLongClick();
    }
    @Override protected void onTouchDown(){
      icon.lightness(0.7f);
    }
    @Override protected void onTouchUp(){
      icon.resetColor();
    }
  }
;
  add(slot);
  crossB=Icons.TARGET.get();
  crossB.visible=false;
  add(crossB);
  crossM=new Image();
  crossM.copy(crossB);
}
Program: 59933
Project: 59933
Buggy source:
@Override public void update(){
  super.update();
  Sample.INSTANCE.play(Assets.SND_CLICK,1,1,1.2f);
}

Fixed version (ground truth):
@Override public void update(){
  super.update();
  if (brightness < 1.0f && brightness > MIN_BRIGHTNESS) {
    if ((brightness-=Game.elapsed) <= MIN_BRIGHTNESS) {
      brightness=MIN_BRIGHTNESS;
    }
    updateBrightness();
  }
}
Program: 59934
Project: 59934
Buggy source:
private void populateList(){
  listContent.clear();
  tempPos=0;
  final PDInputProcessor inputProcessor=(PDInputProcessor)Game.instance.getInputProcessor();
  final Map<Integer,PDInputProcessor.GameActionWrapper> keyMappings=inputProcessor.getKeyMappings();
  final Map<GameAction,KeyPair> mappings=new TreeMap<>();
  for (  Map.Entry<Integer,PDInputProcessor.GameActionWrapper> entry : keyMappings.entrySet()) {
    final Integer key=entry.getKey();
    final PDInputProcessor.GameActionWrapper value=entry.getValue();
    final GameAction action=value.gameAction;
    KeyPair keyPair=mappings.get(action);
    if (keyPair == null) {
      mappings.put(action,keyPair=new KeyPair());
    }
    if (value.defaultKey) {
      keyPair.key1=key;
    }
 else {
      keyPair.key2=key;
    }
  }
  for (  Map.Entry<GameAction,KeyPair> entry : mappings.entrySet()) {
    addKey(listContent,width,entry);
  }
  listContent.setSize(0,tempPos);
}

Fixed version (ground truth):
private void populateList(){
  listContent.clear();
  tempPos=0;
  final PDInputProcessor inputProcessor=(PDInputProcessor)Game.instance.getInputProcessor();
  final Map<Integer,PDInputProcessor.GameActionWrapper> keyMappings=inputProcessor.getKeyMappings();
  final Map<GameAction,KeyPair> mappings=new TreeMap<>();
  for (  GameAction action : GameAction.values()) {
    if (action.getDescription() != null) {
      mappings.put(action,new KeyPair());
    }
  }
  for (  Map.Entry<Integer,PDInputProcessor.GameActionWrapper> entry : keyMappings.entrySet()) {
    final Integer key=entry.getKey();
    final PDInputProcessor.GameActionWrapper value=entry.getValue();
    final GameAction action=value.gameAction;
    KeyPair keyPair=mappings.get(action);
    if (keyPair == null) {
      mappings.put(action,keyPair=new KeyPair());
    }
    if (value.defaultKey) {
      keyPair.key1=key;
    }
 else {
      keyPair.key2=key;
    }
  }
  for (  Map.Entry<GameAction,KeyPair> entry : mappings.entrySet()) {
    addKey(listContent,width,entry);
  }
  listContent.setSize(0,tempPos);
}
Program: 59935
Project: 59935
Buggy source:
public int[] columnTypes(ResultSet res){
  ResultSetMetaData md=res.getMetaData();
  int n=md.getColumnCount();
  cts=new int[n];
  for (int i=0; i < n; i++) {
    int ct=md.getColumnType(i + 1);
    if (ct == -5 || ct == -6 || (ct >= 2 & ct <= 8)) {
      cts[i]=1;
    }
 else {
      cts[i]=0;
    }
  }
}

Fixed version (ground truth):
public int[] columnTypes(ResultSet res) throws java.sql.SQLException {
  try {
    ResultSetMetaData md=res.getMetaData();
    int n=md.getColumnCount();
    int[] cts=new int[n];
    for (int i=0; i < n; i++) {
      int ct=md.getColumnType(i + 1);
      if (ct == -5 || ct == -6 || (ct >= 2 & ct <= 8)) {
        cts[i]=1;
      }
 else {
        cts[i]=0;
      }
    }
    return cts;
  }
 catch (  java.sql.SQLException e) {
    throw e;
  }
}
Program: 59936
Project: 59936
Buggy source:
@Override protected void paintComponent(Graphics g){
  super.paintComponent(g);
  g.drawImage(image,0,0,this);
}

Fixed version (ground truth):
@Override protected void paintComponent(Graphics g){
  super.paintComponent(g);
  if (image == null) {
    return;
  }
  float xScale=getWidth() / (float)image.getWidth();
  float yScale=getHeight() / (float)image.getHeight();
  float scale=Math.min(xScale,yScale);
  g.drawImage(image,0,0,(int)(image.getWidth() * scale),(int)(image.getHeight() * scale),this);
}
Program: 59938
Project: 59938
Buggy source:
@Override public String toString(){
  return name + "String_Node_Str" + ordinal+ "String_Node_Str";
}

Fixed version (ground truth):
@Override public String toString(){
  return name + "String_Node_Str" + value+ "String_Node_Str"+ ordinal+ "String_Node_Str";
}
Program: 59939
Project: 59939
Buggy source:
private static void renderTextView(TextView view,Graphics2D canvas){
  canvas.setColor(view.isSelected() ? Color.RED : Color.BLACK);
  canvas.setStroke(view.isSelected() ? THICK : THIN);
  canvas.drawRect(view.left,view.top,view.getWidth(),view.getHeight());
}

Fixed version (ground truth):
private static void renderTextView(TextView view,Graphics2D canvas){
  canvas.setColor(view.isSelected() ? Color.RED : Color.BLACK);
  canvas.setStroke(view.isSelected() ? THICK : THIN);
  canvas.drawRect(view.left,view.top,view.getWidth(),view.getHeight());
  canvas.translate(view.left,view.top);
  String text=view.text.length() < 20 ? view.text : view.text.substring(0,20);
  canvas.drawString(text,20,view.getHeight() / 2);
  canvas.translate(-view.left,-view.top);
}
Program: 59940
Project: 59940
Buggy source:
public static BufferedImage createBitmap(int bitmapObjectId,byte[] data,int width,int height){
  if (cache.containsKey(bitmapObjectId)) {
    return cache.get(bitmapObjectId);
  }
  if (data.length != width * height * 4) {
    throw new IllegalArgumentException("String_Node_Str" + data.length + "String_Node_Str"+ width+ "String_Node_Str"+ height);
  }
  BufferedImage image=new BufferedImage(width,height,BufferedImage.TYPE_INT_ARGB);
  for (int i=0; i < data.length; i+=4) {
    int pixel=i / 4;
    int value=0xff000000 | (data[i + 1] << 16) | (data[i + 2] << 8)| data[i + 3];
    image.setRGB(pixel % width,pixel / width,value);
  }
  cache.put(bitmapObjectId,image);
  return image;
}

Fixed version (ground truth):
public static BufferedImage createBitmap(int bitmapObjectId,byte[] data,int width,int height){
  if (cache.containsKey(bitmapObjectId)) {
    return cache.get(bitmapObjectId);
  }
  if (data.length != width * height * 4) {
    throw new IllegalArgumentException("String_Node_Str" + data.length + "String_Node_Str"+ width+ "String_Node_Str"+ height);
  }
  BufferedImage image=new BufferedImage(width,height,BufferedImage.TYPE_INT_ARGB);
  for (int i=0; i < data.length; i+=4) {
    int pixel=i / 4;
    int value=((data[i + 3] << 24) & 0xff000000) | ((data[i] << 16) & 0xff0000) | ((data[i + 1] << 8) & 0xff00)| (data[i + 2] & 0xff);
    image.setRGB(pixel % width,pixel / width,value);
  }
  cache.put(bitmapObjectId,image);
  return image;
}
Program: 59941
Project: 59941
Buggy source:
private void renderImageView(ImageView view,Graphics2D canvas){
  renderView(view,canvas);
  canvas.translate(view.left,view.top);
  int left=(view.getWidth() - view.getImage().getWidth()) / 2;
  int top=(view.getHeight() - view.getImage().getHeight()) / 2;
  canvas.drawImage(view.getImage(),left,top,null);
  canvas.translate(-view.left,-view.top);
}

Fixed version (ground truth):
private void renderImageView(ImageView view,Graphics2D canvas){
  renderView(view,canvas);
  canvas.translate(view.left,view.top);
  final BufferedImage image=view.getImage();
  if (image.getWidth() < view.getWidth() && image.getHeight() < view.getHeight()) {
    int left=(view.getWidth() - image.getWidth()) / 2;
    int top=(view.getHeight() - image.getHeight()) / 2;
    canvas.drawImage(image,left,top,null);
  }
 else {
    canvas.drawImage(image,0,0,view.getWidth(),view.getHeight(),null);
  }
  canvas.translate(-view.left,-view.top);
}
Program: 59942
Project: 59942
Buggy source:
@Override public void valueChanged(TreeSelectionEvent event){
  if (selectedView != null) {
    selectedView.setSelected(false);
  }
  DefaultMutableTreeNode newNode=(DefaultMutableTreeNode)event.getNewLeadSelectionPath().getLastPathComponent();
  View newView=(View)newNode.getUserObject();
  newView.setSelected(true);
  selectedView=newView;
  updateImage(false);
}

Fixed version (ground truth):
@Override public void valueChanged(TreeSelectionEvent event){
  if (selectedView != null) {
    selectedView.setSelected(false);
  }
  if (event.getNewLeadSelectionPath() == null) {
    selectedView=null;
    return;
  }
  DefaultMutableTreeNode newNode=(DefaultMutableTreeNode)event.getNewLeadSelectionPath().getLastPathComponent();
  View newView=(View)newNode.getUserObject();
  newView.setSelected(true);
  selectedView=newView;
  updateImage(false);
}
Program: 59943
Project: 59943
Buggy source:
public MainWindow(List<ViewGroup> roots){
  super("String_Node_Str");
  setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  this.roots=roots;
  imagePanel=new ImagePanel();
  viewTree=new JTree(new DefaultMutableTreeNode("String_Node_Str"));
  viewTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
  viewTree.addTreeSelectionListener(this);
  JScrollPane treeScroller=new JScrollPane(viewTree);
  splitPane=new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
  splitPane.setLeftComponent(treeScroller);
  splitPane.setRightComponent(imagePanel);
  splitPane.setDividerLocation(300);
  splitPane.setPreferredSize(new Dimension(800,700));
  add(splitPane);
  setVisible(true);
  showViewTree(roots.get(0));
  updateImage(true);
}

Fixed version (ground truth):
public MainWindow(List<ViewGroup> roots){
  super("String_Node_Str");
  setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  this.roots=roots;
  imagePanel=new ImagePanel();
  viewTree=new JTree(new DefaultMutableTreeNode("String_Node_Str"));
  viewTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
  viewTree.addTreeSelectionListener(this);
  JScrollPane treeScroller=new JScrollPane(viewTree);
  rootPicker=new JComboBox(new Vector<Object>(roots));
  rootPicker.addItemListener(this);
  JPanel leftPanel=new JPanel(new BorderLayout());
  leftPanel.add(rootPicker,BorderLayout.NORTH);
  leftPanel.add(treeScroller,BorderLayout.CENTER);
  splitPane=new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
  splitPane.setLeftComponent(leftPanel);
  splitPane.setRightComponent(imagePanel);
  add(splitPane);
  setVisible(true);
  selectedRoot=roots.get(0);
  update();
}
Program: 59944
Project: 59944
Buggy source:
public void updateImage(boolean resize){
  BufferedImage image=renderer.renderViews(roots.get(0));
  imagePanel.setImage(image);
  if (resize) {
    Dimension size=new Dimension((int)(imagePanel.getPreferredSize().getWidth() + 310),(int)imagePanel.getPreferredSize().getHeight());
    splitPane.setPreferredSize(size);
    pack();
  }
}

Fixed version (ground truth):
public void updateImage(boolean resize){
  BufferedImage image=renderer.renderViews(selectedRoot);
  imagePanel.setImage(image);
  if (resize) {
    Dimension size=new Dimension((int)(imagePanel.getPreferredSize().getWidth() + rootPicker.getPreferredSize().getWidth() + 15),(int)imagePanel.getPreferredSize().getHeight() + 25);
    setPreferredSize(size);
    pack();
  }
}
Program: 59945
Project: 59945
Buggy source:
public void showViewTree(ViewGroup root){
  DefaultMutableTreeNode rootNode=new DefaultMutableTreeNode(root);
  addChildViews(rootNode,root);
  DefaultTreeModel model=new DefaultTreeModel(rootNode);
  viewTree.setModel(model);
}

Fixed version (ground truth):
public void showViewTree(){
  DefaultMutableTreeNode rootNode=new DefaultMutableTreeNode(selectedRoot);
  addChildViews(rootNode,selectedRoot);
  DefaultTreeModel model=new DefaultTreeModel(rootNode);
  viewTree.setModel(model);
}
Program: 59946
Project: 59946
Buggy source:
/** 
 * Callback method invoked when the file header is read. Will only occur once per file.
 * @param version Version number identifying which version of the BMD file format that the data complies to.
 * @param data    Header data (if converted from HPROF this will be the original HPROF header)
 */
public void onHeader(int version,@Nonnull byte[] data) throws IOException ;

Fixed version (ground truth):
/** 
 * Callback method invoked when the file header is read. Will only occur once per file.
 * @param version Version number identifying which version of the BMD file format that the data complies to.
 * @param data    Header data (if converted from HPROF this will be the original HPROF header)
 */
void onHeader(int version,@Nonnull byte[] data) throws IOException ;
Program: 59947
Project: 59947
Buggy source:
/** 
 * Callback method invoked when a record is read. The reader, and stream, are positioned after the record header when this method is invoked.
 * @param tag    The tag of the record (as defined in BmdTag)
 * @param reader The reader used to read the BMD data.
 */
public void onRecord(BmdTag tag,@Nonnull BmdReader reader) throws IOException ;

Fixed version (ground truth):
/** 
 * Callback method invoked when a record is read. The reader, and stream, are positioned after the record header when this method is invoked.
 * @param tag    The tag of the record (as defined in BmdTag)
 * @param reader The reader used to read the BMD data.
 */
void onRecord(BmdTag tag,@Nonnull BmdReader reader) throws IOException ;
Program: 59948
Project: 59948
Buggy source:
public void writeHeader(int version,byte[] metadata) throws IOException {
  writeInt32(version);
  writeByteArrayWithLength(metadata != null ? metadata : new byte[]{});
}

Fixed version (ground truth):
public void writeHeader(int version,@Nullable byte[] metadata) throws IOException {
  writeInt32(version);
  writeByteArrayWithLength(metadata != null ? metadata : EMPTY);
}
Program: 59949
Project: 59949
Buggy source:
public void writeInstanceDump(Instance instance) throws IOException {
  final long start=getCurrentPosition();
  writeTag(BmdTag.INSTANCE_DUMP);
  writeInt32(mapObjectId(instance.getObjectId()));
  writeInt32(mapObjectId(instance.getClassObjectId()));
  ClassDefinition currentClass=classesByOriginalId.get(instance.getClassObjectId());
  ByteArrayInputStream in=new ByteArrayInputStream(instance.getInstanceFieldData());
  while (currentClass != null) {
    int fieldCount=currentClass.getInstanceFields().size();
    for (int i=0; i < fieldCount; i++) {
      InstanceField field=currentClass.getInstanceFields().get(i);
      BasicType type=field.getType();
      if (type == BasicType.OBJECT) {
        int id=readInt(in);
        writeInt32(mapObjectId(id));
      }
 else {
        skip(in,type.size);
      }
    }
    currentClass=classesByOriginalId.get(currentClass.getSuperClassObjectId());
  }
  if (in.available() != 0) {
    throw new IllegalStateException("String_Node_Str" + in.available());
  }
  if (collectStats) {
    Stats.increment(Stats.Type.INSTANCE,Stats.Variant.BMD,writer.getCurrentPosition() - start);
  }
}

Fixed version (ground truth):
public void writeInstanceDump(@Nonnull Instance instance) throws IOException {
  final long start=getCurrentPosition();
  writeTag(BmdTag.INSTANCE_DUMP);
  writeInt32(mapObjectId(instance.getObjectId()));
  writeInt32(mapObjectId(instance.getClassObjectId()));
  ClassDefinition currentClass=classesByOriginalId.get(instance.getClassObjectId());
  ByteArrayInputStream in=new ByteArrayInputStream(instance.getInstanceFieldData());
  while (currentClass != null) {
    int fieldCount=currentClass.getInstanceFields().size();
    for (int i=0; i < fieldCount; i++) {
      InstanceField field=currentClass.getInstanceFields().get(i);
      BasicType type=field.getType();
      if (type == BasicType.OBJECT) {
        int id=readInt(in);
        writeInt32(mapObjectId(id));
      }
 else {
        skip(in,type.size);
      }
    }
    currentClass=classesByOriginalId.get(currentClass.getSuperClassObjectId());
  }
  if (in.available() != 0) {
    throw new IllegalStateException("String_Node_Str" + in.available());
  }
  if (collectStats) {
    Stats.increment(Stats.Type.INSTANCE,Stats.Variant.BMD,writer.getCurrentPosition() - start);
  }
}
Program: 59950
Project: 59950
Buggy source:
/** 
 * Must be called after the first pass (where class data is processed) is finished, before the second pass is started.
 */
public void startSecondPass(){
  if (stringIds.isEmpty() || classesByOriginalId.isEmpty()) {
    throw new IllegalStateException("String_Node_Str");
  }
  readObjects=true;
}

Fixed version (ground truth):
/** 
 * Must be called after the first pass (where class data is processed) is finished, before the second pass is started.
 */
public void startSecondPass(){
  if (stringIds.isEmpty() || classesByOriginalId.isEmpty()) {
    throw new IllegalStateException("String_Node_Str");
  }
  firstPass=false;
}
Program: 59951
Project: 59951
Buggy source:
public void writeLegacyRecord(int tag,byte[] data) throws IOException {
  writeInt32(BmdTag.LEGACY_HPROF_RECORD.value);
  writeInt32(tag);
  writeInt32(data.length);
  writeRawBytes(data);
}

Fixed version (ground truth):
public void writeLegacyRecord(int tag,@Nonnull byte[] data) throws IOException {
  writeInt32(BmdTag.LEGACY_HPROF_RECORD.value);
  writeInt32(tag);
  writeInt32(data.length);
  writeRawBytes(data);
}
Program: 59952
Project: 59952
Buggy source:
@Override public void onRecord(int tag,int timestamp,int length,@Nonnull HprofReader reader) throws IOException {
  if (!readObjects) {
switch (tag) {
case Tag.STRING:
      readStringRecord(timestamp,length,reader);
    break;
case Tag.LOAD_CLASS:
  if (collectStats) {
    Stats.increment(Stats.Type.CLASS,Stats.Variant.HPROF,length + 9);
  }
ClassDefinition classDef=reader.readLoadClassRecord();
classesByOriginalId.put(classDef.getObjectId(),classDef);
break;
case Tag.HEAP_DUMP:
case Tag.HEAP_DUMP_SEGMENT:
ClassDumpProcessor dumpProcessor=new ClassDumpProcessor();
HeapDumpReader dumpReader=new HeapDumpReader(reader.getInputStream(),length,dumpProcessor);
while (dumpReader.hasNext()) {
dumpReader.next();
}
break;
case Tag.UNLOAD_CLASS:
case Tag.HEAP_DUMP_END:
super.onRecord(tag,timestamp,length,reader);
break;
default :
byte[] data=read(reader.getInputStream(),length);
writer.writeLegacyRecord(tag,data);
break;
}
}
 else {
switch (tag) {
case Tag.HEAP_DUMP:
case Tag.HEAP_DUMP_SEGMENT:
ObjectDumpProcessor dumpProcessor=new ObjectDumpProcessor();
HeapDumpReader dumpReader=new HeapDumpReader(reader.getInputStream(),length,dumpProcessor);
while (dumpReader.hasNext()) {
dumpReader.next();
}
break;
default :
super.onRecord(tag,timestamp,length,reader);
}
}
}

Fixed version (ground truth):
@Override public void onRecord(int tag,int timestamp,int length,@Nonnull HprofReader reader) throws IOException {
  if (firstPass) {
switch (tag) {
case Tag.STRING:
      readStringRecord(timestamp,length,reader);
    break;
case Tag.LOAD_CLASS:
  if (collectStats) {
    Stats.increment(Stats.Type.CLASS,Stats.Variant.HPROF,length + 9);
  }
ClassDefinition classDef=reader.readLoadClassRecord();
classesByOriginalId.put(classDef.getObjectId(),classDef);
break;
case Tag.HEAP_DUMP:
case Tag.HEAP_DUMP_SEGMENT:
ClassDumpProcessor dumpProcessor=new ClassDumpProcessor();
HeapDumpReader dumpReader=new HeapDumpReader(reader.getInputStream(),length,dumpProcessor);
while (dumpReader.hasNext()) {
dumpReader.next();
}
break;
case Tag.UNLOAD_CLASS:
case Tag.HEAP_DUMP_END:
super.onRecord(tag,timestamp,length,reader);
break;
default :
byte[] data=read(reader.getInputStream(),length);
writer.writeLegacyRecord(tag,data);
break;
}
}
 else {
switch (tag) {
case Tag.HEAP_DUMP:
case Tag.HEAP_DUMP_SEGMENT:
ObjectDumpProcessor dumpProcessor=new ObjectDumpProcessor();
HeapDumpReader dumpReader=new HeapDumpReader(reader.getInputStream(),length,dumpProcessor);
while (dumpReader.hasNext()) {
dumpReader.next();
}
break;
default :
super.onRecord(tag,timestamp,length,reader);
}
}
}
Program: 59954
Project: 59954
Buggy source:
public void writeString(HprofString string,boolean hashed) throws IOException {
  writeTag(hashed ? BmdTag.HASHED_STRING : BmdTag.STRING);
  writeInt32(string.getId());
  byte[] stringData=string.getValue().getBytes();
  if (hashed) {
    writeRawVarint32(stringData.length);
    writeInt32(string.getValue().hashCode());
  }
 else {
    writeByteArrayWithLength(stringData);
  }
}

Fixed version (ground truth):
public void writeString(@Nonnull HprofString string,boolean hashed) throws IOException {
  writeTag(hashed ? BmdTag.HASHED_STRING : BmdTag.STRING);
  writeInt32(string.getId());
  byte[] stringData=string.getValue().getBytes();
  if (hashed) {
    writeRawVarint32(stringData.length);
    writeInt32(string.getValue().hashCode());
  }
 else {
    writeByteArrayWithLength(stringData);
  }
}
Program: 59955
Project: 59955
Buggy source:
/** 
 * Crunch a HPROF file, converting it to BMD format.
 * @param source the HPROF data source
 * @param out    Output (BMD)
 * @throws IOException If an error occurs while writing the output data
 */
public static void crunch(@Nonnull HprofSource source,@Nonnull OutputStream out,@Nullable Config config) throws IOException, TimeoutException {
  if (config == null) {
    config=new Config();
  }
  Stats.setEnabled(config.collectStats);
  Stats.increment(Stats.Type.TOTAL,Stats.Variant.HPROF,source.getDataSize());
  final long start=System.currentTimeMillis();
  final long limit=config.timeLimit != Config.NO_TIME_LIMIT ? start + config.timeLimit : Long.MAX_VALUE;
  CountingOutputStream cOut=new CountingOutputStream(out);
  if (config.collectStats) {
    out=cOut;
  }
  CrunchProcessor processor=new CrunchProcessor(out,true);
  InputStream in=new BufferedInputStream(source.open());
  HprofReader reader=new HprofReader(in,processor);
  while (reader.hasNext()) {
    reader.next();
    checkTimeLimit(limit);
    iterationSleep(config);
  }
  processor.startSecondPass();
  in.close();
  in=new BufferedInputStream(source.open());
  reader=new HprofReader(in,processor);
  while (reader.hasNext()) {
    reader.next();
    checkTimeLimit(limit);
    iterationSleep(config);
  }
  processor.finishAndWriteOutput();
  Stats.increment(Stats.Type.TOTAL,Stats.Variant.BMD,cOut.getCount());
  Stats.printStats();
}

Fixed version (ground truth):
/** 
 * Crunch a HPROF file, converting it to BMD format.
 * @param source the HPROF data source
 * @param out    Output (BMD)
 * @throws IOException If an error occurs while writing the output data
 */
public static void crunch(@Nonnull HprofSource source,@Nonnull OutputStream out,@Nullable Config config) throws IOException, TimeoutException {
  if (config == null) {
    config=new Config();
  }
  Stats.setEnabled(config.collectStats);
  Stats.increment(Stats.Type.TOTAL,Stats.Variant.HPROF,source.getDataSize());
  final long start=System.currentTimeMillis();
  final long limit=config.timeLimit != Config.NO_TIME_LIMIT ? start + config.timeLimit : Long.MAX_VALUE;
  CountingOutputStream cOut=new CountingOutputStream(out);
  if (config.collectStats) {
    out=cOut;
  }
  CrunchProcessor processor=new CrunchProcessor(out,true);
  InputStream in=new BufferedInputStream(source.open());
  try {
    HprofReader reader=new HprofReader(in,processor);
    while (reader.hasNext()) {
      reader.next();
      checkTimeLimit(limit);
      iterationSleep(config);
    }
    processor.startSecondPass();
  }
  finally {
    in.close();
  }
  in=new BufferedInputStream(source.open());
  try {
    HprofReader reader=new HprofReader(in,processor);
    while (reader.hasNext()) {
      reader.next();
      checkTimeLimit(limit);
      iterationSleep(config);
    }
    processor.finishAndWriteOutput();
  }
  finally {
    in.close();
  }
  Stats.increment(Stats.Type.TOTAL,Stats.Variant.BMD,cOut.getCount());
  Stats.printStats();
}