nus-yam/ex-repair huggingface dataset:
Program: 157707
Project: 157707
Buggy source:
@Override public boolean apply(Game game,Ability source){
  StackAbility stackAbility=(StackAbility)game.getStack().getStackObject(targetPointer.getFirst(game,source));
  if (stackAbility != null) {
    Player controller=game.getPlayer(source.getControllerId());
    Permanent sourcePermanent=game.getPermanent(source.getSourceId());
    if (controller != null && sourcePermanent != null) {
      stackAbility.createCopyOnStack(game,source,source.getControllerId(),true);
      game.informPlayers(new StringBuilder(sourcePermanent.getName()).append("String_Node_Str").append(controller.getLogName()).append("String_Node_Str").toString());
      return true;
    }
  }
  return false;
}

Fixed version (ground truth):
@Override public boolean apply(Game game,Ability source){
  StackAbility stackAbility=(StackAbility)game.getStack().getStackObject(targetPointer.getFirst(game,source));
  if (stackAbility != null) {
    Player controller=game.getPlayer(source.getControllerId());
    Permanent sourcePermanent=game.getPermanent(source.getSourceId());
    if (controller != null && sourcePermanent != null) {
      stackAbility.createCopyOnStack(game,source,source.getControllerId(),true);
      game.informPlayers(sourcePermanent.getIdName() + "String_Node_Str" + controller.getLogName()+ "String_Node_Str");
      return true;
    }
  }
  return false;
}
Program: 157708
Project: 157708
Buggy source:
/** 
 * I made opponent's Nekusar white with 8.5 tails and when Nekusar was recast he was still white.
 */
@Test @Ignore public void testColorChangeIsReset(){
  addCard(Zone.BATTLEFIELD,playerA,"String_Node_Str",1);
  addCard(Zone.BATTLEFIELD,playerA,"String_Node_Str",1);
  addCard(Zone.BATTLEFIELD,playerB,"String_Node_Str",1);
  addCard(Zone.HAND,playerB,"String_Node_Str",1);
  addCard(Zone.BATTLEFIELD,playerB,"String_Node_Str",2);
  activateAbility(1,PhaseStep.PRECOMBAT_MAIN,playerA,"String_Node_Str","String_Node_Str");
  castSpell(1,PhaseStep.BEGIN_COMBAT,playerB,"String_Node_Str","String_Node_Str");
  setStopAt(1,PhaseStep.END_COMBAT);
  execute();
  assertPermanentCount(playerB,"String_Node_Str",1);
  Permanent nekusar=getPermanent("String_Node_Str");
  assertGraveyardCount(playerB,"String_Node_Str",1);
  Assert.assertFalse("String_Node_Str",nekusar.getColor(currentGame).isWhite());
  Assert.assertTrue("String_Node_Str",nekusar.getColor(currentGame).isBlue());
  Assert.assertTrue("String_Node_Str",nekusar.getColor(currentGame).isBlack());
  Assert.assertTrue("String_Node_Str",nekusar.getColor(currentGame).isRed());
}

Fixed version (ground truth):
/** 
 * I made opponent's Nekusar white with 8.5 tails and when Nekusar was recast he was still white.
 */
@Test public void testColorChangeIsReset(){
  addCard(Zone.BATTLEFIELD,playerA,"String_Node_Str",1);
  addCard(Zone.BATTLEFIELD,playerA,"String_Node_Str",1);
  addCard(Zone.BATTLEFIELD,playerB,"String_Node_Str",1);
  addCard(Zone.HAND,playerB,"String_Node_Str",1);
  addCard(Zone.BATTLEFIELD,playerB,"String_Node_Str",2);
  activateAbility(1,PhaseStep.PRECOMBAT_MAIN,playerA,"String_Node_Str","String_Node_Str");
  castSpell(1,PhaseStep.BEGIN_COMBAT,playerB,"String_Node_Str","String_Node_Str");
  setStopAt(1,PhaseStep.END_COMBAT);
  execute();
  assertPermanentCount(playerB,"String_Node_Str",1);
  Permanent nekusar=getPermanent("String_Node_Str");
  assertGraveyardCount(playerB,"String_Node_Str",1);
  Assert.assertFalse("String_Node_Str",nekusar.getColor(currentGame).isWhite());
  Assert.assertTrue("String_Node_Str",nekusar.getColor(currentGame).isBlue());
  Assert.assertTrue("String_Node_Str",nekusar.getColor(currentGame).isBlack());
  Assert.assertTrue("String_Node_Str",nekusar.getColor(currentGame).isRed());
}
Program: 157709
Project: 157709
Buggy source:
@Override public boolean apply(Game game,Ability source){
  Player controller=game.getPlayer(source.getControllerId());
  if (controller == null) {
    return false;
  }
  if (setColor != null) {
    boolean objectFound=false;
    for (    UUID targetId : targetPointer.getTargets(game,source)) {
      MageObject targetObject=game.getObject(targetId);
      if (targetObject != null) {
        objectFound=true;
        targetObject.getColor(game).setColor(setColor);
      }
    }
    if (!objectFound && this.getDuration() == Duration.Custom) {
      this.discard();
    }
    return true;
  }
 else {
    throw new UnsupportedOperationException("String_Node_Str");
  }
}

Fixed version (ground truth):
@Override public boolean apply(Game game,Ability source){
  Player controller=game.getPlayer(source.getControllerId());
  if (controller == null) {
    return false;
  }
  if (setColor != null) {
    boolean objectFound=false;
    for (    UUID targetId : targetPointer.getTargets(game,source)) {
      MageObject targetObject=game.getObject(targetId);
      if (targetObject != null) {
        if (targetObject instanceof Spell || targetObject instanceof Permanent) {
          objectFound=true;
          targetObject.getColor(game).setColor(setColor);
        }
 else {
          objectFound=false;
        }
      }
    }
    if (!objectFound && this.getDuration() == Duration.Custom) {
      this.discard();
    }
    return true;
  }
 else {
    throw new UnsupportedOperationException("String_Node_Str");
  }
}
Program: 157711
Project: 157711
Buggy source:
@Override public boolean moveToExile(UUID exileId,String name,UUID sourceId,Game game,List<UUID> appliedEffects){
  return this.card.moveToExile(exileId,name,sourceId,game,appliedEffects);
}

Fixed version (ground truth):
@Override public boolean moveToExile(UUID exileId,String name,UUID sourceId,Game game,List<UUID> appliedEffects){
  if (this.isCopiedSpell()) {
    game.getStack().remove(this);
    return true;
  }
  return this.card.moveToExile(exileId,name,sourceId,game,appliedEffects);
}
Program: 157713
Project: 157713
Buggy source:
public ReturnSourceFromGraveyardToHandEffect(){
  throw new UnsupportedOperationException("String_Node_Str");
}

Fixed version (ground truth):
public ReturnSourceFromGraveyardToHandEffect(final ReturnSourceFromGraveyardToHandEffect effect){
  super(effect);
}
Program: 157714
Project: 157714
Buggy source:
private void addToken(Token token,BigCard bigCard,UUID gameId,Rectangle rectangle){
  if (cardDimension == null) {
    cardDimension=new Dimension(Config.dimensions.frameWidth,Config.dimensions.frameHeight);
  }
  PermanentToken newToken=new PermanentToken(token,null,token.getOriginalExpansionSetCode(),null);
  PermanentView theToken=new PermanentView(newToken,null,null,null);
  theToken.setInViewerOnly(true);
  final MageCard cardImg=Plugins.instance.getMagePermanent(theToken,bigCard,cardDimension,gameId,true);
  cardImg.setBounds(rectangle);
  jLayeredPane.add(cardImg,JLayeredPane.DEFAULT_LAYER,10);
  cardImg.update(theToken);
  cardImg.setCardBounds(rectangle.x,rectangle.y,cardDimensions.frameWidth,cardDimensions.frameHeight);
}

Fixed version (ground truth):
private void addToken(Token token,BigCard bigCard,UUID gameId,Rectangle rectangle){
  if (cardDimension == null) {
    cardDimension=new Dimension(Config.dimensions.frameWidth,Config.dimensions.frameHeight);
  }
  PermanentToken newToken=new PermanentToken(token,null,token.getOriginalExpansionSetCode(),null);
  newToken.removeSummoningSickness();
  PermanentView theToken=new PermanentView(newToken,null,null,null);
  theToken.setInViewerOnly(true);
  final MageCard cardImg=Plugins.instance.getMagePermanent(theToken,bigCard,cardDimension,gameId,true);
  cardImg.setBounds(rectangle);
  jLayeredPane.add(cardImg,JLayeredPane.DEFAULT_LAYER,10);
  cardImg.update(theToken);
  cardImg.setCardBounds(rectangle.x,rectangle.y,cardDimensions.frameWidth,cardDimensions.frameHeight);
}
Program: 157715
Project: 157715
Buggy source:
public void updateSize(String size){
switch (size) {
case LAYOUT_3x3:
    this.conf=new _3x3Configuration();
  break;
case LAYOUT_4x4:
this.conf=new _4x4Configuration();
break;
default :
return;
}
currentPage=0;
pageLeft.setVisible(false);
setSize(conf.WIDTH,conf.HEIGHT);
setPreferredSize(new Dimension(conf.WIDTH,conf.HEIGHT));
setMinimumSize(new Dimension(conf.WIDTH,conf.HEIGHT));
addSetTabs();
showCards();
}

Fixed version (ground truth):
public void updateSize(String size){
switch (size) {
case LAYOUT_3x3:
    this.conf=new _3x3Configuration();
  break;
case LAYOUT_4x4:
this.conf=new _4x4Configuration();
break;
default :
return;
}
currentPage=0;
pageLeft.setVisible(false);
setSize(conf.WIDTH,conf.HEIGHT);
setPreferredSize(new Dimension(conf.WIDTH,conf.HEIGHT));
setMinimumSize(new Dimension(conf.WIDTH,conf.HEIGHT));
addSetTabs();
}
Program: 157716
Project: 157716
Buggy source:
@Override public boolean checkTrigger(GameEvent event,Game game){
  Permanent permanent=game.getPermanent(event.getTargetId());
  if (permanent != null && permanent.isCreature() && StackObject.class.isInstance(game.getObject(event.getSourceId()))) {
    getEffects().get(0).setTargetPointer(new FixedTarget(event.getTargetId()));
    return true;
  }
  return false;
}

Fixed version (ground truth):
@Override public boolean checkTrigger(GameEvent event,Game game){
  Permanent permanent=game.getPermanent(event.getTargetId());
  if (permanent != null && permanent.isCreature()) {
    getEffects().get(0).setTargetPointer(new FixedTarget(event.getTargetId()));
    return true;
  }
  return false;
}
Program: 157717
Project: 157717
Buggy source:
public void updateSize(String size){
switch (size) {
case LAYOUT_3x3:
    this.conf=new _3x3Configuration();
  break;
case LAYOUT_4x4:
this.conf=new _4x4Configuration();
break;
default :
return;
}
currentPage=0;
pageLeft.setVisible(false);
setSize(conf.WIDTH,conf.HEIGHT);
setPreferredSize(new Dimension(conf.WIDTH,conf.HEIGHT));
setMinimumSize(new Dimension(conf.WIDTH,conf.HEIGHT));
addSetTabs();
showCards();
}

Fixed version (ground truth):
public void updateSize(String size){
switch (size) {
case LAYOUT_3x3:
    this.conf=new _3x3Configuration();
  break;
case LAYOUT_4x4:
this.conf=new _4x4Configuration();
break;
default :
return;
}
currentPage=0;
pageLeft.setVisible(false);
setSize(conf.WIDTH,conf.HEIGHT);
setPreferredSize(new Dimension(conf.WIDTH,conf.HEIGHT));
setMinimumSize(new Dimension(conf.WIDTH,conf.HEIGHT));
addSetTabs();
showCardsOrTokens();
}
Program: 157718
Project: 157718
Buggy source:
void drawPie(Graphics2D g,Rectangle area,Slice[] slices){
  double total=0.0D;
  for (int i=0; i < slices.length; i++) {
    total+=slices[i].value;
  }
  double curValue=0.0D;
  int startAngle=0;
  int lastAngle=0;
  for (int i=0; i < slices.length; i++) {
    startAngle=lastAngle;
    int arcAngle=(int)(slices[i].value * 360 / total);
    g.setColor(slices[i].color);
    g.fillArc(area.x,area.y,area.width - 20,area.height - 20,startAngle,arcAngle);
    curValue+=slices[i].value;
    lastAngle+=arcAngle;
  }
}

Fixed version (ground truth):
void drawPie(Graphics2D g,Rectangle area,Slice[] slices){
  double total=0.0D;
  for (int i=0; i < slices.length; i++) {
    total+=slices[i].value;
  }
  if (total == 0.0D) {
    return;
  }
  double curValue=0.0D;
  int startAngle=0;
  int lastAngle=0;
  for (int i=0; i < slices.length; i++) {
    startAngle=lastAngle;
    int arcAngle=(int)(slices[i].value * 360 / total);
    g.setColor(slices[i].color);
    g.fillArc(area.x,area.y,area.width - 20,area.height - 20,startAngle,arcAngle);
    curValue+=slices[i].value;
    lastAngle+=arcAngle;
  }
}
Program: 157719
Project: 157719
Buggy source:
private void onOK(){
  try {
    File temp=File.createTempFile("String_Node_Str","String_Node_Str");
    BufferedWriter bw=new BufferedWriter(new FileWriter(temp));
    bw.write(txtDeckList.getText());
    bw.close();
    tmpPath=temp.getPath();
  }
 catch (  IOException e) {
    e.printStackTrace();
  }
  dispose();
}

Fixed version (ground truth):
private void onOK(){
  BufferedWriter bw=null;
  try {
    File temp=File.createTempFile("String_Node_Str","String_Node_Str");
    bw=new BufferedWriter(new FileWriter(temp));
    bw.write(txtDeckList.getText());
    tmpPath=temp.getPath();
  }
 catch (  IOException e) {
    e.printStackTrace();
  }
 finally {
    StreamUtils.closeQuietly(bw);
  }
  dispose();
}
Program: 157721
Project: 157721
Buggy source:
/** 
 * Get the panel where all arrows are being drawn.
 * @return
 */
public JPanel getArrowsManagerPanel(){
  if (arrowsManagerPanel == null) {
synchronized (ArrowBuilder.class) {
      if (arrowsManagerPanel == null) {
        arrowsManagerPanel=new JPanel();
        arrowsManagerPanel.setVisible(true);
        arrowsManagerPanel.setOpaque(false);
        arrowsManagerPanel.setLayout(null);
      }
    }
  }
  return arrowsManagerPanel;
}

Fixed version (ground truth):
/** 
 * Get the panel where all arrows are being drawn.
 * @return
 */
public synchronized JPanel getArrowsManagerPanel(){
  if (arrowsManagerPanel == null) {
    arrowsManagerPanel=new JPanel();
    arrowsManagerPanel.setVisible(true);
    arrowsManagerPanel.setOpaque(false);
    arrowsManagerPanel.setLayout(null);
  }
  return arrowsManagerPanel;
}
Program: 157722
Project: 157722
Buggy source:
/** 
 * Save object on disk.
 * @param object Object to save.
 * @param name Part of name that will be used to form original filename to save object to.
 */
public static void saveObject(Object object,String name){
  if (saveIncomeData) {
    ObjectOutputStream oos=null;
    try {
      File dir=new File("String_Node_Str");
      if (!dir.exists() || dir.exists() && dir.isFile()) {
        boolean bCreated=dir.mkdir();
        if (!bCreated) {
          return;
        }
      }
      String time=now(DATE_PATTERN);
      File f=new File("String_Node_Str" + File.separator + name+ '_'+ time+ "String_Node_Str");
      if (!f.exists()) {
        f.createNewFile();
      }
      oos=new ObjectOutputStream(new FileOutputStream(f));
      oos.writeObject(object);
      oos.close();
    }
 catch (    FileNotFoundException e) {
      return;
    }
catch (    IOException io) {
      return;
    }
  }
}

Fixed version (ground truth):
/** 
 * Save object on disk.
 * @param object Object to save.
 * @param name Part of name that will be used to form original filename to save object to.
 */
public static void saveObject(Object object,String name){
  if (saveIncomeData) {
    ObjectOutputStream oos=null;
    try {
      File dir=new File("String_Node_Str");
      if (!dir.exists() || dir.exists() && dir.isFile()) {
        boolean bCreated=dir.mkdir();
        if (!bCreated) {
          return;
        }
      }
      String time=now(DATE_PATTERN);
      File f=new File("String_Node_Str" + File.separator + name+ '_'+ time+ "String_Node_Str");
      if (!f.exists()) {
        f.createNewFile();
      }
      oos=new ObjectOutputStream(new FileOutputStream(f));
      oos.writeObject(object);
      oos.close();
    }
 catch (    Exception e) {
    }
 finally {
      StreamUtils.closeQuietly(oos);
    }
  }
}
Program: 157723
Project: 157723
Buggy source:
public static ImageIcon getImageIcon(String path){
  try {
    InputStream stream;
    stream=UI.class.getResourceAsStream(path);
    if (stream == null && new File(path).exists()) {
      stream=new FileInputStream(path);
    }
    if (stream == null) {
      throw new RuntimeException("String_Node_Str" + path);
    }
    byte[] data=new byte[stream.available()];
    stream.read(data);
    return new ImageIcon(data);
  }
 catch (  IOException ex) {
    throw new RuntimeException("String_Node_Str" + path);
  }
}

Fixed version (ground truth):
public static ImageIcon getImageIcon(String path){
  InputStream stream=null;
  try {
    stream=UI.class.getResourceAsStream(path);
    if (stream == null && new File(path).exists()) {
      stream=new FileInputStream(path);
    }
    if (stream == null) {
      throw new RuntimeException("String_Node_Str" + path);
    }
    byte[] data=new byte[stream.available()];
    stream.read(data);
    return new ImageIcon(data);
  }
 catch (  IOException ex) {
    throw new RuntimeException("String_Node_Str" + path);
  }
 finally {
    StreamUtils.closeQuietly(stream);
  }
}
Program: 157725
Project: 157725
Buggy source:
@Override public boolean apply(Game game,Ability source){
  Player controller=game.getPlayer(source.getControllerId());
  if (controller != null) {
    Set<Card> cardsToExile=controller.getGraveyard().getCards(new FilterInstantOrSorceryCard(),source.getId(),source.getControllerId(),game);
    if (!cardsToExile.isEmpty()) {
      if (controller.moveCards(cardsToExile,Zone.EXILED,source,game)) {
        Cards copiedCards=new CardsImpl();
        for (        Card card : cardsToExile) {
          copiedCards.add(game.copyCard(card,source,source.getControllerId()));
        }
        boolean continueCasting=true;
        while (continueCasting) {
          TargetCard targetCard=new TargetCard(0,1,Zone.EXILED,new FilterCard("String_Node_Str"));
          targetCard.setNotTarget(true);
          if (controller.choose(outcome,copiedCards,targetCard,game)) {
            Card selectedCard=game.getCard(targetCard.getFirstTarget());
            if (selectedCard != null && selectedCard.getSpellAbility().canChooseTarget(game)) {
              if (controller.cast(selectedCard.getSpellAbility(),game,true)) {
                copiedCards.remove(selectedCard);
              }
            }
          }
          continueCasting=!copiedCards.isEmpty() && controller.chooseUse(outcome,"String_Node_Str",source,game);
        }
      }
    }
    return true;
  }
  return false;
}

Fixed version (ground truth):
@Override public boolean apply(Game game,Ability source){
  Player controller=game.getPlayer(source.getControllerId());
  if (controller != null) {
    Set<Card> cardsToExile=controller.getGraveyard().getCards(new FilterInstantOrSorceryCard(),source.getId(),source.getControllerId(),game);
    if (!cardsToExile.isEmpty()) {
      if (controller.moveCards(cardsToExile,Zone.EXILED,source,game)) {
        Cards copiedCards=new CardsImpl();
        for (        Card card : cardsToExile) {
          copiedCards.add(game.copyCard(card,source,source.getControllerId()));
        }
        boolean continueCasting=true;
        while (continueCasting && controller.isInGame()) {
          TargetCard targetCard=new TargetCard(0,1,Zone.EXILED,new FilterCard("String_Node_Str"));
          targetCard.setNotTarget(true);
          if (controller.choose(outcome,copiedCards,targetCard,game)) {
            Card selectedCard=game.getCard(targetCard.getFirstTarget());
            if (selectedCard != null && selectedCard.getSpellAbility().canChooseTarget(game)) {
              if (controller.cast(selectedCard.getSpellAbility(),game,true)) {
                copiedCards.remove(selectedCard);
              }
            }
          }
          continueCasting=!copiedCards.isEmpty() && controller.chooseUse(outcome,"String_Node_Str",source,game);
        }
      }
    }
    return true;
  }
  return false;
}
Program: 157726
Project: 157726
Buggy source:
public MageObjectImpl(final MageObjectImpl object){
  objectId=object.objectId;
  name=object.name;
  manaCost=object.manaCost.copy();
  text=object.text;
  color=object.color.copy();
  frameColor=object.frameColor.copy();
  frameStyle=object.frameStyle;
  power=object.power.copy();
  toughness=object.toughness.copy();
  abilities=object.abilities.copy();
  this.cardType.addAll(object.cardType);
  this.subtype.addAll(object.subtype);
  supertype.addAll(object.supertype);
  this.copy=object.copy;
  textParts=new ArrayList<>();
  textParts.addAll(object.textParts);
}

Fixed version (ground truth):
public MageObjectImpl(final MageObjectImpl object){
  objectId=object.objectId;
  name=object.name;
  manaCost=object.manaCost.copy();
  text=object.text;
  color=object.color.copy();
  frameColor=object.frameColor.copy();
  frameStyle=object.frameStyle;
  power=object.power.copy();
  toughness=object.toughness.copy();
  abilities=object.abilities.copy();
  this.cardType.addAll(object.cardType);
  this.subtype.addAll(object.subtype);
  isAllCreatureTypes=object.isAllCreatureTypes;
  supertype.addAll(object.supertype);
  this.copy=object.copy;
  textParts=new ArrayList<>();
  textParts.addAll(object.textParts);
}
Program: 157727
Project: 157727
Buggy source:
protected void copyFromCard(final Card card,final Game game){
  this.name=card.getName();
  this.abilities.clear();
  if (this.faceDown) {
    for (    Ability ability : card.getAbilities()) {
      if (ability.getWorksFaceDown()) {
        this.abilities.add(ability.copy());
      }
    }
  }
 else {
    this.abilities=card.getAbilities().copy();
  }
  this.abilities.setControllerId(this.controllerId);
  this.abilities.setSourceId(objectId);
  this.cardType.clear();
  this.cardType.addAll(card.getCardType());
  this.color=card.getColor(null).copy();
  this.frameColor=card.getFrameColor(game).copy();
  this.frameStyle=card.getFrameStyle();
  this.manaCost=card.getManaCost().copy();
  if (card instanceof PermanentCard) {
    this.maxLevelCounters=((PermanentCard)card).maxLevelCounters;
  }
  this.subtype.clear();
  this.subtype.addAll(card.getSubtype(game));
  this.supertype.clear();
  supertype.addAll(card.getSuperType());
  this.expansionSetCode=card.getExpansionSetCode();
  this.rarity=card.getRarity();
  this.cardNumber=card.getCardNumber();
  this.usesVariousArt=card.getUsesVariousArt();
  transformable=card.isTransformable();
  if (transformable) {
    this.nightCard=card.isNightCard();
    if (!this.nightCard) {
      this.secondSideCard=card.getSecondCardFace();
      this.secondSideCardClazz=this.secondSideCard.getClass();
    }
  }
  this.flipCard=card.isFlipCard();
  this.flipCardName=card.getFlipCardName();
}

Fixed version (ground truth):
protected void copyFromCard(final Card card,final Game game){
  this.name=card.getName();
  this.abilities.clear();
  if (this.faceDown) {
    for (    Ability ability : card.getAbilities()) {
      if (ability.getWorksFaceDown()) {
        this.abilities.add(ability.copy());
      }
    }
  }
 else {
    this.abilities=card.getAbilities().copy();
  }
  this.abilities.setControllerId(this.controllerId);
  this.abilities.setSourceId(objectId);
  this.cardType.clear();
  this.cardType.addAll(card.getCardType());
  this.color=card.getColor(null).copy();
  this.frameColor=card.getFrameColor(game).copy();
  this.frameStyle=card.getFrameStyle();
  this.manaCost=card.getManaCost().copy();
  if (card instanceof PermanentCard) {
    this.maxLevelCounters=((PermanentCard)card).maxLevelCounters;
  }
  this.subtype.clear();
  this.subtype.addAll(card.getSubtype(game));
  this.isAllCreatureTypes=card.isAllCreatureTypes();
  this.supertype.clear();
  supertype.addAll(card.getSuperType());
  this.expansionSetCode=card.getExpansionSetCode();
  this.rarity=card.getRarity();
  this.cardNumber=card.getCardNumber();
  this.usesVariousArt=card.getUsesVariousArt();
  transformable=card.isTransformable();
  if (transformable) {
    this.nightCard=card.isNightCard();
    if (!this.nightCard) {
      this.secondSideCard=card.getSecondCardFace();
      this.secondSideCardClazz=this.secondSideCard.getClass();
    }
  }
  this.flipCard=card.isFlipCard();
  this.flipCardName=card.getFlipCardName();
}
Program: 157728
Project: 157728
Buggy source:
private void copyFromToken(Token token,Game game,boolean reset){
  this.name=token.getName();
  this.abilities.clear();
  if (reset) {
    this.abilities.addAll(token.getAbilities());
  }
 else {
    for (    Ability ability : token.getAbilities()) {
      this.addAbility(ability,game);
    }
  }
  this.abilities.setControllerId(this.controllerId);
  this.manaCost.clear();
  for (  ManaCost cost : token.getManaCost()) {
    this.getManaCost().add(cost.copy());
  }
  this.cardType=token.getCardType();
  this.color=token.getColor(game).copy();
  this.frameColor=token.getFrameColor(game);
  this.frameStyle=token.getFrameStyle();
  this.supertype.clear();
  this.supertype.addAll(token.getSuperType());
  this.subtype.clear();
  this.subtype.addAll(token.getSubtype(game));
  this.tokenDescriptor=token.getTokenDescriptor();
}

Fixed version (ground truth):
private void copyFromToken(Token token,Game game,boolean reset){
  this.name=token.getName();
  this.abilities.clear();
  if (reset) {
    this.abilities.addAll(token.getAbilities());
  }
 else {
    for (    Ability ability : token.getAbilities()) {
      this.addAbility(ability,game);
    }
  }
  this.abilities.setControllerId(this.controllerId);
  this.manaCost.clear();
  for (  ManaCost cost : token.getManaCost()) {
    this.getManaCost().add(cost.copy());
  }
  this.cardType=token.getCardType();
  this.color=token.getColor(game).copy();
  this.frameColor=token.getFrameColor(game);
  this.frameStyle=token.getFrameStyle();
  this.supertype.clear();
  this.supertype.addAll(token.getSuperType());
  this.subtype.clear();
  this.subtype.addAll(token.getSubtype(game));
  this.isAllCreatureTypes=token.isAllCreatureTypes();
  this.tokenDescriptor=token.getTokenDescriptor();
}
Program: 157729
Project: 157729
Buggy source:
@Override public boolean apply(Game game,Ability source){
  Player controller=game.getPlayer(source.getControllerId());
  Card card=game.getCard(getTargetPointer().getFirst(game,source));
  if (controller != null && card != null) {
    ManaCosts<ManaCost> costRef=card.getSpellAbility().getManaCostsToPay();
    costRef.clear();
    costRef.add(miracleCosts);
    controller.cast(card.getSpellAbility(),game,false);
    costRef.clear();
    for (    ManaCost manaCost : card.getSpellAbility().getManaCosts()) {
      costRef.add(manaCost);
    }
    return true;
  }
  return false;
}

Fixed version (ground truth):
@Override public boolean apply(Game game,Ability source){
  Player controller=game.getPlayer(source.getControllerId());
  Card card=game.getCard(getTargetPointer().getFirst(game,source));
  if (controller != null && card != null) {
    SpellAbility abilityToCast=card.getSpellAbility().copy();
    ManaCosts<ManaCost> costRef=abilityToCast.getManaCostsToPay();
    costRef.clear();
    costRef.add(miracleCosts);
    controller.cast(abilityToCast,game,false);
    return true;
  }
  return false;
}
Program: 157731
Project: 157731
Buggy source:
@Override public SpellAbility getSpellAbilityToResolve(Game game){
  Card card=game.getCard(getSourceId());
  if (card != null) {
    if (spellAbilityToResolve == null) {
      SpellAbility spellAbilityCopy=null;
      if (card.isSplitCard()) {
        if (((SplitCard)card).getLeftHalfCard().getName().equals(abilityName)) {
          spellAbilityCopy=((SplitCard)card).getLeftHalfCard().getSpellAbility().copy();
        }
 else         if (((SplitCard)card).getRightHalfCard().getName().equals(abilityName)) {
          spellAbilityCopy=((SplitCard)card).getRightHalfCard().getSpellAbility().copy();
        }
      }
 else {
        spellAbilityCopy=card.getSpellAbility().copy();
      }
      if (spellAbilityCopy == null) {
        return null;
      }
      spellAbilityCopy.setId(this.getId());
      spellAbilityCopy.getManaCosts().clear();
      spellAbilityCopy.getManaCostsToPay().clear();
      spellAbilityCopy.getCosts().addAll(this.getCosts());
      spellAbilityCopy.addCost(this.getManaCosts());
      spellAbilityCopy.setSpellAbilityCastMode(this.getSpellAbilityCastMode());
      spellAbilityToResolve=spellAbilityCopy;
      ContinuousEffect effect=new FlashbackReplacementEffect();
      effect.setTargetPointer(new FixedTarget(getSourceId(),game.getState().getZoneChangeCounter(getSourceId())));
      game.addEffect(effect,this);
    }
  }
  return spellAbilityToResolve;
}

Fixed version (ground truth):
@Override public SpellAbility getSpellAbilityToResolve(Game game){
  Card card=game.getCard(getSourceId());
  if (card != null) {
    if (spellAbilityToResolve == null) {
      SpellAbility spellAbilityCopy=null;
      if (card.isSplitCard()) {
        if (((SplitCard)card).getLeftHalfCard().getName().equals(abilityName)) {
          spellAbilityCopy=((SplitCard)card).getLeftHalfCard().getSpellAbility().copy();
        }
 else         if (((SplitCard)card).getRightHalfCard().getName().equals(abilityName)) {
          spellAbilityCopy=((SplitCard)card).getRightHalfCard().getSpellAbility().copy();
        }
      }
 else {
        spellAbilityCopy=card.getSpellAbility().copy();
      }
      if (spellAbilityCopy == null) {
        return null;
      }
      spellAbilityCopy.setId(this.getId());
      spellAbilityCopy.getManaCosts().clear();
      spellAbilityCopy.getManaCostsToPay().clear();
      spellAbilityCopy.getCosts().addAll(this.getCosts().copy());
      spellAbilityCopy.addCost(this.getManaCosts().copy());
      spellAbilityCopy.setSpellAbilityCastMode(this.getSpellAbilityCastMode());
      spellAbilityToResolve=spellAbilityCopy;
      ContinuousEffect effect=new FlashbackReplacementEffect();
      effect.setTargetPointer(new FixedTarget(getSourceId(),game.getState().getZoneChangeCounter(getSourceId())));
      game.addEffect(effect,this);
    }
  }
  return spellAbilityToResolve;
}
Program: 157732
Project: 157732
Buggy source:
private void checkPaid(UUID uuid,Spell spell){
  for (  Cost cost : spell.getSpellAbility().getManaCostsToPay()) {
    if (!cost.isPaid()) {
      return;
    }
  }
  CardView cardView=stack.get(uuid);
  cardView.paid=true;
}

Fixed version (ground truth):
private void checkPaid(UUID uuid,StackAbility stackAbility){
  for (  Cost cost : stackAbility.getManaCostsToPay()) {
    if (!cost.isPaid()) {
      return;
    }
  }
  CardView cardView=stack.get(uuid);
  cardView.paid=true;
}
Program: 157734
Project: 157734
Buggy source:
private static MagePane getTopMost(MagePane exclude){
  MagePane topmost=null;
  int best=Integer.MAX_VALUE;
  for (  Component frame : desktopPane.getComponentsInLayer(JLayeredPane.DEFAULT_LAYER)) {
    if (frame.isVisible()) {
      int z=desktopPane.getComponentZOrder(frame);
      if (z < best) {
        if (frame instanceof MagePane && (SessionHandler.isConnected() || !(frame instanceof TablesPane))) {
          best=z;
          if (!frame.equals(exclude)) {
            topmost=(MagePane)frame;
          }
        }
      }
    }
  }
  return topmost;
}

Fixed version (ground truth):
public static MagePane getTopMost(MagePane exclude){
  MagePane topmost=null;
  int best=Integer.MAX_VALUE;
  for (  Component frame : desktopPane.getComponentsInLayer(JLayeredPane.DEFAULT_LAYER)) {
    if (frame.isVisible()) {
      int z=desktopPane.getComponentZOrder(frame);
      if (z < best) {
        if (frame instanceof MagePane && (SessionHandler.isConnected() || !(frame instanceof TablesPane))) {
          best=z;
          if (!frame.equals(exclude)) {
            topmost=(MagePane)frame;
          }
        }
      }
    }
  }
  return topmost;
}
Program: 157735
Project: 157735
Buggy source:
private void handleOverNewView(TransferData data){
  hideTooltipPopup();
  cancelTimeout();
  Component parentComponent=SwingUtilities.getRoot(data.component);
  Point parentPoint=parentComponent.getLocationOnScreen();
  if (data.locationOnScreen == null) {
    data.locationOnScreen=data.component.getLocationOnScreen();
  }
  ArrowUtil.drawArrowsForTargets(data,parentPoint);
  ArrowUtil.drawArrowsForSource(data,parentPoint);
  ArrowUtil.drawArrowsForPairedCards(data,parentPoint);
  ArrowUtil.drawArrowsForBandedCards(data,parentPoint);
  ArrowUtil.drawArrowsForEnchantPlayers(data,parentPoint);
  tooltipCard=data.card;
  showTooltipPopup(data,parentComponent,parentPoint);
}

Fixed version (ground truth):
private void handleOverNewView(TransferData data){
  MagePane topPane=MageFrame.getTopMost(null);
  if (topPane instanceof GamePane) {
    if (!((GamePane)topPane).getGameId().equals(data.gameId)) {
      return;
    }
  }
 else   if (data.gameId != null) {
    return;
  }
  hideTooltipPopup();
  cancelTimeout();
  Component parentComponent=SwingUtilities.getRoot(data.component);
  Point parentPoint=parentComponent.getLocationOnScreen();
  if (data.locationOnScreen == null) {
    data.locationOnScreen=data.component.getLocationOnScreen();
  }
  ArrowUtil.drawArrowsForTargets(data,parentPoint);
  ArrowUtil.drawArrowsForSource(data,parentPoint);
  ArrowUtil.drawArrowsForPairedCards(data,parentPoint);
  ArrowUtil.drawArrowsForBandedCards(data,parentPoint);
  ArrowUtil.drawArrowsForEnchantPlayers(data,parentPoint);
  tooltipCard=data.card;
  showTooltipPopup(data,parentComponent,parentPoint);
}
Program: 157737
Project: 157737
Buggy source:
@Override public boolean checkTrigger(GameEvent event,Game game){
  if (((DamageEvent)event).isCombatDamage() && event.getSourceId().equals(getSourceId())) {
    Permanent targetPermanet=game.getPermanentOrLKIBattlefield(event.getTargetId());
    if (targetPermanet.hasSubtype(SubType.DINOSAUR,game)) {
      getEffects().get(0).setTargetPointer(new FixedTarget(targetPermanet,game));
      return true;
    }
  }
  return false;
}

Fixed version (ground truth):
@Override public boolean checkTrigger(GameEvent event,Game game){
  if (((DamagedEvent)event).isCombatDamage() && event.getSourceId().equals(getSourceId())) {
    Permanent targetPermanet=game.getPermanentOrLKIBattlefield(event.getTargetId());
    if (targetPermanet.hasSubtype(SubType.DINOSAUR,game)) {
      getEffects().get(0).setTargetPointer(new FixedTarget(targetPermanet,game));
      return true;
    }
  }
  return false;
}
Program: 157738
Project: 157738
Buggy source:
protected void playManaAbilities(Ability abilityToCast,ManaCost unpaid,Game game){
  updateGameStatePriority("String_Node_Str",game);
  MageObject object=game.getObject(response.getUUID());
  if (object == null) {
    return;
  }
  Spell spell=game.getStack().getSpell(abilityToCast.getSourceId());
  if (spell != null && !spell.isResolving() && spell.isDoneActivatingManaAbilities()) {
    game.informPlayer(this,"String_Node_Str");
    return;
  }
  Zone zone=game.getState().getZone(object.getId());
  if (zone != null) {
    LinkedHashMap<UUID,ActivatedManaAbilityImpl> useableAbilities=getUseableManaAbilities(object,zone,game);
    if (useableAbilities != null && !useableAbilities.isEmpty()) {
      useableAbilities=ManaUtil.tryToAutoPay(unpaid,useableAbilities);
      currentlyUnpaidMana=unpaid;
      activateAbility(useableAbilities,object,game);
      currentlyUnpaidMana=null;
    }
  }
}

Fixed version (ground truth):
protected void playManaAbilities(Ability abilityToCast,ManaCost unpaid,Game game){
  updateGameStatePriority("String_Node_Str",game);
  MageObject object=game.getObject(response.getUUID());
  if (object == null) {
    return;
  }
  if (AbilityType.SPELL.equals(abilityToCast.getAbilityType())) {
    Spell spell=game.getStack().getSpell(abilityToCast.getSourceId());
    if (spell != null && !spell.isResolving() && spell.isDoneActivatingManaAbilities()) {
      game.informPlayer(this,"String_Node_Str");
      return;
    }
  }
  Zone zone=game.getState().getZone(object.getId());
  if (zone != null) {
    LinkedHashMap<UUID,ActivatedManaAbilityImpl> useableAbilities=getUseableManaAbilities(object,zone,game);
    if (useableAbilities != null && !useableAbilities.isEmpty()) {
      useableAbilities=ManaUtil.tryToAutoPay(unpaid,useableAbilities);
      currentlyUnpaidMana=unpaid;
      activateAbility(useableAbilities,object,game);
      currentlyUnpaidMana=null;
    }
  }
}
Program: 157741
Project: 157741
Buggy source:
/** 
 * This test fails sometimes, probably because two plains are tapped for the first creature
 */
@Test @Ignore public void testSimpleCast2(){
  addCard(Zone.HAND,playerA,"String_Node_Str");
  addCard(Zone.HAND,playerA,"String_Node_Str");
  addCard(Zone.BATTLEFIELD,playerA,"String_Node_Str",2);
  addCard(Zone.BATTLEFIELD,playerA,"String_Node_Str",2);
  setStopAt(1,PhaseStep.BEGIN_COMBAT);
  execute();
  assertPermanentCount(playerA,"String_Node_Str",2);
}

Fixed version (ground truth):
/** 
 * This test fails sometimes, probably because two plains are tapped for the first creature
 */
@Test public void testSimpleCast2(){
  addCard(Zone.HAND,playerA,"String_Node_Str");
  addCard(Zone.HAND,playerA,"String_Node_Str");
  addCard(Zone.BATTLEFIELD,playerA,"String_Node_Str",2);
  addCard(Zone.BATTLEFIELD,playerA,"String_Node_Str",2);
  setStopAt(1,PhaseStep.BEGIN_COMBAT);
  execute();
  assertPermanentCount(playerA,"String_Node_Str",2);
}
Program: 157742
Project: 157742
Buggy source:
@Override public int announceXMana(int min,int max,String message,Game game,Ability ability){
  log.debug("String_Node_Str");
  int numAvailable=getAvailableManaProducers(game).size() - ability.getManaCosts().convertedManaCost();
  if (numAvailable < 0) {
    numAvailable=0;
  }
  return numAvailable;
}

Fixed version (ground truth):
@Override public int announceXMana(int min,int max,String message,Game game,Ability ability){
  log.debug("String_Node_Str");
  int numAvailable=getAvailableManaProducers(game).size() - ability.getManaCosts().convertedManaCost();
  if (numAvailable < 0) {
    numAvailable=0;
  }
  if (numAvailable > max) {
    numAvailable=max;
  }
  return numAvailable;
}
Program: 157743
Project: 157743
Buggy source:
/** 
 * Creates   {@link Mana} object from {@link ColoredManaSymbol}. Created  {@link Mana} will have a single mana of the passed in{@link ColoredManaSymbol} color.
 * @param color The color to create the {@link Mana} object with.
 */
public Mana(final ColoredManaSymbol color){
  Objects.requireNonNull(color,"String_Node_Str");
switch (color) {
case G:
    green=1;
  break;
case R:
red=1;
break;
case B:
black=1;
break;
case U:
blue=1;
break;
case W:
white=1;
break;
default :
throw new IllegalArgumentException("String_Node_Str" + color);
}
}

Fixed version (ground truth):
public Mana(final ManaType manaType){
  Objects.requireNonNull(manaType,"String_Node_Str");
switch (manaType) {
case GREEN:
    green=1;
  break;
case RED:
red=1;
break;
case BLACK:
black=1;
break;
case BLUE:
blue=1;
break;
case WHITE:
white=1;
break;
case COLORLESS:
colorless=1;
break;
case GENERIC:
generic=1;
break;
default :
throw new IllegalArgumentException("String_Node_Str" + manaType);
}
}
Program: 157744
Project: 157744
Buggy source:
/** 
 * Creates a   {@link Mana} object with the passed in {@code num} of Anymana.  {@code num} can not be a negative value. Negative values will belogged and set to 0.
 * @param num value of Any mana to create.
 * @return a {@link Mana} object with the passed in {@code num} of Anymana.
 */
public static Mana AnyMana(int num){
  return new Mana(0,0,0,0,0,0,notNegative(num,"String_Node_Str"),0);
}

Fixed version (ground truth):
/** 
 * Creates a   {@link Mana} object with the passed in {@code num} of Any mana.{@code num} can not be a negative value. Negative values will be loggedand set to 0.
 * @param num value of Any mana to create.
 * @return a {@link Mana} object with the passed in {@code num} of Any mana.
 */
public static Mana AnyMana(int num){
  return new Mana(0,0,0,0,0,0,notNegative(num,"String_Node_Str"),0);
}
Program: 157746
Project: 157746
Buggy source:
@Override public boolean apply(Game game,Ability source){
  Player controller=game.getPlayer(source.getControllerId());
  Permanent thisCreature=game.getPermanentOrLKIBattlefield(source.getId());
  if (controller != null && thisCreature != null) {
    BlockedAttackerWatcher watcher=(BlockedAttackerWatcher)game.getState().getWatchers().get(BlockedAttackerWatcher.class.getSimpleName());
    if (watcher != null) {
      List<Permanent> toDestroy=new ArrayList<>();
      for (      Permanent creature : game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE,source.getControllerId(),source.getSourceId(),game)) {
        if (!creature.getId().equals(thisCreature.getId())) {
          if (watcher.creatureHasBlockedAttacker(creature,thisCreature,game)) {
            toDestroy.add(creature);
          }
        }
      }
      for (      Permanent creature : toDestroy) {
        creature.destroy(source.getSourceId(),game,false);
      }
      thisCreature.destroy(source.getSourceId(),game,false);
      return true;
    }
  }
  return false;
}

Fixed version (ground truth):
@Override public boolean apply(Game game,Ability source){
  Player controller=game.getPlayer(source.getControllerId());
  Permanent thisCreature=game.getPermanentOrLKIBattlefield(source.getSourceId());
  if (controller != null && thisCreature != null) {
    BlockedAttackerWatcher watcher=(BlockedAttackerWatcher)game.getState().getWatchers().get(BlockedAttackerWatcher.class.getSimpleName());
    if (watcher != null) {
      List<Permanent> toDestroy=new ArrayList<>();
      for (      Permanent creature : game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE,source.getControllerId(),source.getSourceId(),game)) {
        if (!creature.getId().equals(thisCreature.getId())) {
          if (watcher.creatureHasBlockedAttacker(creature,thisCreature,game)) {
            toDestroy.add(creature);
          }
        }
      }
      thisCreature.destroy(source.getSourceId(),game,false);
      for (      Permanent creature : toDestroy) {
        creature.destroy(source.getSourceId(),game,false);
      }
      return true;
    }
  }
  return false;
}
Program: 157748
Project: 157748
Buggy source:
public KaerveksSpite copy(){
  return new KaerveksSpite(this);
}

Fixed version (ground truth):
@Override public KaerveksSpite copy(){
  return new KaerveksSpite(this);
}
Program: 157749
Project: 157749
Buggy source:
@Override public boolean pay(Ability ability,Game game,UUID sourceId,UUID controllerId,boolean noMana,Cost costToPay){
  for (  Permanent permanent : game.getBattlefield().getAllActivePermanents(filter,controllerId,game)) {
    permanents.add(permanent.copy());
    permanent.sacrifice(sourceId,game);
  }
  return true;
}

Fixed version (ground truth):
@Override public boolean pay(Ability ability,Game game,UUID sourceId,UUID controllerId,boolean noMana,Cost costToPay){
  for (  Permanent permanent : game.getBattlefield().getAllActivePermanents(filter,controllerId,game)) {
    if (permanent.sacrifice(sourceId,game)) {
      permanents.add(permanent.copy());
    }
  }
  paid=true;
  return paid;
}
Program: 157750
Project: 157750
Buggy source:
public SacrificeAllCost(final SacrificeAllCost cost){
  super(cost);
  for (  Permanent permanent : cost.permanents) {
    this.permanents.add(permanent.copy());
  }
  this.filter=cost.filter.copy();
}

Fixed version (ground truth):
public SacrificeAllCost(final SacrificeAllCost cost){
  super(cost);
  this.permanents.addAll(cost.permanents);
  this.filter=cost.filter.copy();
}
Program: 157752
Project: 157752
Buggy source:
public CardImpl(final CardImpl card){
  super(card);
  ownerId=card.ownerId;
  cardNumber=card.cardNumber;
  expansionSetCode=card.expansionSetCode;
  tokenDescriptor=card.tokenDescriptor;
  rarity=card.rarity;
  transformable=card.transformable;
  if (transformable) {
    secondSideCardClazz=card.secondSideCardClazz;
    nightCard=card.nightCard;
  }
  flipCard=card.flipCard;
  flipCardName=card.flipCardName;
  splitCard=card.splitCard;
  usesVariousArt=card.usesVariousArt;
  this.attachments.addAll(card.attachments);
}

Fixed version (ground truth):
public CardImpl(final CardImpl card){
  super(card);
  ownerId=card.ownerId;
  cardNumber=card.cardNumber;
  expansionSetCode=card.expansionSetCode;
  tokenDescriptor=card.tokenDescriptor;
  rarity=card.rarity;
  transformable=card.transformable;
  if (transformable) {
    secondSideCardClazz=card.secondSideCardClazz;
    nightCard=card.nightCard;
  }
  if (card.spellAbility != null) {
    spellAbility=card.getSpellAbility().copy();
  }
 else {
    spellAbility=null;
  }
  flipCard=card.flipCard;
  flipCardName=card.flipCardName;
  splitCard=card.splitCard;
  usesVariousArt=card.usesVariousArt;
  this.attachments.addAll(card.attachments);
}
Program: 157753
Project: 157753
Buggy source:
@Override public void assignNewId(){
  this.objectId=UUID.randomUUID();
  this.abilities.newOriginalId();
  this.abilities.setSourceId(objectId);
}

Fixed version (ground truth):
@Override public void assignNewId(){
  this.objectId=UUID.randomUUID();
  this.abilities.newOriginalId();
  this.abilities.setSourceId(objectId);
  if (this.spellAbility != null) {
    this.spellAbility.setSourceId(objectId);
  }
}
Program: 157754
Project: 157754
Buggy source:
@Override public boolean apply(Game game,Ability source){
  List<Permanent> permanents=game.getBattlefield().getActivePermanents(source.getControllerId(),game);
  Set<String> permanentNames=new HashSet<>();
  FilterCard filter=new FilterCard("String_Node_Str");
  for (  Permanent permanent : permanents) {
    permanentNames.add(permanent.getName());
    filter.add(new NamePredicate(permanent.getName()));
  }
  Player player=game.getPlayer(source.getControllerId());
  if (player == null) {
    return false;
  }
  Cards cards=new CardsImpl();
  Cards cardsFound=new CardsImpl();
  int count=Math.min(player.getLibrary().size(),7);
  for (int i=0; i < count; i++) {
    Card card=player.getLibrary().removeFromTop(game);
    if (card != null) {
      cards.add(card);
      if (permanentNames.contains(card.getName())) {
        cardsFound.add(card);
      }
    }
  }
  player.lookAtCards("String_Node_Str",cards,game);
  if (!cardsFound.isEmpty() && player.chooseUse(Outcome.PutCardInPlay,"String_Node_Str",source,game)) {
    TargetCard target=new TargetCard(Zone.LIBRARY,filter);
    if (player.choose(Outcome.PutCardInPlay,cardsFound,target,game)) {
      Card card=cards.get(target.getFirstTarget(),game);
      if (card != null) {
        cards.remove(card);
        card.putOntoBattlefield(game,Zone.LIBRARY,source.getSourceId(),source.getControllerId());
      }
    }
  }
  player.putCardsOnBottomOfLibrary(cards,game,source,true);
  return true;
}

Fixed version (ground truth):
@Override public boolean apply(Game game,Ability source){
  Player controller=game.getPlayer(source.getControllerId());
  MageObject sourceObject=source.getSourceObject(game);
  if (controller != null && sourceObject != null) {
    Set<String> permanentNames=new HashSet<>();
    for (    Permanent permanent : game.getBattlefield().getActivePermanents(source.getControllerId(),game)) {
      permanentNames.add(permanent.getName());
    }
    Cards cardsFromTop=new CardsImpl();
    cardsFromTop.addAll(controller.getLibrary().getTopCards(game,7));
    controller.lookAtCards(sourceObject.getIdName(),cardsFromTop,game);
    FilterCard filter=new FilterCard("String_Node_Str");
    List<NamePredicate> namePredicates=new ArrayList<>();
    for (    String name : permanentNames) {
      namePredicates.add(new NamePredicate(name));
    }
    if (!namePredicates.isEmpty() && !cardsFromTop.isEmpty()) {
      filter.add(Predicates.or(namePredicates));
      TargetCard target=new TargetCard(Zone.LIBRARY,filter);
      if (cardsFromTop.count(filter,source.getSourceId(),source.getControllerId(),game) > 0 && controller.chooseUse(Outcome.PutCardInPlay,"String_Node_Str",source,game)) {
        if (controller.choose(Outcome.PutCardInPlay,cardsFromTop,target,game)) {
          Card card=cardsFromTop.get(target.getFirstTarget(),game);
          if (card != null) {
            controller.moveCards(card,Zone.BATTLEFIELD,source,game);
            cardsFromTop.remove(card);
          }
        }
      }
    }
    controller.putCardsOnBottomOfLibrary(cardsFromTop,game,source,true);
    return true;
  }
  return false;
}