nus-yam/ex-repair huggingface dataset:
Program: 158406
Project: 158406
Buggy source:
@Override public boolean putCardsOnBottomOfLibrary(Cards cards,Game game,Ability source,boolean anyOrder){
  if (!cards.isEmpty()) {
    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 (isInGame() && cards.size() > 1) {
        this.choose(Outcome.Neutral,cards,target,game);
        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) {
      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 (isInGame() && cards.size() > 1) {
        this.choose(Outcome.Neutral,cards,target,game);
        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;
}
Program: 158408
Project: 158408
Buggy source:
public static List<ZoneChangeInfo> moveCards(List<ZoneChangeInfo> zoneChangeInfos,Game game){
  for (ListIterator<ZoneChangeInfo> itr=zoneChangeInfos.listIterator(); itr.hasNext(); ) {
    ZoneChangeInfo info=itr.next();
    MeldCard card=game.getMeldCard(info.event.getTargetId());
    if (card != null && !card.isMelded() && !card.isCopy()) {
      ZoneChangeInfo.Unmelded unmelded=new ZoneChangeInfo.Unmelded(info,game);
      if (unmelded.subInfo.isEmpty()) {
        itr.remove();
      }
 else {
        itr.set(unmelded);
      }
    }
  }
  for (Iterator<ZoneChangeInfo> itr=zoneChangeInfos.iterator(); itr.hasNext(); ) {
    if (!maybeRemoveFromSourceZone(itr.next(),game)) {
      itr.remove();
    }
  }
  for (  ZoneChangeInfo zoneChangeInfo : zoneChangeInfos) {
    placeInDestinationZone(zoneChangeInfo,game);
    game.addSimultaneousEvent(zoneChangeInfo.event);
  }
  return zoneChangeInfos;
}

Fixed version (ground truth):
public static List<ZoneChangeInfo> moveCards(List<ZoneChangeInfo> zoneChangeInfos,Game game){
  for (ListIterator<ZoneChangeInfo> itr=zoneChangeInfos.listIterator(); itr.hasNext(); ) {
    ZoneChangeInfo info=itr.next();
    MeldCard card=game.getMeldCard(info.event.getTargetId());
    if (card != null && !card.isMelded() && !card.isCopy()) {
      ZoneChangeInfo.Unmelded unmelded=new ZoneChangeInfo.Unmelded(info,game);
      if (unmelded.subInfo.isEmpty()) {
        itr.remove();
      }
 else {
        itr.set(unmelded);
      }
    }
  }
  for (Iterator<ZoneChangeInfo> itr=zoneChangeInfos.iterator(); itr.hasNext(); ) {
    if (!maybeRemoveFromSourceZone(itr.next(),game)) {
      itr.remove();
    }
  }
  for (  ZoneChangeInfo zoneChangeInfo : zoneChangeInfos) {
    placeInDestinationZone(zoneChangeInfo,game);
    if (game.getPhase() != null) {
      game.addSimultaneousEvent(zoneChangeInfo.event);
    }
  }
  return zoneChangeInfos;
}
Program: 158409
Project: 158409
Buggy source:
@Override public boolean apply(Game game,Ability source){
  Permanent permanent=affectedObjectList.get(0).getPermanent(game);
  if (permanent == null) {
    permanent=(Permanent)game.getLastKnownInformation(getSourceId(),Zone.BATTLEFIELD,source.getSourceObjectZoneChangeCounter());
    if (permanent == null) {
      discard();
      return false;
    }
  }
  return copyToPermanent(permanent,game,source);
}

Fixed version (ground truth):
@Override public boolean apply(Game game,Ability source){
  if (affectedObjectList.isEmpty()) {
    this.discard();
    return false;
  }
  Permanent permanent=affectedObjectList.get(0).getPermanent(game);
  if (permanent == null) {
    permanent=(Permanent)game.getLastKnownInformation(getSourceId(),Zone.BATTLEFIELD,source.getSourceObjectZoneChangeCounter());
    if (permanent == null) {
      discard();
      return false;
    }
  }
  return copyToPermanent(permanent,game,source);
}
Program: 158410
Project: 158410
Buggy source:
@Override public boolean apply(Game game,Ability source){
  Player targetPlayer=game.getPlayer(targetPointer.getFirst(game,source));
  Player controller=game.getPlayer(source.getControllerId());
  MageObject sourceObject=game.getObject(source.getSourceId());
  if (targetPlayer != null && controller != null && sourceObject != null) {
    String cardName=(String)game.getState().getValue(source.getSourceId().toString() + NameACardEffect.INFO_KEY);
    for (    Card card : targetPlayer.getHand().getCards(game)) {
      if (card.getName().equals(cardName)) {
        targetPlayer.discard(card,source,game);
      }
    }
    controller.lookAtCards(sourceObject.getName() + "String_Node_Str",targetPlayer.getHand(),game);
  }
  return true;
}

Fixed version (ground truth):
@Override public boolean apply(Game game,Ability source){
  Player targetPlayer=game.getPlayer(targetPointer.getFirst(game,source));
  Player controller=game.getPlayer(source.getControllerId());
  MageObject sourceObject=game.getObject(source.getSourceId());
  if (targetPlayer != null && controller != null && sourceObject != null) {
    String cardName=(String)game.getState().getValue(source.getSourceId().toString() + NameACardEffect.INFO_KEY);
    Cards hand=targetPlayer.getHand();
    for (    Card card : hand.getCards(game)) {
      if (card.getName().equals(cardName)) {
        targetPlayer.discard(card,source,game);
      }
    }
    targetPlayer.revealCards("String_Node_Str",hand,game);
  }
  return true;
}
Program: 158411
Project: 158411
Buggy source:
private static BufferedImage createImage(Key key){
  int cardWidth=key.cardWidth;
  int cardHeight=key.cardHeight;
  int cardXOffset=key.cardXOffset;
  int cardYOffset=key.cardYOffset;
  BufferedImage image=GraphicsUtilities.createCompatibleTranslucentImage(key.width,key.height);
  Graphics2D g2d=image.createGraphics();
  g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
  if (!key.hasImage) {
    g2d.setColor(new Color(30,200,200,120));
  }
 else {
    g2d.setColor(new Color(0,0,0,255));
  }
  int cornerSize=Math.max(4,Math.round(cardWidth * ROUNDED_CORNER_SIZE));
  g2d.fillRoundRect(cardXOffset,cardYOffset,cardWidth,cardHeight,cornerSize,cornerSize);
  if (key.isSelected) {
    g2d.setColor(Color.green);
    g2d.fillRoundRect(cardXOffset + 1,cardYOffset + 1,cardWidth - 2,cardHeight - 2,cornerSize,cornerSize);
  }
 else   if (key.isChoosable) {
    g2d.setColor(new Color(250,250,0,230));
    g2d.fillRoundRect(cardXOffset + 1,cardYOffset + 1,cardWidth - 2,cardHeight - 2,cornerSize,cornerSize);
  }
 else   if (key.isPlayable) {
    g2d.setColor(new Color(153,102,204,200));
    g2d.fillRoundRect(cardXOffset,cardYOffset,cardWidth,cardHeight,cornerSize,cornerSize);
  }
  if (key.canAttack) {
    g2d.setColor(new Color(0,0,255,230));
    g2d.fillRoundRect(cardXOffset + 1,cardYOffset + 1,cardWidth - 2,cardHeight - 2,cornerSize,cornerSize);
  }
  g2d.dispose();
  return image;
}

Fixed version (ground truth):
private static BufferedImage createImage(Key key){
  int cardWidth=key.cardWidth;
  int cardHeight=key.cardHeight;
  int cardXOffset=key.cardXOffset;
  int cardYOffset=key.cardYOffset;
  BufferedImage image=GraphicsUtilities.createCompatibleTranslucentImage(key.width,key.height);
  Graphics2D g2d=image.createGraphics();
  g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
  if (!key.hasImage) {
    g2d.setColor(new Color(30,200,200,120));
  }
 else {
    g2d.setColor(new Color(0,0,0,0));
  }
  int cornerSize=Math.max(4,Math.round(cardWidth * ROUNDED_CORNER_SIZE));
  g2d.fillRoundRect(cardXOffset,cardYOffset,cardWidth,cardHeight,cornerSize,cornerSize);
  if (key.isSelected) {
    g2d.setColor(Color.green);
    g2d.fillRoundRect(cardXOffset + 1,cardYOffset + 1,cardWidth - 2,cardHeight - 2,cornerSize,cornerSize);
  }
 else   if (key.isChoosable) {
    g2d.setColor(new Color(250,250,0,230));
    g2d.fillRoundRect(cardXOffset + 1,cardYOffset + 1,cardWidth - 2,cardHeight - 2,cornerSize,cornerSize);
  }
 else   if (key.isPlayable) {
    g2d.setColor(new Color(153,102,204,200));
    g2d.fillRoundRect(cardXOffset,cardYOffset,cardWidth,cardHeight,cornerSize,cornerSize);
  }
  if (key.canAttack) {
    g2d.setColor(new Color(0,0,255,230));
    g2d.fillRoundRect(cardXOffset + 1,cardYOffset + 1,cardWidth - 2,cardHeight - 2,cornerSize,cornerSize);
  }
  g2d.dispose();
  return image;
}
Program: 158412
Project: 158412
Buggy source:
/** 
 * Swap cards between specified card from library and any hand card.
 * @param game
 * @param card Card to put to player's hand
 */
private static void swapWithAnyCard(Game game,Player player,Card card,Zone zone){
  game.getExile().getPermanentExile().add(card);
  game.setZone(card.getId(),Zone.EXILED);
  if (zone.equals(Zone.BATTLEFIELD)) {
    card.putOntoBattlefield(game,Zone.EXILED,null,player.getId());
  }
 else   if (zone.equals(Zone.LIBRARY)) {
    card.setZone(Zone.LIBRARY,game);
    player.getLibrary().putOnTop(card,game);
  }
 else {
    card.moveToZone(zone,null,game,false);
  }
  logger.info("String_Node_Str" + zone.toString() + "String_Node_Str"+ card.getName()+ "String_Node_Str"+ player.getName());
}

Fixed version (ground truth):
/** 
 * Swap cards between specified card from library and any hand card.
 * @param game
 * @param card Card to put to player's hand
 */
private static void swapWithAnyCard(Game game,Player player,Card card,Zone zone){
  game.getExile().getPermanentExile().add(card);
  game.setZone(card.getId(),Zone.EXILED);
  if (zone.equals(Zone.BATTLEFIELD)) {
    card.putOntoBattlefield(game,Zone.EXILED,null,player.getId());
  }
 else   if (zone.equals(Zone.LIBRARY)) {
    card.setZone(Zone.LIBRARY,game);
    game.getExile().getPermanentExile().remove(card);
    player.getLibrary().putOnTop(card,game);
  }
 else {
    card.moveToZone(zone,null,game,false);
  }
  logger.info("String_Node_Str" + zone.toString() + "String_Node_Str"+ card.getName()+ "String_Node_Str"+ player.getName());
}
Program: 158413
Project: 158413
Buggy source:
@Override public boolean apply(Game game,Ability source){
  for (  UUID targetID : this.targetPointer.getTargets(game,source)) {
    Permanent permanent=game.getPermanent(targetID);
    if (permanent != null) {
      if (permanent.destroy(source.getSourceId(),game,false)) {
        if (game.getState().getZone(permanent.getId()) == Zone.GRAVEYARD) {
          Player controller=game.getPlayer(permanent.getControllerId());
          ElephantToken elephantToken=new ElephantToken();
          elephantToken.putOntoBattlefield(1,game,source.getSourceId(),controller.getId());
        }
      }
    }
  }
  return true;
}

Fixed version (ground truth):
@Override public boolean apply(Game game,Ability source){
  HashMap<UUID,Integer> destroyedPermanents=new HashMap<>();
  for (  UUID targetID : this.targetPointer.getTargets(game,source)) {
    Permanent permanent=game.getPermanent(targetID);
    if (permanent != null) {
      if (permanent.destroy(source.getSourceId(),game,false)) {
        if (game.getState().getZone(permanent.getId()) == Zone.GRAVEYARD) {
          int numberPermanents=0;
          if (destroyedPermanents.containsKey(permanent.getControllerId())) {
            numberPermanents=destroyedPermanents.get(permanent.getControllerId());
          }
          destroyedPermanents.put(permanent.getControllerId(),numberPermanents);
        }
      }
    }
  }
  ElephantToken elephantToken=new ElephantToken();
  for (  Entry<UUID,Integer> entry : destroyedPermanents.entrySet()) {
    elephantToken.putOntoBattlefield(entry.getValue(),game,source.getSourceId(),entry.getKey());
  }
  return true;
}
Program: 158414
Project: 158414
Buggy source:
@Override public void adjustTargets(Ability ability,Game game){
  if (ability.getOriginalId().equals(abilityId)) {
    Card sourceCard=game.getCard(ability.getSourceId());
    if (sourceCard != null) {
      ability.getTargets().clear();
      FilterPlayer filter=new FilterPlayer("String_Node_Str" + sourceCard.getIdName() + "String_Node_Str");
      filter.add(Predicates.not(new OwnerIdPredicate(sourceCard.getOwnerId())));
      ability.addTarget(new TargetPlayer(1,1,false,filter));
    }
  }
}

Fixed version (ground truth):
@Override public void adjustTargets(Ability ability,Game game){
  if (ability.getOriginalId().equals(abilityId)) {
    Card sourceCard=game.getCard(ability.getSourceId());
    if (sourceCard != null) {
      ability.getTargets().clear();
      FilterPlayer filter=new FilterPlayer("String_Node_Str" + sourceCard.getIdName() + "String_Node_Str");
      filter.add(Predicates.not(new PlayerIdPredicate(sourceCard.getOwnerId())));
      ability.addTarget(new TargetPlayer(1,1,false,filter));
    }
  }
}
Program: 158415
Project: 158415
Buggy source:
@Override public Set<Card> getCards(Game game){
  Set<Card> cards=new LinkedHashSet<>();
  for (Iterator<UUID> it=this.iterator(); it.hasNext(); ) {
    UUID cardId=it.next();
    Card card=game.getCard(cardId);
    if (card != null) {
      cards.add(card);
    }
  }
  return cards;
}

Fixed version (ground truth):
@Override public Set<Card> getCards(Game game){
  Set<Card> cards=new LinkedHashSet<>();
  for (Iterator<UUID> it=this.iterator(); it.hasNext(); ) {
    UUID cardId=it.next();
    Card card=game.getCard(cardId);
    if (card == null) {
      card=game.getPermanent(cardId);
    }
    if (card != null) {
      cards.add(card);
    }
  }
  return cards;
}
Program: 158416
Project: 158416
Buggy source:
@Override public boolean apply(Game game,Ability source){
  Player controller=game.getPlayer(source.getControllerId());
  if (controller != null) {
    ExileZone exileZone=game.getExile().getExileZone(CardUtil.getCardExileZoneId(game,source));
    if (exileZone != null && exileZone.count(new FilterInstantOrSorceryCard(),game) > 0) {
      if (controller.chooseUse(outcome,"String_Node_Str",source,game)) {
        TargetCardInExile target=new TargetCardInExile(new FilterInstantOrSorceryCard(),CardUtil.getCardExileZoneId(game,source));
        if (controller.choose(Outcome.PlayForFree,exileZone,target,game)) {
          Card card=game.getCard(target.getFirstTarget());
          if (card != null) {
            game.getExile().removeCard(card,game);
            return controller.cast(card.getSpellAbility(),game,true);
          }
        }
      }
    }
    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) {
    ExileZone exileZone=game.getExile().getExileZone(CardUtil.getCardExileZoneId(game,source));
    if (exileZone != null && exileZone.count(new FilterInstantOrSorceryCard(),game) > 0) {
      if (controller.chooseUse(outcome,"String_Node_Str",source,game)) {
        TargetCardInExile target=new TargetCardInExile(new FilterInstantOrSorceryCard(),CardUtil.getCardExileZoneId(game,source));
        if (controller.choose(Outcome.PlayForFree,exileZone,target,game)) {
          Card card=game.getCard(target.getFirstTarget());
          if (card != null) {
            return controller.cast(card.getSpellAbility(),game,true);
          }
        }
      }
    }
    return true;
  }
  return false;
}
Program: 158417
Project: 158417
Buggy source:
@Override public boolean apply(Game game,Ability source){
  Spell spell=game.getStack().getSpell(targetPointer.getFirst(game,source));
  Permanent sourceObject=game.getPermanentOrLKIBattlefield(source.getSourceId());
  Player controller=game.getPlayer(source.getControllerId());
  if (controller != null && spell != null && sourceObject != null) {
    UUID exileZoneId=CardUtil.getExileZoneId(game,source.getSourceId(),sourceObject.getZoneChangeCounter(game));
    if (controller.moveCardsToExile(spell,source,game,true,exileZoneId,sourceObject.getIdName())) {
      Player player=game.getPlayer(spell.getControllerId());
      if (player != null && player.chooseUse(Outcome.PlayForFree,"String_Node_Str" + sourceObject.getLogName() + "String_Node_Str",source,game)) {
        TargetCardInExile target=new TargetCardInExile(filter,source.getSourceId());
        while (player.choose(Outcome.PlayForFree,game.getExile().getExileZone(exileZoneId),target,game)) {
          Card card=game.getCard(target.getFirstTarget());
          if (card != null && !card.getId().equals(spell.getSourceId())) {
            game.getExile().removeCard(card,game);
            return player.cast(card.getSpellAbility(),game,true);
          }
          target.clearChosen();
        }
      }
      return true;
    }
  }
  return false;
}

Fixed version (ground truth):
@Override public boolean apply(Game game,Ability source){
  Spell spell=game.getStack().getSpell(targetPointer.getFirst(game,source));
  Permanent sourceObject=game.getPermanentOrLKIBattlefield(source.getSourceId());
  Player controller=game.getPlayer(source.getControllerId());
  if (controller != null && spell != null && sourceObject != null) {
    UUID exileZoneId=CardUtil.getExileZoneId(game,source.getSourceId(),sourceObject.getZoneChangeCounter(game));
    if (controller.moveCardsToExile(spell,source,game,true,exileZoneId,sourceObject.getIdName())) {
      Player player=game.getPlayer(spell.getControllerId());
      if (player != null && player.chooseUse(Outcome.PlayForFree,"String_Node_Str" + sourceObject.getLogName() + "String_Node_Str",source,game)) {
        TargetCardInExile target=new TargetCardInExile(filter,source.getSourceId());
        while (player.choose(Outcome.PlayForFree,game.getExile().getExileZone(exileZoneId),target,game)) {
          Card card=game.getCard(target.getFirstTarget());
          if (card != null && !card.getId().equals(spell.getSourceId())) {
            return player.cast(card.getSpellAbility(),game,true);
          }
          target.clearChosen();
        }
      }
      return true;
    }
  }
  return false;
}
Program: 158418
Project: 158418
Buggy source:
@Override public List<CardInfo> getCardsByRarity(Rarity rarity){
  if (rarity.equals(Rarity.COMMON)) {
    List<CardInfo> savedCardsInfos=savedCards.get(rarity);
    if (savedCardsInfos == null) {
      CardCriteria criteria=new CardCriteria();
      criteria.setCodes(this.code).notTypes(CardType.LAND);
      if (maxCardNumberInBooster != Integer.MAX_VALUE) {
        criteria.maxCardNumber(maxCardNumberInBooster);
      }
      savedCardsInfos=CardRepository.instance.findCards(criteria);
      savedCards.put(rarity,savedCardsInfos);
    }
    return new ArrayList<>(savedCardsInfos);
  }
 else {
    return super.getCardsByRarity(rarity);
  }
}

Fixed version (ground truth):
@Override public List<CardInfo> getCardsByRarity(Rarity rarity){
  if (rarity.equals(Rarity.COMMON)) {
    List<CardInfo> savedCardsInfos=savedCards.get(rarity);
    if (savedCardsInfos == null) {
      CardCriteria criteria=new CardCriteria();
      criteria.rarities(Rarity.COMMON);
      criteria.setCodes(this.code).notTypes(CardType.LAND);
      if (maxCardNumberInBooster != Integer.MAX_VALUE) {
        criteria.maxCardNumber(maxCardNumberInBooster);
      }
      savedCardsInfos=CardRepository.instance.findCards(criteria);
      savedCards.put(rarity,savedCardsInfos);
    }
    return new ArrayList<>(savedCardsInfos);
  }
 else {
    return super.getCardsByRarity(rarity);
  }
}
Program: 158420
Project: 158420
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.power.modifyBaseValue(token.getPower().getBaseValueModified());
  this.toughness.modifyBaseValue(token.getToughness().getBaseValueModified());
  this.supertype=token.getSupertype();
  this.subtype=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=token.getSupertype();
  this.subtype=token.getSubtype(game);
  this.tokenDescriptor=token.getTokenDescriptor();
}
Program: 158421
Project: 158421
Buggy source:
@Override public void reset(Game game){
  copyFromToken(token,game,true);
  super.reset(game);
}

Fixed version (ground truth):
@Override public void reset(Game game){
  copyFromToken(token,game,true);
  super.reset(game);
  this.power.resetToBaseValue();
  this.toughness.resetToBaseValue();
}
Program: 158422
Project: 158422
Buggy source:
@Override public boolean applies(GameEvent event,Ability source,Game game){
  Permanent permanent=game.getPermanentOrLKIBattlefield(event.getSourceId());
  return permanent != null && permanent.getControllerId().equals(source.getControllerId());
}

Fixed version (ground truth):
@Override public boolean applies(GameEvent event,Ability source,Game game){
  Permanent permanent=game.getPermanentOrLKIBattlefield(event.getSourceId());
  return permanent != null && permanent.getCardType().contains(CardType.CREATURE) && permanent.getControllerId().equals(source.getControllerId());
}
Program: 158423
Project: 158423
Buggy source:
@Override public boolean apply(Game game,Ability source){
  Player opponent=game.getPlayer(source.getFirstTarget());
  if (opponent != null && opponent.isLifeTotalCanChange()) {
    Permanent perm=game.getPermanent(source.getSourceId());
    if (perm != null) {
      int amount=perm.getToughness().getValue();
      int life=opponent.getLife();
      if (life == amount) {
        return false;
      }
      if (life < amount && !opponent.isCanGainLife()) {
        return false;
      }
      if (life > amount && !opponent.isCanLoseLife()) {
        return false;
      }
      opponent.setLife(amount,game);
      perm.getPower().modifyBaseValue(life);
      perm.getToughness().modifyBaseValue(life);
      return true;
    }
  }
  return false;
}

Fixed version (ground truth):
@Override public boolean apply(Game game,Ability source){
  Player opponent=game.getPlayer(source.getFirstTarget());
  if (opponent != null && opponent.isLifeTotalCanChange()) {
    Permanent perm=game.getPermanent(source.getSourceId());
    if (perm != null) {
      int amount=perm.getToughness().getValue();
      int life=opponent.getLife();
      if (life == amount) {
        return false;
      }
      if (life < amount && !opponent.isCanGainLife()) {
        return false;
      }
      if (life > amount && !opponent.isCanLoseLife()) {
        return false;
      }
      opponent.setLife(amount,game);
      perm.getToughness().modifyBaseValue(life);
      return true;
    }
  }
  return false;
}
Program: 158424
Project: 158424
Buggy source:
@Override public boolean apply(Game game,Ability source){
  Player damagedPlayer=game.getPlayer(targetPointer.getFirst(game,source));
  Player you=game.getPlayer(source.getControllerId());
  FilterCard filter=new FilterCard("String_Node_Str");
  filter.add(new CardTypePredicate(CardType.CREATURE));
  filter.add(new OwnerIdPredicate(damagedPlayer.getId()));
  TargetCardInGraveyard target=new TargetCardInGraveyard(filter);
  if (target.canChoose(source.getSourceId(),you.getId(),game)) {
    if (you.chooseTarget(Outcome.PutCreatureInPlay,target,source,game)) {
      Card card=game.getCard(target.getFirstTarget());
      if (card != null) {
        card.putOntoBattlefield(game,Zone.GRAVEYARD,id,you.getId());
        return true;
      }
    }
  }
  return false;
}

Fixed version (ground truth):
@Override public boolean apply(Game game,Ability source){
  Player damagedPlayer=game.getPlayer(targetPointer.getFirst(game,source));
  Player you=game.getPlayer(source.getControllerId());
  FilterCard filter=new FilterCard("String_Node_Str");
  filter.add(new CardTypePredicate(CardType.CREATURE));
  filter.add(new OwnerIdPredicate(damagedPlayer.getId()));
  TargetCardInGraveyard target=new TargetCardInGraveyard(filter);
  if (target.canChoose(source.getSourceId(),you.getId(),game)) {
    if (you.chooseTarget(Outcome.PutCreatureInPlay,target,source,game)) {
      Card card=game.getCard(target.getFirstTarget());
      if (card != null) {
        you.moveCards(card,Zone.BATTLEFIELD,source,game);
        return true;
      }
    }
  }
  return false;
}
Program: 158425
Project: 158425
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.EndOfGame,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 && 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: 158426
Project: 158426
Buggy source:
@Override public void adjustTargets(Ability ability,Game game){
  if (ability.getOriginalId().equals(abilityId)) {
    Card sourceCard=game.getCard(ability.getSourceId());
    if (sourceCard != null) {
      ability.getTargets().clear();
      FilterPlayer filter=new FilterPlayer("String_Node_Str" + sourceCard.getName() + "String_Node_Str");
      filter.add(Predicates.not(new OwnerIdPredicate(sourceCard.getOwnerId())));
      ability.addTarget(new TargetPlayer(1,1,false,filter));
    }
  }
}

Fixed version (ground truth):
@Override public void adjustTargets(Ability ability,Game game){
  if (ability.getOriginalId().equals(abilityId)) {
    Card sourceCard=game.getCard(ability.getSourceId());
    if (sourceCard != null) {
      ability.getTargets().clear();
      FilterPlayer filter=new FilterPlayer("String_Node_Str" + sourceCard.getIdName() + "String_Node_Str");
      filter.add(Predicates.not(new OwnerIdPredicate(sourceCard.getOwnerId())));
      ability.addTarget(new TargetPlayer(1,1,false,filter));
    }
  }
}
Program: 158428
Project: 158428
Buggy source:
@Override public boolean replaceEvent(GameEvent event,Ability source,Game game){
  DamagePlayerEvent damageEvent=(DamagePlayerEvent)event;
  Permanent equipment=game.getPermanent(source.getSourceId());
  if (equipment != null) {
    Permanent p=game.getPermanent(equipment.getAttachedTo());
    if (p != null) {
      p.damage(damageEvent.getAmount(),event.getSourceId(),game,damageEvent.isCombatDamage(),damageEvent.isPreventable());
      return true;
    }
  }
  return true;
}

Fixed version (ground truth):
@Override public boolean replaceEvent(GameEvent event,Ability source,Game game){
  Permanent equipment=game.getPermanent(source.getSourceId());
  if (equipment != null) {
    Permanent p=game.getPermanent(equipment.getAttachedTo());
    if (p != null) {
      DamagePlayerEvent damageEvent=(DamagePlayerEvent)event;
      p.damage(damageEvent.getAmount(),event.getSourceId(),game,damageEvent.isCombatDamage(),damageEvent.isPreventable());
      return true;
    }
  }
  return false;
}
Program: 158430
Project: 158430
Buggy source:
public FalkenrathGorgerEffect(final FalkenrathGorgerEffect effect){
  super(effect);
}

Fixed version (ground truth):
public FalkenrathGorgerEffect(final FalkenrathGorgerEffect effect){
  super(effect);
  this.madnessAbilities.putAll(effect.madnessAbilities);
}
Program: 158431
Project: 158431
Buggy source:
@Override public boolean apply(Game game,Ability source){
  Player controller=game.getPlayer(source.getControllerId());
  if (controller != null) {
    for (    Card card : controller.getHand().getCards(filter,game)) {
      game.getState().addOtherAbility(card,new MadnessAbility(card,card.getSpellAbility().getManaCosts()));
    }
    for (    Card card : controller.getGraveyard().getCards(filter,game)) {
      game.getState().addOtherAbility(card,new MadnessAbility(card,card.getSpellAbility().getManaCosts()));
    }
    for (    Card card : game.getExile().getAllCards(game)) {
      if (filter.match(card,source.getSourceId(),controller.getId(),game)) {
        if (card.getOwnerId().equals(controller.getId())) {
          game.getState().addOtherAbility(card,new MadnessAbility(card,card.getSpellAbility().getManaCosts()));
        }
      }
    }
    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) {
    HashMap<UUID,MadnessAbility> usedMadnessAbilities=new HashMap<>();
    for (    Card card : controller.getHand().getCards(filter,game)) {
      addMadnessToCard(game,card,usedMadnessAbilities);
    }
    for (    Card card : controller.getGraveyard().getCards(filter,game)) {
      addMadnessToCard(game,card,usedMadnessAbilities);
    }
    for (    Card card : game.getExile().getAllCards(game)) {
      if (filter.match(card,source.getSourceId(),controller.getId(),game)) {
        if (card.getOwnerId().equals(controller.getId())) {
          addMadnessToCard(game,card,usedMadnessAbilities);
        }
      }
    }
    madnessAbilities.clear();
    madnessAbilities.putAll(usedMadnessAbilities);
    return true;
  }
  return false;
}
Program: 158432
Project: 158432
Buggy source:
MadnessTriggeredAbility(final MadnessTriggeredAbility ability){
  super(ability);
}

Fixed version (ground truth):
MadnessTriggeredAbility(final MadnessTriggeredAbility ability){
  super(ability);
  this.madnessOriginalId=ability.madnessOriginalId;
}
Program: 158433
Project: 158433
Buggy source:
@Override public boolean checkTrigger(GameEvent event,Game game){
  return event.getTargetId().equals(getSourceId());
}

Fixed version (ground truth):
@Override public boolean checkTrigger(GameEvent event,Game game){
  return event.getSourceId().equals(madnessOriginalId);
}
Program: 158434
Project: 158434
Buggy source:
@Override public boolean replaceEvent(GameEvent event,Ability source,Game game){
  Player controller=game.getPlayer(source.getControllerId());
  if (controller != null) {
    Card card=game.getCard(event.getTargetId());
    if (card != null) {
      if (controller.moveCardToExileWithInfo(card,source.getSourceId(),"String_Node_Str",source.getSourceId(),game,((ZoneChangeEvent)event).getFromZone(),true)) {
        game.applyEffects();
        game.fireEvent(GameEvent.getEvent(GameEvent.EventType.MADNESS_CARD_EXILED,card.getId(),card.getId(),controller.getId()));
      }
      return true;
    }
  }
  return false;
}

Fixed version (ground truth):
@Override public boolean replaceEvent(GameEvent event,Ability source,Game game){
  Player controller=game.getPlayer(source.getControllerId());
  if (controller != null) {
    Card card=game.getCard(event.getTargetId());
    if (card != null) {
      if (controller.moveCardToExileWithInfo(card,source.getSourceId(),"String_Node_Str",source.getSourceId(),game,((ZoneChangeEvent)event).getFromZone(),true)) {
        game.applyEffects();
        GameEvent gameEvent=GameEvent.getEvent(GameEvent.EventType.MADNESS_CARD_EXILED,card.getId(),source.getOriginalId(),controller.getId());
        game.fireEvent(gameEvent);
      }
      return true;
    }
  }
  return false;
}
Program: 158437
Project: 158437
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) {
    ContinuousEffect effect=new GainControlTargetEffect(Duration.EndOfGame,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 && controller.getId() != newController.getId()) {
    ContinuousEffect effect=new GainControlTargetEffect(Duration.EndOfGame,newController.getId());
    effect.setTargetPointer(new FixedTarget(source.getSourceId()));
    game.addEffect(effect,source);
    return true;
  }
  return false;
}
Program: 158438
Project: 158438
Buggy source:
@Override public void adjustTargets(Ability ability,Game game){
  if (ability.getOriginalId().equals(ability2Id)) {
    int cmc=0;
    for (    Cost cost : ability.getCosts()) {
      if (cost instanceof PayVariableLoyaltyCost) {
        cmc=((PayVariableLoyaltyCost)cost).getAmount();
      }
    }
    FilterCard newFilter=filter.copy();
    newFilter.add(new ConvertedManaCostPredicate(Filter.ComparisonType.Equal,cmc));
    ability.getTargets().clear();
    ability.addTarget(new TargetCardInYourGraveyard(filter));
  }
}

Fixed version (ground truth):
@Override public void adjustTargets(Ability ability,Game game){
  if (ability.getOriginalId().equals(ability2Id)) {
    int cmc=0;
    for (    Cost cost : ability.getCosts()) {
      if (cost instanceof PayVariableLoyaltyCost) {
        cmc=((PayVariableLoyaltyCost)cost).getAmount();
      }
    }
    FilterCard newFilter=filter.copy();
    newFilter.add(new ConvertedManaCostPredicate(Filter.ComparisonType.Equal,cmc));
    ability.getTargets().clear();
    ability.addTarget(new TargetCardInYourGraveyard(newFilter));
  }
}
Program: 158439
Project: 158439
Buggy source:
@Test public void testMinusAbilityShouldNotReturnHigherCmcCreature(){
  addCard(Zone.BATTLEFIELD,playerA,"String_Node_Str",1);
  addCard(Zone.BATTLEFIELD,playerA,"String_Node_Str",3);
  addCard(Zone.HAND,playerA,"String_Node_Str");
  addCard(Zone.HAND,playerB,"String_Node_Str");
  addCard(Zone.BATTLEFIELD,playerB,"String_Node_Str",1);
  castSpell(1,PhaseStep.PRECOMBAT_MAIN,playerA,"String_Node_Str");
  castSpell(1,PhaseStep.BEGIN_COMBAT,playerB,"String_Node_Str");
  addTarget(playerB,"String_Node_Str");
  activateAbility(1,PhaseStep.POSTCOMBAT_MAIN,playerA,"String_Node_Str");
  setChoice(playerA,"String_Node_Str");
  addTarget(playerA,"String_Node_Str");
  setChoice(playerA,"String_Node_Str");
  setStopAt(1,PhaseStep.END_TURN);
  execute();
  assertGraveyardCount(playerB,"String_Node_Str",1);
  assertPermanentCount(playerA,"String_Node_Str",0);
  assertPermanentCount(playerA,"String_Node_Str",1);
  assertPermanentCount(playerA,"String_Node_Str",1);
  assertCounterCount("String_Node_Str",CounterType.LOYALTY,2);
  assertPermanentCount(playerA,"String_Node_Str",0);
  assertGraveyardCount(playerA,"String_Node_Str",1);
}

Fixed version (ground truth):
@Test public void testMinusAbilityShouldNotReturnHigherCmcCreature(){
  addCard(Zone.BATTLEFIELD,playerA,"String_Node_Str",1);
  addCard(Zone.BATTLEFIELD,playerA,"String_Node_Str",3);
  addCard(Zone.HAND,playerA,"String_Node_Str");
  addCard(Zone.HAND,playerB,"String_Node_Str");
  addCard(Zone.BATTLEFIELD,playerB,"String_Node_Str",1);
  castSpell(1,PhaseStep.PRECOMBAT_MAIN,playerA,"String_Node_Str");
  castSpell(1,PhaseStep.BEGIN_COMBAT,playerB,"String_Node_Str","String_Node_Str");
  activateAbility(1,PhaseStep.POSTCOMBAT_MAIN,playerA,"String_Node_Str","String_Node_Str");
  setChoice(playerA,"String_Node_Str");
  setStopAt(1,PhaseStep.END_TURN);
  execute();
  assertGraveyardCount(playerB,"String_Node_Str",1);
  assertPermanentCount(playerA,"String_Node_Str",0);
  assertPermanentCount(playerA,"String_Node_Str",1);
  assertPermanentCount(playerA,"String_Node_Str",1);
  assertCounterCount("String_Node_Str",CounterType.LOYALTY,3);
  assertPermanentCount(playerA,"String_Node_Str",0);
  assertGraveyardCount(playerA,"String_Node_Str",1);
}
Program: 158441
Project: 158441
Buggy source:
@Override public void adjustTargets(Ability ability,Game game){
  card.adjustTargets(ability,game);
}

Fixed version (ground truth):
@Override public void adjustTargets(Ability ability,Game game){
  if (this.isTransformed()) {
    card.getSecondCardFace().adjustTargets(ability,game);
  }
 else {
    card.adjustTargets(ability,game);
  }
}
Program: 158442
Project: 158442
Buggy source:
@Override public void adjustCosts(Ability ability,Game game){
  card.adjustCosts(ability,game);
}

Fixed version (ground truth):
@Override public void adjustCosts(Ability ability,Game game){
  if (this.isTransformed()) {
    card.getSecondCardFace().adjustCosts(ability,game);
  }
 else {
    card.adjustCosts(ability,game);
  }
}
Program: 158443
Project: 158443
Buggy source:
@Override public boolean apply(Game game,Ability source){
  Player controller=game.getPlayer(source.getControllerId());
  MageObject sourceObject=source.getSourceObject(game);
  if (controller != null && sourceObject != null) {
    Permanent permanentLeftBattlefield=(Permanent)getValue("String_Node_Str");
    if (permanentLeftBattlefield == null) {
      Logger.getLogger(ReturnFromExileForSourceEffect.class).error("String_Node_Str" + sourceObject.getName());
      return false;
    }
    ExileZone exile=game.getExile().getExileZone(CardUtil.getExileZoneId(game,source.getSourceId(),permanentLeftBattlefield.getZoneChangeCounter(game)));
    if (exile != null) {
      Card card=exile.getCards(game).iterator().next();
      if (card != null) {
        Player cardOwner=game.getPlayer(card.getOwnerId());
        if (cardOwner != null) {
          if (cardOwner.chooseUse(Outcome.PlayForFree,"String_Node_Str" + card.getLogName() + "String_Node_Str",source,game)) {
            cardOwner.cast(card.getSpellAbility(),game,true);
          }
        }
      }
    }
    return true;
  }
  return false;
}

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) {
    Permanent permanentLeftBattlefield=(Permanent)getValue("String_Node_Str");
    if (permanentLeftBattlefield == null) {
      Logger.getLogger(ReturnFromExileForSourceEffect.class).error("String_Node_Str" + sourceObject.getName());
      return false;
    }
    ExileZone exile=game.getExile().getExileZone(CardUtil.getExileZoneId(game,source.getSourceId(),permanentLeftBattlefield.getZoneChangeCounter(game)));
    if (exile != null) {
      Card card=null;
      Set<Card> exiledCards=exile.getCards(game);
      if (exiledCards != null && !exiledCards.isEmpty()) {
        card=exiledCards.iterator().next();
        if (card != null) {
          Player cardOwner=game.getPlayer(card.getOwnerId());
          if (cardOwner != null) {
            if (cardOwner.chooseUse(Outcome.PlayForFree,"String_Node_Str" + card.getLogName() + "String_Node_Str",source,game)) {
              cardOwner.cast(card.getSpellAbility(),game,true);
            }
          }
        }
      }
    }
    return true;
  }
  return false;
}
Program: 158444
Project: 158444
Buggy source:
@Override public boolean apply(Game game,Ability source){
  Player targetPlayer=game.getPlayer(source.getFirstTarget());
  if (targetPlayer != null && targetPlayer.getHand().size() > 0) {
    Cards revealed=new CardsImpl();
    Card card=targetPlayer.getHand().getRandom(game);
    revealed.add(card);
    targetPlayer.revealCards("String_Node_Str",revealed,game);
    targetPlayer.loseLife(card.getConvertedManaCost(),game);
    return true;
  }
  return false;
}

Fixed version (ground truth):
@Override public boolean apply(Game game,Ability source){
  Player targetPlayer=game.getPlayer(source.getFirstTarget());
  if (targetPlayer != null && !targetPlayer.getHand().isEmpty()) {
    Cards revealed=new CardsImpl();
    Card card=targetPlayer.getHand().getRandom(game);
    revealed.add(card);
    targetPlayer.revealCards("String_Node_Str",revealed,game);
    targetPlayer.loseLife(card.getConvertedManaCost(),game);
    return true;
  }
  return false;
}
Program: 158445
Project: 158445
Buggy source:
@Override public boolean apply(Game game,Ability source){
  Player controller=game.getPlayer(source.getControllerId());
  if (controller != null) {
    HashMap<UUID,Integer> destroyedCreatures=new HashMap<>();
    for (    Permanent permanent : game.getBattlefield().getActivePermanents(new FilterCreaturePermanent(),source.getControllerId(),source.getSourceId(),game)) {
      if (permanent.destroy(source.getSourceId(),game,false)) {
        int count=destroyedCreatures.containsKey(permanent.getControllerId()) ? destroyedCreatures.get(permanent.getControllerId()) : 0;
        destroyedCreatures.put(permanent.getControllerId(),count + 1);
      }
    }
    for (    UUID playerId : game.getState().getPlayerList(source.getControllerId())) {
      int count=destroyedCreatures.containsKey(playerId) ? destroyedCreatures.get(playerId) : 0;
      if (count > 0) {
        Player player=game.getPlayer(playerId);
        if (player != null) {
          player.damage(count,playerId,game,false,true);
        }
      }
    }
    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) {
    HashMap<UUID,Integer> destroyedCreatures=new HashMap<>();
    for (    Permanent permanent : game.getBattlefield().getActivePermanents(new FilterCreaturePermanent(),source.getControllerId(),source.getSourceId(),game)) {
      if (permanent.destroy(source.getSourceId(),game,false)) {
        int count=destroyedCreatures.containsKey(permanent.getControllerId()) ? destroyedCreatures.get(permanent.getControllerId()) : 0;
        destroyedCreatures.put(permanent.getControllerId(),count + 1);
      }
    }
    for (    UUID playerId : game.getState().getPlayerList(source.getControllerId())) {
      int count=destroyedCreatures.containsKey(playerId) ? destroyedCreatures.get(playerId) : 0;
      if (count > 0) {
        Player player=game.getPlayer(playerId);
        if (player != null) {
          player.loseLife(count,game);
        }
      }
    }
    return true;
  }
  return false;
}
Program: 158446
Project: 158446
Buggy source:
@Override public MortisDogsEffect copy(){
  return new MortisDogsEffect();
}

Fixed version (ground truth):
@Override public MortisDogs copy(){
  return new MortisDogs(this);
}
Program: 158447
Project: 158447
Buggy source:
@Override public boolean apply(Game game,Ability source){
  int amount=0;
  for (  Cost cost : source.getCosts()) {
    if (cost instanceof SacrificeTargetCost && ((SacrificeTargetCost)cost).getPermanents().size() > 0) {
      amount=((SacrificeTargetCost)cost).getPermanents().get(0).getPower().getValue();
      break;
    }
  }
  if (amount > 0) {
    Player player=game.getPlayer(source.getFirstTarget());
    if (player != null) {
      player.damage(amount,source.getSourceId(),game,false,true);
      return true;
    }
  }
  return false;
}

Fixed version (ground truth):
@Override public boolean apply(Game game,Ability source){
  int amount=0;
  for (  Cost cost : source.getCosts()) {
    if (cost instanceof SacrificeTargetCost && ((SacrificeTargetCost)cost).getPermanents().size() > 0) {
      amount=((SacrificeTargetCost)cost).getPermanents().get(0).getPower().getValue();
      break;
    }
  }
  if (amount > 0) {
    Player player=game.getPlayer(source.getFirstTarget());
    if (player != null) {
      player.loseLife(amount,game);
      return true;
    }
  }
  return false;
}
Program: 158448
Project: 158448
Buggy source:
@Override public boolean apply(Game game,Ability source){
  Player you=game.getPlayer(source.getControllerId());
  Player targetPlayer=game.getPlayer(source.getFirstTarget());
  if (targetPlayer != null && you != null) {
    FilterCard filter=new FilterCard("String_Node_Str");
    filter.add(new OwnerIdPredicate(targetPlayer.getId()));
    TargetCardInGraveyard target=new TargetCardInGraveyard(filter);
    boolean opponentChoosesExile=targetPlayer.chooseUse(Outcome.Exile,"String_Node_Str",source,game);
    if (opponentChoosesExile && targetPlayer.chooseTarget(Outcome.Exile,target,source,game)) {
      Card card=game.getCard(target.getFirstTarget());
      if (card != null) {
        if (targetPlayer.moveCardToExileWithInfo(card,null,"String_Node_Str",source.getSourceId(),game,Zone.GRAVEYARD,true)) {
          if (you.chooseUse(Outcome.DrawCard,"String_Node_Str",source,game)) {
            you.drawCards(1,game);
          }
        }
      }
      return true;
    }
  }
  return false;
}

Fixed version (ground truth):
@Override public boolean apply(Game game,Ability source){
  Player you=game.getPlayer(source.getControllerId());
  Player targetPlayer=game.getPlayer(source.getFirstTarget());
  if (targetPlayer != null && you != null) {
    FilterCard filter=new FilterCard("String_Node_Str");
    filter.add(new OwnerIdPredicate(targetPlayer.getId()));
    TargetCardInGraveyard target=new TargetCardInGraveyard(filter);
    boolean opponentChoosesExile=targetPlayer.chooseUse(Outcome.Exile,"String_Node_Str",source,game);
    boolean opponentExilesACard=false;
    if (opponentChoosesExile && targetPlayer.chooseTarget(Outcome.Exile,target,source,game)) {
      Card card=game.getCard(target.getFirstTarget());
      if (card != null) {
        opponentExilesACard=targetPlayer.moveCardToExileWithInfo(card,null,"String_Node_Str",source.getSourceId(),game,Zone.GRAVEYARD,true);
      }
    }
    if (!opponentExilesACard) {
      if (you.chooseUse(Outcome.DrawCard,"String_Node_Str",source,game)) {
        you.drawCards(1,game);
      }
    }
    return true;
  }
  return false;
}