nus-yam/ex-repair huggingface dataset:
Program: 158136
Project: 158136
Buggy source:
@Override public boolean apply(Game game,Ability source){
  Player controller=game.getPlayer(source.getControllerId());
  if (controller != null) {
    int xSum=0;
    xSum+=playerPaysXGenericMana(controller,source,game);
    for (    UUID playerId : game.getState().getPlayersInRange(controller.getId(),game)) {
      if (playerId != controller.getId()) {
        Player player=game.getPlayer(playerId);
        if (player != null) {
          xSum+=playerPaysXGenericMana(player,source,game);
        }
      }
    }
    for (    UUID playerId : game.getState().getPlayersInRange(controller.getId(),game)) {
      Player player=game.getPlayer(playerId);
      if (player != null) {
        TargetCardInLibrary target=new TargetCardInLibrary(0,xSum,new FilterBasicLandCard());
        if (player.searchLibrary(target,game)) {
          for (          UUID cardId : target.getTargets()) {
            Card card=player.getLibrary().getCard(cardId,game);
            if (card != null) {
              card.putOntoBattlefield(game,Zone.LIBRARY,source.getSourceId(),player.getId(),true);
            }
          }
          player.shuffleLibrary(source,game);
        }
      }
    }
    controller.resetStoredBookmark(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) {
    int xSum=0;
    xSum+=playerPaysXGenericMana(controller,source,game);
    for (    UUID playerId : game.getState().getPlayersInRange(controller.getId(),game)) {
      if (!Objects.equals(playerId,controller.getId())) {
        Player player=game.getPlayer(playerId);
        if (player != null) {
          xSum+=playerPaysXGenericMana(player,source,game);
        }
      }
    }
    for (    UUID playerId : game.getState().getPlayersInRange(controller.getId(),game)) {
      Player player=game.getPlayer(playerId);
      if (player != null) {
        TargetCardInLibrary target=new TargetCardInLibrary(0,xSum,new FilterBasicLandCard());
        if (player.searchLibrary(target,game)) {
          for (          UUID cardId : target.getTargets()) {
            Card card=player.getLibrary().getCard(cardId,game);
            if (card != null) {
              card.putOntoBattlefield(game,Zone.LIBRARY,source.getSourceId(),player.getId(),true);
            }
          }
          player.shuffleLibrary(source,game);
        }
      }
    }
    controller.resetStoredBookmark(game);
    return true;
  }
  return false;
}
Program: 158137
Project: 158137
Buggy source:
@Override public boolean apply(Game game,Ability source){
  Player controller=game.getPlayer(source.getControllerId());
  Player newController=game.getPlayer(getTargetPointer().getFirst(game,source));
  if (controller != null && newController != null && controller.getId() != newController.getId()) {
    ContinuousEffect effect=new GainControlTargetEffect(Duration.Custom,newController.getId());
    effect.setTargetPointer(new FixedTarget(source.getSourceId()));
    game.addEffect(effect,source);
    return true;
  }
  return false;
}

Fixed version (ground truth):
@Override public boolean apply(Game game,Ability source){
  Player controller=game.getPlayer(source.getControllerId());
  Player newController=game.getPlayer(getTargetPointer().getFirst(game,source));
  if (controller != null && newController != null && !Objects.equals(controller.getId(),newController.getId())) {
    ContinuousEffect effect=new GainControlTargetEffect(Duration.Custom,newController.getId());
    effect.setTargetPointer(new FixedTarget(source.getSourceId()));
    game.addEffect(effect,source);
    return true;
  }
  return false;
}
Program: 158138
Project: 158138
Buggy source:
@Override public boolean applies(UUID objectId,Ability source,UUID affectedControllerId,Game game){
  return source.getControllerId().equals(affectedControllerId) && objectId == ((FixedTarget)getTargetPointer()).getTarget() && ((FixedTarget)getTargetPointer()).getZoneChangeCounter() + 1 == game.getState().getZoneChangeCounter(objectId) && (((FixedTarget)getTargetPointer()).getZoneChangeCounter() + 1 == game.getState().getZoneChangeCounter(objectId)) && game.getState().getZone(objectId).equals(Zone.STACK);
}

Fixed version (ground truth):
@Override public boolean applies(UUID objectId,Ability source,UUID affectedControllerId,Game game){
  return source.getControllerId().equals(affectedControllerId) && Objects.equals(objectId,((FixedTarget)getTargetPointer()).getTarget()) && ((FixedTarget)getTargetPointer()).getZoneChangeCounter() + 1 == game.getState().getZoneChangeCounter(objectId) && (((FixedTarget)getTargetPointer()).getZoneChangeCounter() + 1 == game.getState().getZoneChangeCounter(objectId)) && game.getState().getZone(objectId).equals(Zone.STACK);
}
Program: 158139
Project: 158139
Buggy source:
@Override public boolean checkTrigger(GameEvent event,Game game){
  if (event.getData().equals(CounterType.INTERVENTION.getName()) && event.getTargetId().equals(this.getSourceId())) {
    boolean onlyYouOnStack=true;
    boolean onlyOpponentOnStack=true;
    UUID you=getControllerId();
    boolean firstOnStack=false;
    for (    StackObject stackObject : game.getStack()) {
      if (stackObject.getControllerId() != null && !firstOnStack) {
        if (you != stackObject.getControllerId()) {
          onlyYouOnStack=false;
        }
 else         if (you == stackObject.getControllerId()) {
          onlyOpponentOnStack=false;
        }
        firstOnStack=true;
      }
    }
    if (onlyYouOnStack && !onlyOpponentOnStack) {
      return true;
    }
 else     if (!onlyYouOnStack && onlyOpponentOnStack) {
      return false;
    }
  }
  return false;
}

Fixed version (ground truth):
@Override public boolean checkTrigger(GameEvent event,Game game){
  if (event.getData().equals(CounterType.INTERVENTION.getName()) && event.getTargetId().equals(this.getSourceId())) {
    boolean onlyYouOnStack=true;
    boolean onlyOpponentOnStack=true;
    UUID you=getControllerId();
    boolean firstOnStack=false;
    for (    StackObject stackObject : game.getStack()) {
      if (stackObject.getControllerId() != null && !firstOnStack) {
        if (!Objects.equals(you,stackObject.getControllerId())) {
          onlyYouOnStack=false;
        }
 else         if (Objects.equals(you,stackObject.getControllerId())) {
          onlyOpponentOnStack=false;
        }
        firstOnStack=true;
      }
    }
    if (onlyYouOnStack && !onlyOpponentOnStack) {
      return true;
    }
 else     if (!onlyYouOnStack && onlyOpponentOnStack) {
      return false;
    }
  }
  return false;
}
Program: 158140
Project: 158140
Buggy source:
@Override public boolean apply(Game game,Ability source){
  Player controller=game.getPlayer(source.getControllerId());
  if (controller != null) {
    Target target=new TargetCreaturePermanent(0,1,new FilterCreaturePermanent("String_Node_Str"),true);
    target.setRequired(true);
    Permanent creatureToKeep=null;
    if (controller.choose(outcome,target,source.getSourceId(),game)) {
      creatureToKeep=game.getPermanent(target.getFirstTarget());
    }
    for (    Permanent creature : game.getBattlefield().getActivePermanents(new FilterCreaturePermanent(),source.getControllerId(),source.getSourceId(),game)) {
      if (creature != creatureToKeep) {
        creature.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());
  if (controller != null) {
    Target target=new TargetCreaturePermanent(0,1,new FilterCreaturePermanent("String_Node_Str"),true);
    target.setRequired(true);
    Permanent creatureToKeep=null;
    if (controller.choose(outcome,target,source.getSourceId(),game)) {
      creatureToKeep=game.getPermanent(target.getFirstTarget());
    }
    for (    Permanent creature : game.getBattlefield().getActivePermanents(new FilterCreaturePermanent(),source.getControllerId(),source.getSourceId(),game)) {
      if (!Objects.equals(creature,creatureToKeep)) {
        creature.destroy(source.getSourceId(),game,false);
      }
    }
    return true;
  }
  return false;
}
Program: 158141
Project: 158141
Buggy source:
@Override public boolean applies(GameEvent event,Ability source,Game game){
  if (event.getType() == GameEvent.EventType.DAMAGE_PLAYER) {
    if (event.getTargetId().equals(source.getControllerId()) && game.getControllerId(event.getSourceId()) != source.getControllerId()) {
      return super.applies(event,source,game);
    }
  }
  return false;
}

Fixed version (ground truth):
@Override public boolean applies(GameEvent event,Ability source,Game game){
  if (event.getType() == GameEvent.EventType.DAMAGE_PLAYER) {
    if (event.getTargetId().equals(source.getControllerId()) && !Objects.equals(game.getControllerId(event.getSourceId()),source.getControllerId())) {
      return super.applies(event,source,game);
    }
  }
  return false;
}
Program: 158142
Project: 158142
Buggy source:
@Override public boolean apply(Game game,Ability source){
  Player controller=game.getPlayer(source.getControllerId());
  Player targetPlayer=game.getPlayer(getTargetPointer().getFirst(game,source));
  if (controller != null && targetPlayer != null) {
    if (targetPlayer != controller) {
      phaseOutCardType(controller,targetPlayer,CardType.LAND,source,game);
      phaseOutCardType(controller,targetPlayer,CardType.ARTIFACT,source,game);
      phaseOutCardType(controller,targetPlayer,CardType.CREATURE,source,game);
    }
    return true;
  }
  return false;
}

Fixed version (ground truth):
@Override public boolean apply(Game game,Ability source){
  Player controller=game.getPlayer(source.getControllerId());
  Player targetPlayer=game.getPlayer(getTargetPointer().getFirst(game,source));
  if (controller != null && targetPlayer != null) {
    if (!Objects.equals(targetPlayer,controller)) {
      phaseOutCardType(controller,targetPlayer,CardType.LAND,source,game);
      phaseOutCardType(controller,targetPlayer,CardType.ARTIFACT,source,game);
      phaseOutCardType(controller,targetPlayer,CardType.CREATURE,source,game);
    }
    return true;
  }
  return false;
}
Program: 158143
Project: 158143
Buggy source:
@Override public boolean apply(Game game,Ability source){
  HashMap<UUID,Integer> toDestroy=new HashMap<>();
  Permanent etbPermanent=game.getPermanentOrLKIBattlefield(getTargetPointer().getFirst(game,source));
  if (etbPermanent == null) {
    return false;
  }
  String cn=etbPermanent.getName();
  for (  Permanent permanent : game.getBattlefield().getActivePermanents(filter,source.getControllerId(),source.getSourceId(),game)) {
    String cardName=permanent.getName();
    if (cardName.equals(cn) && permanent.getId() != etbPermanent.getId()) {
      toDestroy.put(permanent.getId(),1);
    }
  }
  for (  UUID id : toDestroy.keySet()) {
    Permanent permanent=game.getPermanent(id);
    if (permanent != null) {
      permanent.destroy(source.getSourceId(),game,false);
    }
  }
  return true;
}

Fixed version (ground truth):
@Override public boolean apply(Game game,Ability source){
  HashMap<UUID,Integer> toDestroy=new HashMap<>();
  Permanent etbPermanent=game.getPermanentOrLKIBattlefield(getTargetPointer().getFirst(game,source));
  if (etbPermanent == null) {
    return false;
  }
  String cn=etbPermanent.getName();
  for (  Permanent permanent : game.getBattlefield().getActivePermanents(filter,source.getControllerId(),source.getSourceId(),game)) {
    String cardName=permanent.getName();
    if (cardName.equals(cn) && !Objects.equals(permanent.getId(),etbPermanent.getId())) {
      toDestroy.put(permanent.getId(),1);
    }
  }
  for (  UUID id : toDestroy.keySet()) {
    Permanent permanent=game.getPermanent(id);
    if (permanent != null) {
      permanent.destroy(source.getSourceId(),game,false);
    }
  }
  return true;
}
Program: 158144
Project: 158144
Buggy source:
@Override public boolean checkTrigger(GameEvent event,Game game){
  if (event.getData().equals(CounterType.ENERGY.getName())) {
    return event.getTargetId() == this.getControllerId();
  }
  return false;
}

Fixed version (ground truth):
@Override public boolean checkTrigger(GameEvent event,Game game){
  if (event.getData().equals(CounterType.ENERGY.getName())) {
    return Objects.equals(event.getTargetId(),this.getControllerId());
  }
  return false;
}
Program: 158145
Project: 158145
Buggy source:
@Override public boolean applies(GameEvent event,Ability source,Game game){
  Permanent sourceObject=game.getPermanent(source.getSourceId());
  Permanent targetPermanent=game.getPermanent(event.getTargetId());
  Permanent guardianBeast=game.getPermanent(guardianBeastId);
  if (guardianBeast == null || guardianBeast.isTapped() || sourceObject == null || targetPermanent == null) {
    return false;
  }
  if (targetPermanent.getControllerId() != guardianBeast.getControllerId()) {
    return false;
  }
  StackObject spell=game.getStack().getStackObject(event.getSourceId());
  if (event.getType() == EventType.LOSE_CONTROL || event.getType() == EventType.ATTACH || event.getType() == EventType.TARGET && spell != null && spell.getCardType().contains(CardType.ENCHANTMENT) && spell.getSubtype(game).contains("String_Node_Str")) {
    for (    Permanent perm : game.getBattlefield().getAllActivePermanents(filter,source.getControllerId(),game)) {
      if (perm != null && perm.getId() == targetPermanent.getId() && !perm.getCardType().contains(CardType.CREATURE)) {
        return true;
      }
    }
  }
  return false;
}

Fixed version (ground truth):
@Override public boolean applies(GameEvent event,Ability source,Game game){
  Permanent sourceObject=game.getPermanent(source.getSourceId());
  Permanent targetPermanent=game.getPermanent(event.getTargetId());
  Permanent guardianBeast=game.getPermanent(guardianBeastId);
  if (guardianBeast == null || guardianBeast.isTapped() || sourceObject == null || targetPermanent == null) {
    return false;
  }
  if (!Objects.equals(targetPermanent.getControllerId(),guardianBeast.getControllerId())) {
    return false;
  }
  StackObject spell=game.getStack().getStackObject(event.getSourceId());
  if (event.getType() == EventType.LOSE_CONTROL || event.getType() == EventType.ATTACH || event.getType() == EventType.TARGET && spell != null && spell.getCardType().contains(CardType.ENCHANTMENT) && spell.getSubtype(game).contains("String_Node_Str")) {
    for (    Permanent perm : game.getBattlefield().getAllActivePermanents(filter,source.getControllerId(),game)) {
      if (perm != null && Objects.equals(perm.getId(),targetPermanent.getId()) && !perm.getCardType().contains(CardType.CREATURE)) {
        return true;
      }
    }
  }
  return false;
}
Program: 158146
Project: 158146
Buggy source:
@Override public boolean apply(Game game,Ability source){
  Player player=game.getPlayer(source.getControllerId());
  Permanent hellcarverDemon=game.getPermanent(source.getSourceId());
  for (  Permanent permanent : game.getBattlefield().getActivePermanents(filterPermanents,source.getControllerId(),game)) {
    if (permanent != hellcarverDemon) {
      permanent.sacrifice(source.getSourceId(),game);
    }
  }
  if (player != null && !player.getHand().isEmpty()) {
    int cardsInHand=player.getHand().size();
    player.discard(cardsInHand,source,game);
  }
  for (int i=0; i < 6; i++) {
    if (player != null && player.getLibrary().size() > 0) {
      Card topCard=player.getLibrary().getFromTop(game);
      topCard.moveToExile(source.getSourceId(),"String_Node_Str",source.getSourceId(),game);
    }
  }
  while (player != null && player.canRespond() && player.chooseUse(Outcome.PlayForFree,"String_Node_Str",source,game)) {
    TargetCardInExile target=new TargetCardInExile(filter,source.getSourceId());
    while (player.choose(Outcome.PlayForFree,game.getExile().getExileZone(source.getSourceId()),target,game)) {
      Card card=game.getCard(target.getFirstTarget());
      if (card != null) {
        game.getExile().removeCard(card,game);
        player.cast(card.getSpellAbility(),game,true);
      }
      target.clearChosen();
    }
    return true;
  }
  return false;
}

Fixed version (ground truth):
@Override public boolean apply(Game game,Ability source){
  Player player=game.getPlayer(source.getControllerId());
  Permanent hellcarverDemon=game.getPermanent(source.getSourceId());
  for (  Permanent permanent : game.getBattlefield().getActivePermanents(filterPermanents,source.getControllerId(),game)) {
    if (!Objects.equals(permanent,hellcarverDemon)) {
      permanent.sacrifice(source.getSourceId(),game);
    }
  }
  if (player != null && !player.getHand().isEmpty()) {
    int cardsInHand=player.getHand().size();
    player.discard(cardsInHand,source,game);
  }
  for (int i=0; i < 6; i++) {
    if (player != null && player.getLibrary().size() > 0) {
      Card topCard=player.getLibrary().getFromTop(game);
      topCard.moveToExile(source.getSourceId(),"String_Node_Str",source.getSourceId(),game);
    }
  }
  while (player != null && player.canRespond() && player.chooseUse(Outcome.PlayForFree,"String_Node_Str",source,game)) {
    TargetCardInExile target=new TargetCardInExile(filter,source.getSourceId());
    while (player.choose(Outcome.PlayForFree,game.getExile().getExileZone(source.getSourceId()),target,game)) {
      Card card=game.getCard(target.getFirstTarget());
      if (card != null) {
        game.getExile().removeCard(card,game);
        player.cast(card.getSpellAbility(),game,true);
      }
      target.clearChosen();
    }
    return true;
  }
  return false;
}
Program: 158147
Project: 158147
Buggy source:
@Override public boolean checkTrigger(GameEvent event,Game game){
  Permanent equipment=game.getPermanent(this.getSourceId());
  if (equipment != null && equipment.getAttachedTo() != null) {
    if (event.getTargetId() == equipment.getAttachedTo()) {
      for (      Effect effect : this.getEffects()) {
        effect.setTargetPointer(new FixedTarget(equipment.getAttachedTo()));
      }
      return true;
    }
  }
  return false;
}

Fixed version (ground truth):
@Override public boolean checkTrigger(GameEvent event,Game game){
  Permanent equipment=game.getPermanent(this.getSourceId());
  if (equipment != null && equipment.getAttachedTo() != null) {
    if (Objects.equals(event.getTargetId(),equipment.getAttachedTo())) {
      for (      Effect effect : this.getEffects()) {
        effect.setTargetPointer(new FixedTarget(equipment.getAttachedTo()));
      }
      return true;
    }
  }
  return false;
}
Program: 158148
Project: 158148
Buggy source:
/** 
 * Removes all arrows from the screen.
 */
public void removeAllArrows(UUID gameId){
  if (map.containsKey(gameId)) {
    Map<Type,List<Arrow>> innerMap=map.get(gameId);
    JPanel p=getArrowsPanel(gameId);
    if (p != null && p.getComponentCount() > 0) {
      p.removeAll();
      p.revalidate();
      p.repaint();
    }
    innerMap.clear();
    map.remove(gameId);
  }
}

Fixed version (ground truth):
/** 
 * Removes all arrows from the screen.
 */
public void removeAllArrows(UUID gameId){
  if (map.containsKey(gameId)) {
    Map<Type,List<Arrow>> innerMap=map.get(gameId);
    JPanel p=getArrowsPanel(gameId);
synchronized (map) {
      if (p != null && p.getComponentCount() > 0) {
        p.removeAll();
        p.revalidate();
        p.repaint();
      }
      innerMap.clear();
      map.remove(gameId);
    }
  }
}
Program: 158149
Project: 158149
Buggy source:
/** 
 * Adds new arrow.
 * @param startX
 * @param startY
 * @param endX
 * @param endY
 * @param color
 */
public void addArrow(UUID gameId,int startX,int startY,int endX,int endY,Color color,Type type){
  JPanel p=getArrowsPanel(gameId);
  Arrow arrow=new Arrow();
  arrow.setColor(color);
  arrow.setArrowLocation(startX,startY,endX,endY);
  arrow.setBounds(0,0,Math.max(startX,endX) + 40,Math.max(startY,endY) + 30);
  p.add(arrow);
  Map<Type,List<Arrow>> innerMap=map.computeIfAbsent(gameId,k -> new HashMap<>());
  List<Arrow> arrows=innerMap.computeIfAbsent(type,k -> new ArrayList<>());
  arrows.add(arrow);
  p.revalidate();
  p.repaint();
}

Fixed version (ground truth):
/** 
 * Adds new arrow.
 * @param startX
 * @param startY
 * @param endX
 * @param endY
 * @param color
 */
public void addArrow(UUID gameId,int startX,int startY,int endX,int endY,Color color,Type type){
  JPanel p=getArrowsPanel(gameId);
  Arrow arrow=new Arrow();
  arrow.setColor(color);
  arrow.setArrowLocation(startX,startY,endX,endY);
  arrow.setBounds(0,0,Math.max(startX,endX) + 40,Math.max(startY,endY) + 30);
synchronized (map) {
    p.add(arrow);
    Map<Type,java.util.List<Arrow>> innerMap=map.get(gameId);
    if (innerMap == null) {
      innerMap=new HashMap<Type,List<Arrow>>();
      map.put(gameId,innerMap);
    }
    java.util.List<Arrow> arrows=innerMap.get(type);
    if (arrows == null) {
      arrows=new ArrayList<Arrow>();
      innerMap.put(type,arrows);
    }
    arrows.add(arrow);
  }
  p.revalidate();
  p.repaint();
}
Program: 158150
Project: 158150
Buggy source:
public void removeArrowsByType(UUID gameId,Type type){
  if (map.containsKey(gameId)) {
    Map<Type,List<Arrow>> innerMap=map.get(gameId);
    java.util.List<Arrow> arrows=innerMap.get(type);
    if (arrows != null && !arrows.isEmpty()) {
      JPanel p=getArrowsPanel(gameId);
      for (      Arrow arrow : arrows) {
        p.remove(arrow);
      }
      innerMap.put(type,new ArrayList<>());
      p.revalidate();
      p.repaint();
    }
  }
}

Fixed version (ground truth):
public void removeArrowsByType(UUID gameId,Type type){
  if (map.containsKey(gameId)) {
    Map<Type,List<Arrow>> innerMap=map.get(gameId);
    java.util.List<Arrow> arrows=innerMap.get(type);
    if (arrows != null && arrows.size() > 0) {
      JPanel p=getArrowsPanel(gameId);
synchronized (map) {
        for (        Arrow arrow : arrows) {
          p.remove(arrow);
        }
        innerMap.put(type,new ArrayList<Arrow>());
      }
      p.revalidate();
      p.repaint();
    }
  }
}
Program: 158151
Project: 158151
Buggy source:
@Override public boolean apply(Game game,Ability source){
}

Fixed version (ground truth):
@Override public boolean apply(Game game,Ability source){
  Card card;
  Player controller=game.getPlayer(source.getControllerId());
  if (controller == null) {
    return false;
  }
  ExileZone exile=game.getExile().createZone(source.getSourceId(),controller.getName() + "String_Node_Str");
  int sourceCost=game.getCard(source.getSourceId()).getConvertedManaCost();
  do {
    card=controller.getLibrary().getFromTop(game);
    if (card == null) {
      break;
    }
    controller.moveCardsToExile(card,source,game,true,exile.getId(),exile.getName());
  }
 while (controller.isInGame() && (card.getCardType().contains(CardType.LAND) || !cardThatCostsLess(sourceCost,card,game)));
  controller.getLibrary().reset();
  if (card != null) {
    if (controller.chooseUse(outcome,"String_Node_Str" + card.getLogName() + '?',source,game)) {
      controller.cast(card.getSpellAbility(),game,true);
    }
    Cards cardsFromExile=new CardsImpl();
    Cards cardsToLibrary=new CardsImpl();
    cardsFromExile.addAll(exile);
    while (!cardsFromExile.isEmpty()) {
      card=cardsFromExile.getRandom(game);
      cardsFromExile.remove(card.getId());
      cardsToLibrary.add(card);
    }
    controller.putCardsOnBottomOfLibrary(cardsToLibrary,game,source,false);
  }
  return true;
}
Program: 158152
Project: 158152
Buggy source:
public void fireCallback(final ClientCallback call){
  if (isConnected()) {
    SessionManager.getInstance().getSession(sessionId).fireCallback(call);
  }
}

Fixed version (ground truth):
public void fireCallback(final ClientCallback call){
  if (isConnected()) {
    Session session=SessionManager.getInstance().getSession(sessionId);
    if (session != null) {
      session.fireCallback(call);
    }
  }
}
Program: 158153
Project: 158153
Buggy source:
private void defenderDamage(Permanent attacker,int amount,Game game){
  if (this.defenderIsPlaneswalker) {
    Permanent defender=game.getPermanent(defenderId);
    if (defender != null) {
      defender.markDamage(amount,attacker.getId(),game,true,true);
    }
  }
 else {
    Player defender=game.getPlayer(defenderId);
    defender.damage(amount,attacker.getId(),game,true,true);
  }
}

Fixed version (ground truth):
private void defenderDamage(Permanent attacker,int amount,Game game){
  if (this.defenderIsPlaneswalker) {
    Permanent defender=game.getPermanent(defenderId);
    if (defender != null) {
      defender.markDamage(amount,attacker.getId(),game,true,true);
    }
  }
 else {
    Player defender=game.getPlayer(defenderId);
    if (defender.isInGame()) {
      defender.damage(amount,attacker.getId(),game,true,true);
    }
  }
}
Program: 158154
Project: 158154
Buggy source:
@Override public boolean apply(Game game,Ability source){
  UUID exileId=source.getSourceId();
  Permanent targetPermanent=game.getPermanent(getTargetPointer().getFirst(game,source));
  if (targetPermanent != null) {
    UUID controllerPermanentId=targetPermanent.getControllerId();
    Player you=game.getPlayer(source.getControllerId());
    MageObject sourceObject=game.getObject(source.getSourceId());
    if (sourceObject != null && exileId != null && you != null) {
      int exiledCount=0;
      if (targetPermanent.getName().isEmpty()) {
        you.moveCardToExileWithInfo(targetPermanent,exileId,sourceObject.getIdName(),source.getSourceId(),game,Zone.BATTLEFIELD,true);
        exiledCount=1;
      }
 else {
        String name=targetPermanent.getName();
        for (        Permanent permanent : game.getBattlefield().getAllActivePermanents(controllerPermanentId)) {
          if (permanent != null && permanent.getName().equals(name)) {
            if (creaturesOnly.match(permanent,game)) {
              you.moveCardToExileWithInfo(permanent,null,"String_Node_Str",source.getSourceId(),game,Zone.BATTLEFIELD,true);
            }
            if (nonTokenFilter.match(permanent,game)) {
              exiledCount++;
            }
          }
        }
      }
      if (exiledCount > 0) {
        Token token=new ClueArtifactToken();
        token.putOntoBattlefield(exiledCount,game,source.getSourceId(),controllerPermanentId,false,false);
      }
      return true;
    }
  }
  return false;
}

Fixed version (ground truth):
@Override public boolean apply(Game game,Ability source){
  Player controller=game.getPlayer(source.getControllerId());
  MageObject sourceObject=game.getObject(source.getSourceId());
  if (sourceObject != null && controller != null) {
    Permanent targetPermanent=game.getPermanent(getTargetPointer().getFirst(game,source));
    if (targetPermanent != null) {
      Set<Card> cardsToExile=new HashSet<>();
      int nonTokenCount=0;
      if (targetPermanent.getName().isEmpty()) {
        cardsToExile.add(targetPermanent);
        if (!(targetPermanent instanceof PermanentToken)) {
          nonTokenCount++;
        }
      }
 else {
        for (        Permanent permanent : game.getBattlefield().getAllActivePermanents(new FilterCreaturePermanent(),targetPermanent.getControllerId(),game)) {
          if (!permanent.getId().equals(targetPermanent.getId()) && permanent.getName().equals(targetPermanent.getName())) {
            cardsToExile.add(permanent);
            if (!(permanent instanceof PermanentToken)) {
              nonTokenCount++;
            }
          }
        }
      }
      controller.moveCards(cardsToExile,Zone.EXILED,source,game);
      game.applyEffects();
      if (nonTokenCount > 0) {
        new ClueArtifactToken().putOntoBattlefield(nonTokenCount,game,source.getSourceId(),targetPermanent.getControllerId(),false,false);
      }
      return true;
    }
  }
  return false;
}
Program: 158155
Project: 158155
Buggy source:
@Test public void testBlockedByTwo22s(){
  addCard(Zone.BATTLEFIELD,playerA,"String_Node_Str");
  addCard(Zone.BATTLEFIELD,playerB,"String_Node_Str");
  addCard(Zone.BATTLEFIELD,playerB,"String_Node_Str");
  attack(3,playerA,"String_Node_Str");
  block(3,playerB,"String_Node_Str","String_Node_Str");
  block(3,playerB,"String_Node_Str","String_Node_Str");
  setStopAt(3,PhaseStep.POSTCOMBAT_MAIN);
  execute();
  assertLife(playerA,20);
  assertLife(playerB,20);
  assertPermanentCount(playerA,"String_Node_Str",1);
  assertGraveyardCount(playerA,"String_Node_Str",0);
  assertPermanentCount(playerB,"String_Node_Str",0);
  assertGraveyardCount(playerB,"String_Node_Str",1);
  assertPermanentCount(playerB,"String_Node_Str",0);
  assertGraveyardCount(playerB,"String_Node_Str",1);
}

Fixed version (ground truth):
@Test public void testBlockedByTwo22s(){
  addCard(Zone.BATTLEFIELD,playerA,"String_Node_Str");
  addCard(Zone.BATTLEFIELD,playerB,"String_Node_Str");
  addCard(Zone.BATTLEFIELD,playerB,"String_Node_Str");
  attack(3,playerA,"String_Node_Str");
  block(3,playerB,"String_Node_Str","String_Node_Str");
  block(3,playerB,"String_Node_Str","String_Node_Str");
  setStopAt(3,PhaseStep.POSTCOMBAT_MAIN);
  execute();
  assertLife(playerA,20);
  assertLife(playerB,20);
  assertGraveyardCount(playerA,"String_Node_Str",0);
  assertPermanentCount(playerA,"String_Node_Str",1);
  assertPermanentCount(playerB,"String_Node_Str",0);
  assertGraveyardCount(playerB,"String_Node_Str",1);
  assertPermanentCount(playerB,"String_Node_Str",0);
  assertGraveyardCount(playerB,"String_Node_Str",1);
}
Program: 158156
Project: 158156
Buggy source:
private void sendInfoAboutPlayersNotJoinedYet(){
  for (  Player player : game.getPlayers().values()) {
    if (!player.hasLeft() && player.isHuman()) {
      User user=getUserByPlayerId(player.getId()).get();
      if (user != null) {
        if (!user.isConnected()) {
          if (gameSessions.get(player.getId()) == null) {
            user.removeConstructing(player.getId());
            GameManager.getInstance().joinGame(game.getId(),user.getId());
            logger.debug("String_Node_Str" + player.getName() + "String_Node_Str"+ game.getId());
          }
          ChatManager.getInstance().broadcast(chatId,player.getName(),user.getPingInfo() + "String_Node_Str",MessageColor.BLUE,true,ChatMessage.MessageType.STATUS,null);
          if (user.getSecondsDisconnected() > 240) {
            logger.debug("String_Node_Str" + player.getName() + "String_Node_Str"+ game.getId());
            player.leave();
          }
        }
      }
 else       if (!player.hasLeft()) {
        logger.debug("String_Node_Str" + player.getName() + "String_Node_Str"+ game.getId());
        player.leave();
      }
    }
  }
  checkStart();
}

Fixed version (ground truth):
private void sendInfoAboutPlayersNotJoinedYet(){
  for (  Player player : game.getPlayers().values()) {
    if (!player.hasLeft() && player.isHuman()) {
      Optional<User> requestedUser=getUserByPlayerId(player.getId());
      if (requestedUser.isPresent()) {
        User user=requestedUser.get();
        if (!user.isConnected()) {
          if (gameSessions.get(player.getId()) == null) {
            user.removeConstructing(player.getId());
            GameManager.getInstance().joinGame(game.getId(),user.getId());
            logger.debug("String_Node_Str" + player.getName() + "String_Node_Str"+ game.getId());
          }
          ChatManager.getInstance().broadcast(chatId,player.getName(),user.getPingInfo() + "String_Node_Str",MessageColor.BLUE,true,ChatMessage.MessageType.STATUS,null);
          if (user.getSecondsDisconnected() > 240) {
            logger.debug("String_Node_Str" + player.getName() + "String_Node_Str"+ game.getId());
            player.leave();
          }
        }
      }
 else       if (!player.hasLeft()) {
        logger.debug("String_Node_Str" + player.getName() + "String_Node_Str"+ game.getId());
        player.leave();
      }
    }
  }
  checkStart();
}
Program: 158157
Project: 158157
Buggy source:
@Override public boolean apply(Game game,Ability source){
  Player controller=game.getPlayer(source.getControllerId());
  if (controller != null) {
    filter.add(new ConvertedManaCostPredicate(Filter.ComparisonType.LessThan,source.getManaCostsToPay().getX() + 1));
    TargetCardInLibrary target=new TargetCardInLibrary(filter);
    if (controller.searchLibrary(target,game)) {
      if (target.getTargets().size() > 0) {
        Card card=controller.getLibrary().getCard(target.getFirstTarget(),game);
        if (card != null) {
          controller.moveCards(card,Zone.BATTLEFIELD,source,game);
        }
      }
      controller.shuffleLibrary(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) {
    FilterCard advancedFilter=filter.copy();
    advancedFilter.add(new ConvertedManaCostPredicate(Filter.ComparisonType.LessThan,source.getManaCostsToPay().getX() + 1));
    TargetCardInLibrary target=new TargetCardInLibrary(advancedFilter);
    if (controller.searchLibrary(target,game)) {
      if (target.getTargets().size() > 0) {
        Card card=controller.getLibrary().getCard(target.getFirstTarget(),game);
        if (card != null) {
          controller.moveCards(card,Zone.BATTLEFIELD,source,game);
        }
      }
      controller.shuffleLibrary(source,game);
    }
    return true;
  }
  return false;
}
Program: 158158
Project: 158158
Buggy source:
public void requestPermissionToRollbackTurn(UUID requestingUserId,int numberTurns){
  if (!killed) {
    Optional<User> requestingUser=UserManager.getInstance().getUser(requestingUserId);
    Optional<User> requestedUser=UserManager.getInstance().getUser(userId);
    if (!requestedUser.isPresent() && !requestingUser.isPresent()) {
      String message;
switch (numberTurns) {
case 0:
        message="String_Node_Str";
      break;
case 1:
    message="String_Node_Str";
  break;
default :
message="String_Node_Str" + numberTurns + "String_Node_Str";
}
UserRequestMessage userRequestMessage=new UserRequestMessage("String_Node_Str" + requestedUser.get().getName(),message);
userRequestMessage.setRelatedUser(requestingUserId,requestingUser.get().getName());
userRequestMessage.setGameId(game.getId());
userRequestMessage.setButton1("String_Node_Str",PlayerAction.ADD_PERMISSION_TO_ROLLBACK_TURN);
userRequestMessage.setButton2("String_Node_Str",PlayerAction.DENY_PERMISSON_TO_ROLLBACK_TURN);
requestedUser.get().fireCallback(new ClientCallback("String_Node_Str",game.getId(),userRequestMessage));
}
}
}

Fixed version (ground truth):
public void requestPermissionToRollbackTurn(UUID requestingUserId,int numberTurns){
  if (!killed) {
    Optional<User> requestingUser=UserManager.getInstance().getUser(requestingUserId);
    Optional<User> requestedUser=UserManager.getInstance().getUser(userId);
    if (requestedUser.isPresent() && requestingUser.isPresent()) {
      String message;
switch (numberTurns) {
case 0:
        message="String_Node_Str";
      break;
case 1:
    message="String_Node_Str";
  break;
default :
message="String_Node_Str" + numberTurns + "String_Node_Str";
}
UserRequestMessage userRequestMessage=new UserRequestMessage("String_Node_Str" + requestedUser.get().getName(),message);
userRequestMessage.setRelatedUser(requestingUserId,requestingUser.get().getName());
userRequestMessage.setGameId(game.getId());
userRequestMessage.setButton1("String_Node_Str",PlayerAction.ADD_PERMISSION_TO_ROLLBACK_TURN);
userRequestMessage.setButton2("String_Node_Str",PlayerAction.DENY_PERMISSON_TO_ROLLBACK_TURN);
requestedUser.get().fireCallback(new ClientCallback("String_Node_Str",game.getId(),userRequestMessage));
}
}
}
Program: 158160
Project: 158160
Buggy source:
@Test public void testKessigForgemaster(){
  System.out.println("String_Node_Str");
  addCard(Zone.BATTLEFIELD,playerA,"String_Node_Str");
  addCard(Zone.BATTLEFIELD,playerB,"String_Node_Str");
  addCard(Zone.BATTLEFIELD,playerB,"String_Node_Str");
  addCard(Zone.BATTLEFIELD,playerA,"String_Node_Str");
  addCard(Zone.BATTLEFIELD,playerB,"String_Node_Str");
  addCard(Zone.HAND,playerA,"String_Node_Str");
  addCard(Zone.HAND,playerB,"String_Node_Str");
  castSpell(1,PhaseStep.PRECOMBAT_MAIN,playerA,"String_Node_Str");
  castSpell(2,PhaseStep.PRECOMBAT_MAIN,playerB,"String_Node_Str");
  attack(3,playerA,"String_Node_Str");
  block(3,playerB,"String_Node_Str","String_Node_Str");
  block(3,playerB,"String_Node_Str","String_Node_Str");
  setStopAt(3,PhaseStep.POSTCOMBAT_MAIN);
  execute();
  assertLife(playerA,20);
  assertLife(playerB,20);
  assertPermanentCount(playerA,"String_Node_Str",1);
  assertGraveyardCount(playerA,"String_Node_Str",0);
  assertPermanentCount(playerB,"String_Node_Str",0);
  assertGraveyardCount(playerB,"String_Node_Str",1);
  assertPermanentCount(playerB,"String_Node_Str",0);
  assertGraveyardCount(playerB,"String_Node_Str",1);
}

Fixed version (ground truth):
@Test public void testKessigForgemaster(){
  addCard(Zone.BATTLEFIELD,playerA,"String_Node_Str");
  addCard(Zone.BATTLEFIELD,playerB,"String_Node_Str");
  addCard(Zone.BATTLEFIELD,playerB,"String_Node_Str");
  addCard(Zone.BATTLEFIELD,playerA,"String_Node_Str");
  addCard(Zone.BATTLEFIELD,playerB,"String_Node_Str");
  addCard(Zone.HAND,playerA,"String_Node_Str");
  addCard(Zone.HAND,playerB,"String_Node_Str");
  castSpell(1,PhaseStep.PRECOMBAT_MAIN,playerA,"String_Node_Str");
  castSpell(2,PhaseStep.PRECOMBAT_MAIN,playerB,"String_Node_Str");
  attack(3,playerA,"String_Node_Str");
  block(3,playerB,"String_Node_Str","String_Node_Str");
  block(3,playerB,"String_Node_Str","String_Node_Str");
  setStopAt(3,PhaseStep.POSTCOMBAT_MAIN);
  execute();
  assertLife(playerA,20);
  assertLife(playerB,20);
  assertPermanentCount(playerA,"String_Node_Str",1);
  assertGraveyardCount(playerA,"String_Node_Str",0);
  assertPermanentCount(playerB,"String_Node_Str",0);
  assertGraveyardCount(playerB,"String_Node_Str",1);
  assertPermanentCount(playerB,"String_Node_Str",0);
  assertGraveyardCount(playerB,"String_Node_Str",1);
}
Program: 158161
Project: 158161
Buggy source:
@Test public void testBlockedByTwo22s(){
  addCard(Zone.BATTLEFIELD,playerA,"String_Node_Str");
  addCard(Zone.BATTLEFIELD,playerB,"String_Node_Str");
  addCard(Zone.BATTLEFIELD,playerB,"String_Node_Str");
  attack(3,playerA,"String_Node_Str");
  block(3,playerB,"String_Node_Str","String_Node_Str");
  block(3,playerB,"String_Node_Str","String_Node_Str");
  setStopAt(3,PhaseStep.POSTCOMBAT_MAIN);
  execute();
  assertLife(playerA,20);
  assertLife(playerB,20);
  assertPermanentCount(playerA,"String_Node_Str",1);
  assertGraveyardCount(playerA,"String_Node_Str",0);
  assertPermanentCount(playerB,"String_Node_Str",0);
  assertGraveyardCount(playerB,"String_Node_Str",1);
  assertPermanentCount(playerB,"String_Node_Str",0);
  assertGraveyardCount(playerB,"String_Node_Str",1);
  System.out.println("String_Node_Str");
}

Fixed version (ground truth):
@Test public void testBlockedByTwo22s(){
  addCard(Zone.BATTLEFIELD,playerA,"String_Node_Str");
  addCard(Zone.BATTLEFIELD,playerB,"String_Node_Str");
  addCard(Zone.BATTLEFIELD,playerB,"String_Node_Str");
  attack(3,playerA,"String_Node_Str");
  block(3,playerB,"String_Node_Str","String_Node_Str");
  block(3,playerB,"String_Node_Str","String_Node_Str");
  setStopAt(3,PhaseStep.POSTCOMBAT_MAIN);
  execute();
  assertLife(playerA,20);
  assertLife(playerB,20);
  assertPermanentCount(playerA,"String_Node_Str",1);
  assertGraveyardCount(playerA,"String_Node_Str",0);
  assertPermanentCount(playerB,"String_Node_Str",0);
  assertGraveyardCount(playerB,"String_Node_Str",1);
  assertPermanentCount(playerB,"String_Node_Str",0);
  assertGraveyardCount(playerB,"String_Node_Str",1);
}
Program: 158163
Project: 158163
Buggy source:
/** 
 * There's currently a bug with Possibility Storm and Zoetic Cavern. The way it's supposed to work is the P. Storm trigger exiles Zoetic Cavern and then uses last known information about the spell to determine the type of card the trigger is looking for(creature in this instance). Instead it's basing the type solely off what's printed on the card. What happened to me earlier was the trigger skipped right over an Emrakul and then revealed a Flooded Strand. I was prompted whether or not I wanted to "cast" Flooded Strand without paying it's cost. Eventually I clicked yes and it produced a Game Error that resulted in rollback. I recreated the error against an AI opponent and copied the code. Can't actually post it because the filter on this site claims it makes my post look too "spammy". Here's a screenshot of it instead(in spoiler tag).
 */
@Test public void TestWithZoeticCavern(){
  addCard(Zone.BATTLEFIELD,playerA,"String_Node_Str",3);
  addCard(Zone.BATTLEFIELD,playerA,"String_Node_Str",2);
  addCard(Zone.HAND,playerA,"String_Node_Str");
  addCard(Zone.LIBRARY,playerA,"String_Node_Str");
  skipInitShuffling();
  playLand(1,PhaseStep.PRECOMBAT_MAIN,playerA,"String_Node_Str");
  setChoice(playerA,"String_Node_Str");
  setStopAt(1,PhaseStep.BEGIN_COMBAT);
  execute();
  assertPermanentCount(playerA,"String_Node_Str",0);
  boolean zoeticCavernInLibrary=false;
  for (  Card card : playerA.getLibrary().getCards(currentGame)) {
    if (card.getName().equals("String_Node_Str")) {
      zoeticCavernInLibrary=true;
    }
  }
  Assert.assertEquals("String_Node_Str",true,zoeticCavernInLibrary);
  assertPermanentCount(playerA,"String_Node_Str",1);
}

Fixed version (ground truth):
/** 
 * There's currently a bug with Possibility Storm and Zoetic Cavern. The way it's supposed to work is the P. Storm trigger exiles Zoetic Cavern and then uses last known information about the spell to determine the type of card the trigger is looking for(creature in this instance). Instead it's basing the type solely off what's printed on the card. What happened to me earlier was the trigger skipped right over an Emrakul and then revealed a Flooded Strand. I was prompted whether or not I wanted to "cast" Flooded Strand without paying it's cost. Eventually I clicked yes and it produced a Game Error that resulted in rollback. I recreated the error against an AI opponent and copied the code. Can't actually post it because the filter on this site claims it makes my post look too "spammy". Here's a screenshot of it instead(in spoiler tag).
 */
@Test public void TestWithZoeticCavern(){
  addCard(Zone.BATTLEFIELD,playerA,"String_Node_Str",3);
  addCard(Zone.BATTLEFIELD,playerA,"String_Node_Str",1);
  addCard(Zone.HAND,playerA,"String_Node_Str");
  addCard(Zone.LIBRARY,playerA,"String_Node_Str");
  skipInitShuffling();
  playLand(1,PhaseStep.PRECOMBAT_MAIN,playerA,"String_Node_Str");
  setChoice(playerA,"String_Node_Str");
  setStopAt(1,PhaseStep.BEGIN_COMBAT);
  execute();
  assertPermanentCount(playerA,"String_Node_Str",0);
  assertLibraryCount(playerA,"String_Node_Str",1);
  assertPermanentCount(playerA,"String_Node_Str",1);
}
Program: 158164
Project: 158164
Buggy source:
/** 
 * Moves the cards from cards to the bottom of the players library.
 * @param cards - list of cards that have to be moved
 * @param game - game
 * @param anyOrder - true if player can determine the order of the cards
 * @param source - source ability
 * @return
 */
boolean putCardsOnBottomOfLibrary(Cards cards,Game game,Ability source,boolean anyOrder);

Fixed version (ground truth):
/** 
 * Moves the cards from cards to the bottom of the players library.
 * @param cards - list of cards that have to be moved
 * @param game - game
 * @param anyOrder - true if player can determine the order of the cardselse random order
 * @param source - source ability
 * @return
 */
boolean putCardsOnBottomOfLibrary(Cards cards,Game game,Ability source,boolean anyOrder);
Program: 158165
Project: 158165
Buggy source:
/** 
 * Can be cards or permanents that go to library
 * @param cardsToLibrary
 * @param game
 * @param source
 * @param anyOrder
 * @return
 */
@Override public boolean putCardsOnTopOfLibrary(Cards cardsToLibrary,Game game,Ability source,boolean anyOrder){
  if (cardsToLibrary != null && !cardsToLibrary.isEmpty()) {
    Cards cards=new CardsImpl(cardsToLibrary);
    UUID sourceId=(source == null ? null : source.getSourceId());
    if (!anyOrder) {
      for (      UUID cardId : cards) {
        moveObjectToLibrary(cardId,sourceId,game,true,false);
      }
    }
 else {
      TargetCard target=new TargetCard(Zone.LIBRARY,new FilterCard("String_Node_Str"));
      target.setRequired(true);
      while (cards.size() > 1) {
        this.choose(Outcome.Neutral,cards,target,game);
        if (!canRespond()) {
          return false;
        }
        UUID targetObjectId=target.getFirstTarget();
        cards.remove(targetObjectId);
        moveObjectToLibrary(targetObjectId,sourceId,game,true,false);
        target.clearChosen();
      }
      if (cards.size() == 1) {
        moveObjectToLibrary(cards.iterator().next(),sourceId,game,true,false);
      }
    }
  }
  return true;
}

Fixed version (ground truth):
/** 
 * Can be cards or permanents that go to library
 * @param cardsToLibrary
 * @param game
 * @param source
 * @param anyOrder
 * @return
 */
@Override public boolean putCardsOnTopOfLibrary(Cards cardsToLibrary,Game game,Ability source,boolean anyOrder){
  if (cardsToLibrary != null && !cardsToLibrary.isEmpty()) {
    Cards cards=new CardsImpl(cardsToLibrary);
    UUID sourceId=(source == null ? null : source.getSourceId());
    if (!anyOrder) {
      while (!cards.isEmpty()) {
        UUID cardId=cards.getRandom(game).getId();
        cards.remove(cardId);
        moveObjectToLibrary(cardId,source == null ? null : source.getSourceId(),game,true,false);
      }
    }
 else {
      TargetCard target=new TargetCard(Zone.LIBRARY,new FilterCard("String_Node_Str"));
      target.setRequired(true);
      while (cards.size() > 1) {
        this.choose(Outcome.Neutral,cards,target,game);
        if (!canRespond()) {
          return false;
        }
        UUID targetObjectId=target.getFirstTarget();
        cards.remove(targetObjectId);
        moveObjectToLibrary(targetObjectId,sourceId,game,true,false);
        target.clearChosen();
      }
      if (cards.size() == 1) {
        moveObjectToLibrary(cards.iterator().next(),sourceId,game,true,false);
      }
    }
  }
  return true;
}
Program: 158166
Project: 158166
Buggy source:
@Override public boolean putCardsOnBottomOfLibrary(Cards cardsToLibrary,Game game,Ability source,boolean anyOrder){
  if (!cardsToLibrary.isEmpty()) {
    Cards cards=new CardsImpl(cardsToLibrary);
    if (!anyOrder) {
      for (      UUID objectId : cards) {
        moveObjectToLibrary(objectId,source == null ? null : source.getSourceId(),game,false,false);
      }
    }
 else {
      TargetCard target=new TargetCard(Zone.ALL,new FilterCard("String_Node_Str"));
      target.setRequired(true);
      while (cards.size() > 1) {
        this.choose(Outcome.Neutral,cards,target,game);
        if (!canRespond()) {
          return false;
        }
        UUID targetObjectId=target.getFirstTarget();
        cards.remove(targetObjectId);
        moveObjectToLibrary(targetObjectId,source == null ? null : source.getSourceId(),game,false,false);
        target.clearChosen();
      }
      if (cards.size() == 1) {
        moveObjectToLibrary(cards.iterator().next(),source == null ? null : source.getSourceId(),game,false,false);
      }
    }
  }
  return true;
}

Fixed version (ground truth):
@Override public boolean putCardsOnBottomOfLibrary(Cards cardsToLibrary,Game game,Ability source,boolean anyOrder){
  if (!cardsToLibrary.isEmpty()) {
    Cards cards=new CardsImpl(cardsToLibrary);
    if (!anyOrder) {
      while (!cards.isEmpty()) {
        UUID cardId=cards.getRandom(game).getId();
        cards.remove(cardId);
        moveObjectToLibrary(cardId,source == null ? null : source.getSourceId(),game,false,false);
      }
    }
 else {
      TargetCard target=new TargetCard(Zone.ALL,new FilterCard("String_Node_Str"));
      target.setRequired(true);
      while (cards.size() > 1) {
        this.choose(Outcome.Neutral,cards,target,game);
        if (!canRespond()) {
          return false;
        }
        UUID targetObjectId=target.getFirstTarget();
        cards.remove(targetObjectId);
        moveObjectToLibrary(targetObjectId,source == null ? null : source.getSourceId(),game,false,false);
        target.clearChosen();
      }
      if (cards.size() == 1) {
        moveObjectToLibrary(cards.iterator().next(),source == null ? null : source.getSourceId(),game,false,false);
      }
    }
  }
  return true;
}