nus-yam/ex-repair huggingface dataset:
Program: 157616
Project: 157616
Buggy source:
@Override public boolean apply(Game game,Ability source){
  Player controller=game.getPlayer(source.getControllerId());
  MageObject sourceObject=game.getObject(source.getSourceId());
  if (controller.getLibrary().hasCards()) {
    Card card=controller.getLibrary().getFromTop(game);
    Cards cards=new CardsImpl(card);
    controller.lookAtCards(sourceObject.getIdName(),cards,game);
    FilterCreatureCard filter=new FilterCreatureCard("String_Node_Str");
    filter.add(new ChosenSubtypePredicate(source.getSourceId()));
    String message="String_Node_Str";
    if (card != null) {
      if (filter.match(card,game) && controller.chooseUse(Outcome.Benefit,message,source,game)) {
        controller.moveCards(card,Zone.HAND,source,game);
        controller.revealCards(sourceObject.getIdName() + "String_Node_Str",cards,game);
      }
    }
  }
  return true;
}

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 (controller.getLibrary().hasCards()) {
    Card card=controller.getLibrary().getFromTop(game);
    Cards cards=new CardsImpl(card);
    controller.lookAtCards(sourceObject.getIdName(),cards,game);
    FilterCreatureCard filter=new FilterCreatureCard("String_Node_Str");
    filter.add(new ChosenSubtypePredicate());
    String message="String_Node_Str";
    if (card != null) {
      if (filter.match(card,game) && controller.chooseUse(Outcome.Benefit,message,source,game)) {
        controller.moveCards(card,Zone.HAND,source,game);
        controller.revealCards(sourceObject.getIdName() + "String_Node_Str",cards,game);
      }
    }
  }
  return true;
}
Program: 157617
Project: 157617
Buggy source:
@Override public boolean apply(MageObject input,Game game){
  SubType subType=ChooseCreatureTypeEffect.getChoosenCreatureType(cardID,game);
  return input.hasSubtype(subType,game);
}

Fixed version (ground truth):
@Override public boolean apply(ObjectSourcePlayer<MageObject> input,Game game){
  SubType subType=ChooseCreatureTypeEffect.getChoosenCreatureType(input.getSourceId(),game);
  return input.getObject().hasSubtype(subType,game);
}
Program: 157618
Project: 157618
Buggy source:
public ChosenSubtypePredicate(UUID cardID){
  this.cardID=cardID;
}

Fixed version (ground truth):
public ChosenSubtypePredicate(){
}
Program: 157619
Project: 157619
Buggy source:
@Override public boolean apply(Game game,Ability source){
  Permanent permanent=game.getPermanent(source.getSourceId());
  if (permanent == null) {
    return false;
  }
  Player player=game.getPlayer(permanent.getControllerId());
  if (player == null) {
    return false;
  }
  if (player.chooseUse(Outcome.GainLife,"String_Node_Str" + permanent.getLogName() + "String_Node_Str",source,game)) {
    permanent.sacrifice(source.getSourceId(),game);
  }
 else {
    player.damage(permanent.getConvertedManaCost(),permanent.getId(),game,false,true);
  }
  return true;
}

Fixed version (ground truth):
@Override public boolean apply(Game game,Ability source){
  Permanent permanent=game.getPermanent(source.getFirstTarget());
  if (permanent == null) {
    return false;
  }
  Player player=game.getPlayer(permanent.getControllerId());
  if (player == null) {
    return false;
  }
  if (player.chooseUse(Outcome.GainLife,"String_Node_Str" + permanent.getLogName() + "String_Node_Str",source,game)) {
    permanent.sacrifice(source.getSourceId(),game);
  }
 else {
    player.damage(permanent.getConvertedManaCost(),permanent.getId(),game,false,true);
  }
  return true;
}
Program: 157620
Project: 157620
Buggy source:
@Override public boolean apply(Game game,Ability source){
  Player controller=game.getPlayer(source.getControllerId());
  Player opponent=game.getPlayer(source.getFirstTarget());
  if (controller == null || opponent == null) {
    return false;
  }
  Cards cardsToShuffle=new CardsImpl();
  while (opponent.getLibrary().hasCards()) {
    Card card=opponent.getLibrary().getFromTop(game);
    if (card == null) {
      break;
    }
    opponent.moveCards(card,Zone.EXILED,source,game);
    if (card.isInstant() || card.isSorcery()) {
      if (!controller.chooseUse(outcome,"String_Node_Str" + card.getName() + "String_Node_Str",source,game) || !controller.cast(card.getSpellAbility(),game,true,new MageObjectReference(source.getSourceObject(game),game))) {
        cardsToShuffle.add(card);
      }
      break;
    }
    cardsToShuffle.add(card);
  }
  return opponent.putCardsOnBottomOfLibrary(cardsToShuffle,game,source,false);
}

Fixed version (ground truth):
@Override public boolean apply(Game game,Ability source){
  Player controller=game.getPlayer(source.getControllerId());
  Player opponent=game.getPlayer(source.getFirstTarget());
  if (controller == null || opponent == null) {
    return false;
  }
  Cards cardsToShuffle=new CardsImpl();
  while (opponent.getLibrary().hasCards()) {
    Card card=opponent.getLibrary().getFromTop(game);
    if (card == null) {
      break;
    }
    opponent.moveCards(card,Zone.EXILED,source,game);
    controller.revealCards(source,new CardsImpl(card),game);
    if (card.isInstant() || card.isSorcery()) {
      if (!controller.chooseUse(outcome,"String_Node_Str" + card.getName() + "String_Node_Str",source,game) || !controller.cast(card.getSpellAbility(),game,true,new MageObjectReference(source.getSourceObject(game),game))) {
        cardsToShuffle.add(card);
      }
      break;
    }
 else {
      cardsToShuffle.add(card);
    }
  }
  return opponent.putCardsOnBottomOfLibrary(cardsToShuffle,game,source,false);
}
Program: 157621
Project: 157621
Buggy source:
@Override public boolean apply(Game game,Ability source){
  int otherCreatures=new PermanentsOnBattlefieldCount(filter).calculate(game,source,this);
  if (otherCreatures > 0) {
    new SacrificeControllerEffect(filter,1,"String_Node_Str").apply(game,source);
  }
 else {
    Permanent permanent=game.getPermanentOrLKIBattlefield(source.getSourceId());
    if (permanent != null) {
      permanent.damage(6,permanent.getId(),game,false,true);
    }
  }
  return true;
}

Fixed version (ground truth):
@Override public boolean apply(Game game,Ability source){
  int otherCreatures=new PermanentsOnBattlefieldCount(filter).calculate(game,source,this);
  if (otherCreatures > 0) {
    new SacrificeControllerEffect(filter,1,"String_Node_Str").apply(game,source);
  }
 else {
    Player controller=game.getPlayer(source.getControllerId());
    if (controller != null) {
      controller.damage(6,source.getSourceId(),game,false,true);
    }
  }
  return true;
}
Program: 157622
Project: 157622
Buggy source:
@Override public boolean apply(Game game,Ability source){
  Permanent sourceObject=game.getPermanent(source.getSourceId());
  if (sourceObject == null || sourceObject.getImprinted() == null) {
    return false;
  }
  for (  UUID imprinted : sourceObject.getImprinted()) {
    if (imprinted != null) {
      Card card=game.getCard(imprinted);
      if (card != null) {
        for (        CardType cardType : card.getCardType()) {
          FilterCard filterCard;
          if (cardType.equals(CardType.SORCERY)) {
            filterCard=new FilterCard("String_Node_Str");
          }
 else           if (cardType.equals(CardType.TRIBAL)) {
            filterCard=new FilterCard("String_Node_Str");
          }
 else {
            filterCard=new FilterCard(cardType.toString() + "String_Node_Str");
          }
          filterCard.add(new CardTypePredicate(cardType));
          sourceObject.addAbility(new ProtectionAbility(filterCard));
        }
      }
    }
  }
  return true;
}

Fixed version (ground truth):
@Override public boolean apply(Game game,Ability source){
  Permanent sourceObject=game.getPermanent(source.getSourceId());
  ExileZone exileZone=game.getExile().getExileZone(CardUtil.getCardExileZoneId(game,source.getSourceId()));
  if (sourceObject == null || sourceObject.getImprinted() == null) {
    return false;
  }
  for (  UUID imprinted : sourceObject.getImprinted()) {
    if (imprinted != null && exileZone.contains(imprinted)) {
      Card card=game.getCard(imprinted);
      if (card != null) {
        for (        CardType cardType : card.getCardType()) {
          FilterCard filterCard;
          if (cardType.equals(CardType.SORCERY)) {
            filterCard=new FilterCard("String_Node_Str");
          }
 else           if (cardType.equals(CardType.TRIBAL)) {
            filterCard=new FilterCard("String_Node_Str");
          }
 else {
            filterCard=new FilterCard(cardType.toString() + "String_Node_Str");
          }
          filterCard.add(new CardTypePredicate(cardType));
          sourceObject.addAbility(new ProtectionAbility(filterCard));
        }
      }
    }
  }
  return true;
}
Program: 157623
Project: 157623
Buggy source:
@Override public String getRule(){
  return new StringBuilder("String_Node_Str").append(super.getRule()).toString();
}

Fixed version (ground truth):
@Override public String getRule(){
  return "String_Node_Str" + super.getRule();
}
Program: 157625
Project: 157625
Buggy source:
@Override public boolean apply(Game game,Ability source){
  Player controller=game.getPlayer(source.getControllerId());
  if (controller != null) {
    checkToFirePossibleEvents(getMana(game,source),game,source);
    controller.getManaPool().addMana(getMana(game,source),game,source);
    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) {
    controller.getManaPool().addMana(getMana(game,source),game,source);
    return true;
  }
  return false;
}
Program: 157626
Project: 157626
Buggy source:
@Override public boolean apply(Game game,Ability source){
  Player controller=game.getPlayer(source.getSourceId());
  ChooseFriendsAndFoes choice=new ChooseFriendsAndFoes();
  if (!choice.chooseFriendOrFoe(controller,source,game)) {
    return false;
  }
  for (  Player player : choice.getFriends()) {
    if (player != null) {
      TargetCardInLibrary target=new TargetCardInLibrary(0,1,StaticFilters.FILTER_CARD_LAND);
      if (player.searchLibrary(target,game)) {
        player.moveCards(new CardsImpl(target.getTargets()).getCards(game),Zone.BATTLEFIELD,source,game,true,false,true,null);
        player.shuffleLibrary(source,game);
      }
    }
  }
  for (  Player player : choice.getFoes()) {
    if (player != null) {
      Effect effect=new SacrificeEffect(StaticFilters.FILTER_PERMANENT_ARTIFACT_OR_ENCHANTMENT,1,"String_Node_Str");
      effect.setTargetPointer(new FixedTarget(player.getId(),game));
      effect.apply(game,source);
    }
  }
  return true;
}

Fixed version (ground truth):
@Override public boolean apply(Game game,Ability source){
  Player controller=game.getPlayer(source.getControllerId());
  ChooseFriendsAndFoes choice=new ChooseFriendsAndFoes();
  if (!choice.chooseFriendOrFoe(controller,source,game)) {
    return false;
  }
  for (  Player player : choice.getFriends()) {
    if (player != null) {
      TargetCardInLibrary target=new TargetCardInLibrary(0,1,StaticFilters.FILTER_CARD_LAND);
      if (player.searchLibrary(target,game)) {
        player.moveCards(new CardsImpl(target.getTargets()).getCards(game),Zone.BATTLEFIELD,source,game,true,false,true,null);
        player.shuffleLibrary(source,game);
      }
    }
  }
  for (  Player player : choice.getFoes()) {
    if (player != null) {
      Effect effect=new SacrificeEffect(StaticFilters.FILTER_PERMANENT_ARTIFACT_OR_ENCHANTMENT,1,"String_Node_Str");
      effect.setTargetPointer(new FixedTarget(player.getId(),game));
      effect.apply(game,source);
    }
  }
  return true;
}
Program: 157630
Project: 157630
Buggy source:
@Override public boolean apply(Game game,Ability source){
  Player controller=game.getPlayer(source.getControllerId());
  if (controller != null) {
    checkToFirePossibleEvents(getMana(game,source),game,source);
    controller.getManaPool().addMana(getMana(game,source),game,source);
    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) {
    Mana mana=getMana(game,source);
    checkToFirePossibleEvents(mana,game,source);
    controller.getManaPool().addMana(mana,game,source);
    return true;
  }
  return false;
}
Program: 157631
Project: 157631
Buggy source:
@Override public boolean apply(Game game,Ability source){
  Player controller=game.getPlayer(source.getControllerId());
  if (controller != null) {
    Card card=game.getCard(source.getSourceId());
    if (card != null) {
      ContinuousEffect effect=new EntersBattlefieldEffect(new AddCountersSourceEffect(CounterType.LUCK.createInstance()),"String_Node_Str");
      effect.setDuration(Duration.OneUse);
      game.addEffect(effect,source);
      if (controller.moveCards(card,Zone.BATTLEFIELD,source,game)) {
        Permanent permanent=game.getPermanent(card.getId());
        if (permanent != null) {
          Cost cost=new ExileFromHandCost(new TargetCardInHand());
          if (cost.canPay(source,source.getSourceId(),source.getControllerId(),game)) {
            cost.pay(source,game,source.getSourceId(),source.getControllerId(),true,null);
          }
        }
      }
    }
    return true;
  }
  return false;
}

Fixed version (ground truth):
@Override public boolean apply(Game game,Ability source){
  boolean result=false;
  Player controller=game.getPlayer(source.getControllerId());
  if (controller != null) {
    Card card=game.getCard(source.getSourceId());
    if (card != null) {
      ContinuousEffect effect=new EntersBattlefieldEffect(new AddCountersSourceEffect(CounterType.LUCK.createInstance()),"String_Node_Str");
      effect.setDuration(Duration.OneUse);
      game.addEffect(effect,source);
      if (controller.moveCards(card,Zone.BATTLEFIELD,source,game)) {
        Permanent permanent=game.getPermanent(card.getId());
        if (permanent != null) {
          Cost cost=new ExileFromHandCost(new TargetCardInHand());
          if (cost.canPay(source,source.getSourceId(),source.getControllerId(),game)) {
            result=cost.pay(source,game,source.getSourceId(),source.getControllerId(),true,null);
          }
        }
      }
    }
  }
  return result;
}
Program: 157632
Project: 157632
Buggy source:
@Test public void test_DaxosGotBoostWithLoseFlyAndGotItAgain(){
  addCard(Zone.HAND,playerA,daxosCard,1);
  addCard(Zone.BATTLEFIELD,playerA,"String_Node_Str",4);
  addCard(Zone.HAND,playerA,"String_Node_Str",1);
  addCard(Zone.BATTLEFIELD,playerA,"String_Node_Str",3);
  castSpell(1,PhaseStep.PRECOMBAT_MAIN,playerA,daxosCard);
  castSpell(1,PhaseStep.POSTCOMBAT_MAIN,playerA,"String_Node_Str");
  setStopAt(1,PhaseStep.END_TURN);
  execute();
  assertHandCount(playerA,daxosCard,0);
  assertPermanentCount(playerA,daxosCard,1);
  assertHandCount(playerA,"String_Node_Str",0);
  assertPermanentCount(playerA,"String_Node_Str",1);
  assertPowerToughness(playerA,daxosCard,5,5);
  assertType(daxosCard,CardType.CREATURE,SubType.DEMON);
  assertAbility(playerA,daxosCard,FlyingAbility.getInstance(),true);
  assertAbility(playerA,daxosCard,HasteAbility.getInstance(),true);
}

Fixed version (ground truth):
@Test public void test_DaxosGotBoostWithLoseFlyAndGotItAgain(){
  addCard(Zone.HAND,playerA,daxosCard,1);
  addCard(Zone.BATTLEFIELD,playerA,"String_Node_Str",1);
  addCard(Zone.HAND,playerA,"String_Node_Str",1);
  addCard(Zone.BATTLEFIELD,playerA,"String_Node_Str",6);
  castSpell(1,PhaseStep.PRECOMBAT_MAIN,playerA,daxosCard);
  castSpell(1,PhaseStep.POSTCOMBAT_MAIN,playerA,"String_Node_Str");
  setStopAt(1,PhaseStep.END_TURN);
  execute();
  assertHandCount(playerA,daxosCard,0);
  assertPermanentCount(playerA,daxosCard,1);
  assertHandCount(playerA,"String_Node_Str",0);
  assertPermanentCount(playerA,"String_Node_Str",1);
  assertPowerToughness(playerA,daxosCard,5,5);
  assertType(daxosCard,CardType.CREATURE,SubType.DEMON);
  assertAbility(playerA,daxosCard,FlyingAbility.getInstance(),true);
  assertAbility(playerA,daxosCard,HasteAbility.getInstance(),true);
}
Program: 157633
Project: 157633
Buggy source:
@Test public void nagaVitalist_GiftOfParadiseCanAnyColor(){
  addCard(Zone.BATTLEFIELD,playerA,"String_Node_Str");
  addCard(Zone.BATTLEFIELD,playerA,"String_Node_Str",3);
  addCard(Zone.HAND,playerA,giftParadise);
  addCard(Zone.BATTLEFIELD,playerA,"String_Node_Str",1);
  activateManaAbility(1,PhaseStep.PRECOMBAT_MAIN,playerA,"String_Node_Str");
  activateManaAbility(1,PhaseStep.PRECOMBAT_MAIN,playerA,"String_Node_Str");
  activateManaAbility(1,PhaseStep.PRECOMBAT_MAIN,playerA,"String_Node_Str");
  castSpell(1,PhaseStep.PRECOMBAT_MAIN,playerA,giftParadise,"String_Node_Str");
  setStopAt(1,PhaseStep.PRECOMBAT_MAIN);
  execute();
  Assert.assertTrue("String_Node_Str",manaOptionsContain(playerA.getManaAvailable(currentGame),"String_Node_Str"));
}

Fixed version (ground truth):
@Test public void nagaVitalist_GiftOfParadiseCanAnyColor(){
  addCard(Zone.BATTLEFIELD,playerA,"String_Node_Str");
  addCard(Zone.BATTLEFIELD,playerA,"String_Node_Str",3);
  addCard(Zone.HAND,playerA,giftParadise);
  addCard(Zone.BATTLEFIELD,playerA,"String_Node_Str",1);
  activateManaAbility(1,PhaseStep.PRECOMBAT_MAIN,playerA,"String_Node_Str");
  activateManaAbility(1,PhaseStep.PRECOMBAT_MAIN,playerA,"String_Node_Str");
  activateManaAbility(1,PhaseStep.PRECOMBAT_MAIN,playerA,"String_Node_Str");
  castSpell(1,PhaseStep.PRECOMBAT_MAIN,playerA,giftParadise,"String_Node_Str");
  setStopAt(1,PhaseStep.PRECOMBAT_MAIN);
  execute();
  ManaOptions manaOptions=playerA.getAvailableManaTest(currentGame);
  assertDuplicatedManaOptions(manaOptions);
  Assert.assertEquals("String_Node_Str",5,manaOptions.size());
  assertManaOptions("String_Node_Str",manaOptions);
  assertManaOptions("String_Node_Str",manaOptions);
  assertManaOptions("String_Node_Str",manaOptions);
  assertManaOptions("String_Node_Str",manaOptions);
  assertManaOptions("String_Node_Str",manaOptions);
}
Program: 157634
Project: 157634
Buggy source:
/** 
 * Vorinclex glitches with Gemstone Cavern
 */
@Ignore @Test public void testGemstoneCavern(){
  addCard(Zone.BATTLEFIELD,playerB,"String_Node_Str",1);
  addCard(Zone.HAND,playerB,"String_Node_Str",1);
  addCard(Zone.HAND,playerB,"String_Node_Str",2);
  activateManaAbility(2,PhaseStep.PRECOMBAT_MAIN,playerB,"String_Node_Str");
  setChoice(playerB,"String_Node_Str");
  castSpell(2,PhaseStep.PRECOMBAT_MAIN,playerB,"String_Node_Str");
  setStopAt(2,PhaseStep.BEGIN_COMBAT);
  execute();
  assertPermanentCount(playerB,"String_Node_Str",1);
  assertCounterCount("String_Node_Str",CounterType.LUCK,1);
  assertPermanentCount(playerB,"String_Node_Str",1);
  assertExileCount("String_Node_Str",1);
  assertTapped("String_Node_Str",true);
}

Fixed version (ground truth):
/** 
 * Vorinclex glitches with Gemstone Cavern
 */
@Test public void testGemstoneCavern(){
  addCard(Zone.BATTLEFIELD,playerB,"String_Node_Str",1);
  addCard(Zone.HAND,playerB,"String_Node_Str",1);
  addCard(Zone.HAND,playerB,"String_Node_Str",2);
  activateManaAbility(2,PhaseStep.PRECOMBAT_MAIN,playerB,"String_Node_Str");
  setChoice(playerB,"String_Node_Str");
  castSpell(2,PhaseStep.PRECOMBAT_MAIN,playerB,"String_Node_Str");
  setStopAt(2,PhaseStep.BEGIN_COMBAT);
  execute();
  assertPermanentCount(playerB,"String_Node_Str",1);
  assertCounterCount("String_Node_Str",CounterType.LUCK,1);
  assertPermanentCount(playerB,"String_Node_Str",1);
  assertExileCount("String_Node_Str",1);
  assertTapped("String_Node_Str",true);
}
Program: 157635
Project: 157635
Buggy source:
@Override public boolean apply(Game game,Ability source){
  Player controller=game.getPlayer(source.getControllerId());
  if (controller == null) {
    return false;
  }
  Mana mana=getMana(game,source);
  controller.getManaPool().addMana(mana,game,source);
  if (produceMana(true,game,source).getAny() > 0) {
    checkToFirePossibleEvents(mana,game,source);
  }
  return true;
}

Fixed version (ground truth):
@Override public boolean apply(Game game,Ability source){
  Player controller=game.getPlayer(source.getControllerId());
  if (controller == null) {
    return false;
  }
  Mana mana=getMana(game,source);
  if (produceMana(true,game,source).getAny() > 0) {
    checkToFirePossibleEvents(mana,game,source);
  }
  controller.getManaPool().addMana(mana,game,source);
  return true;
}
Program: 157636
Project: 157636
Buggy source:
public AddManaOfAnyColorEffect(final AddManaOfAnyColorEffect effect){
  super(effect);
  this.amount=effect.amount;
}

Fixed version (ground truth):
public AddManaOfAnyColorEffect(final AddManaOfAnyColorEffect effect){
  super(effect);
  this.amount=effect.amount;
  this.netMana.addAll(effect.netMana);
}
Program: 157637
Project: 157637
Buggy source:
@Override public boolean apply(Game game,Ability source){
  Player controller=game.getPlayer(source.getControllerId());
  if (controller != null) {
    String mes=String.format("String_Node_Str",this.amount);
    ChoiceColor choice=new ChoiceColor(true,mes,game.getObject(source.getSourceId()));
    if (controller.choose(outcome,choice,game)) {
      if (choice.getColor() == null) {
        return false;
      }
      Mana createdMana=choice.getMana(amount);
      if (createdMana != null) {
        checkToFirePossibleEvents(createdMana,game,source);
        controller.getManaPool().addMana(createdMana,game,source);
      }
      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) {
    checkToFirePossibleEvents(getMana(game,source),game,source);
    controller.getManaPool().addMana(getMana(game,source),game,source);
    return true;
  }
  return false;
}
Program: 157638
Project: 157638
Buggy source:
@Override public List<Mana> getNetMana(Game game){
  List<Mana> newNetMana=new ArrayList<>();
  newNetMana.add(conditionalManaEffect.getMana(game,this));
  return newNetMana;
}

Fixed version (ground truth):
@Override public List<Mana> getNetMana(Game game){
  List<Mana> newNetMana=new ArrayList<>();
  newNetMana.addAll(conditionalManaEffect.getNetMana(game,this));
  return newNetMana;
}
Program: 157639
Project: 157639
Buggy source:
public void addMana(Mana manaToAdd,Game game,Ability source,boolean emptyOnTurnsEnd){
  Mana mana=manaToAdd.copy();
  if (!game.replaceEvent(new ManaEvent(EventType.ADD_MANA,source.getId(),source.getSourceId(),playerId,mana))) {
    if (mana instanceof ConditionalMana) {
      ManaPoolItem item=new ManaPoolItem((ConditionalMana)mana,source.getSourceObject(game),((ConditionalMana)mana).getManaProducerOriginalId() != null ? ((ConditionalMana)mana).getManaProducerOriginalId() : source.getOriginalId());
      if (emptyOnTurnsEnd) {
        item.setDuration(Duration.EndOfTurn);
      }
      this.manaItems.add(item);
    }
 else {
      ManaPoolItem item=new ManaPoolItem(mana.getRed(),mana.getGreen(),mana.getBlue(),mana.getWhite(),mana.getBlack(),mana.getGeneric() + mana.getColorless(),source.getSourceObject(game),source.getOriginalId(),mana.getFlag());
      if (emptyOnTurnsEnd) {
        item.setDuration(Duration.EndOfTurn);
      }
      this.manaItems.add(item);
    }
    ManaEvent manaEvent=new ManaEvent(EventType.MANA_ADDED,source.getId(),source.getSourceId(),playerId,mana);
    manaEvent.setData(mana.toString());
    game.fireEvent(manaEvent);
  }
}

Fixed version (ground truth):
public void addMana(Mana manaToAdd,Game game,Ability source,boolean emptyOnTurnsEnd){
  if (manaToAdd != null) {
    Mana mana=manaToAdd.copy();
    if (!game.replaceEvent(new ManaEvent(EventType.ADD_MANA,source.getId(),source.getSourceId(),playerId,mana))) {
      if (mana instanceof ConditionalMana) {
        ManaPoolItem item=new ManaPoolItem((ConditionalMana)mana,source.getSourceObject(game),((ConditionalMana)mana).getManaProducerOriginalId() != null ? ((ConditionalMana)mana).getManaProducerOriginalId() : source.getOriginalId());
        if (emptyOnTurnsEnd) {
          item.setDuration(Duration.EndOfTurn);
        }
        this.manaItems.add(item);
      }
 else {
        ManaPoolItem item=new ManaPoolItem(mana.getRed(),mana.getGreen(),mana.getBlue(),mana.getWhite(),mana.getBlack(),mana.getGeneric() + mana.getColorless(),source.getSourceObject(game),source.getOriginalId(),mana.getFlag());
        if (emptyOnTurnsEnd) {
          item.setDuration(Duration.EndOfTurn);
        }
        this.manaItems.add(item);
      }
      ManaEvent manaEvent=new ManaEvent(EventType.MANA_ADDED,source.getId(),source.getSourceId(),playerId,mana);
      manaEvent.setData(mana.toString());
      game.fireEvent(manaEvent);
    }
  }
}
Program: 157641
Project: 157641
Buggy source:
private void handleForcedToPayOnlyForCurrentPayment(Game game,ManaPool pool,ManaCosts referenceCosts){
  if (pool.isForcedToPay()) {
    if (referenceCosts != null && this.getPayment().equals(referenceCosts.getPayment())) {
      UUID playerId=pool.getPlayerId();
      Player player=game.getPlayer(playerId);
      if (player != null) {
        game.undo(playerId);
        this.clearPaid();
        game.bookmarkState();
      }
    }
  }
}

Fixed version (ground truth):
private void handleForcedToPayOnlyForCurrentPayment(Game game,ManaPool pool,ManaCosts referenceCosts){
  if (pool.isForcedToPay()) {
    if (referenceCosts != null && this.getPayment().equals(referenceCosts.getPayment())) {
      UUID playerId=pool.getPlayerId();
      Player player=game.getPlayer(playerId);
      if (player != null) {
        game.undo(playerId);
        this.clearPaid();
        player.getManaPool().restoreMana(pool.getPoolBookmark());
        game.bookmarkState();
      }
    }
  }
}
Program: 157643
Project: 157643
Buggy source:
void resetControlAfterSpellResolve(Spell spell);

Fixed version (ground truth):
void resetControlAfterSpellResolve(UUID topId);
Program: 157644
Project: 157644
Buggy source:
protected void resolve(){
  StackObject top=null;
  try {
    top=state.getStack().peek();
    Spell topSpell=getSpell(top.getId());
    if (topSpell != null) {
      top.resolve(this);
      resetControlAfterSpellResolve(topSpell);
    }
 else {
      top.resolve(this);
    }
  }
  finally {
    if (top != null) {
      state.getStack().remove(top,this);
      rememberLKI(top.getSourceId(),Zone.STACK,top);
      checkInfiniteLoop(top.getSourceId());
      if (!getTurn().isEndTurnRequested()) {
        while (state.hasSimultaneousEvents()) {
          state.handleSimultaneousEvent(this);
        }
      }
    }
  }
}

Fixed version (ground truth):
protected void resolve(){
  StackObject top=null;
  try {
    top=state.getStack().peek();
    top.resolve(this);
    resetControlAfterSpellResolve(top.getId());
  }
  finally {
    if (top != null) {
      state.getStack().remove(top,this);
      rememberLKI(top.getSourceId(),Zone.STACK,top);
      checkInfiniteLoop(top.getSourceId());
      if (!getTurn().isEndTurnRequested()) {
        while (state.hasSimultaneousEvents()) {
          state.handleSimultaneousEvent(this);
        }
      }
    }
  }
}
Program: 157645
Project: 157645
Buggy source:
@Override public void resetControlAfterSpellResolve(Spell spell){
  if (spell.getCommandedBy() != null) {
    UUID commandedBy=spell.getCommandedBy();
    UUID spellControllerId=null;
    if (commandedBy.equals(spell.getControllerId())) {
      spellControllerId=spell.getSpellAbility().getFirstTarget();
    }
 else {
      spellControllerId=spell.getControllerId();
    }
    if (commandedBy != null && spellControllerId != null) {
      Player turnController=getPlayer(commandedBy);
      if (turnController != null) {
        Player targetPlayer=getPlayer(spellControllerId);
        if (targetPlayer != null) {
          informPlayers(turnController.getLogName() + "String_Node_Str" + targetPlayer.getLogName());
          turnController.resetOtherTurnsControlled();
          targetPlayer.setGameUnderYourControl(true);
        }
      }
    }
  }
}

Fixed version (ground truth):
@Override public void resetControlAfterSpellResolve(UUID topId){
  Spell spell=getSpellOrLKIStack(topId);
  if (spell != null) {
    if (spell.getCommandedBy() != null) {
      UUID commandedBy=spell.getCommandedBy();
      UUID spellControllerId=null;
      if (commandedBy.equals(spell.getControllerId())) {
        spellControllerId=spell.getSpellAbility().getFirstTarget();
      }
 else {
        spellControllerId=spell.getControllerId();
      }
      if (commandedBy != null && spellControllerId != null) {
        Player turnController=getPlayer(commandedBy);
        if (turnController != null) {
          Player targetPlayer=getPlayer(spellControllerId);
          if (targetPlayer != null) {
            informPlayers(turnController.getLogName() + "String_Node_Str" + targetPlayer.getLogName());
            turnController.resetOtherTurnsControlled();
            targetPlayer.setGameUnderYourControl(true);
          }
        }
      }
    }
  }
}
Program: 157646
Project: 157646
Buggy source:
public void resolve(Game game){
  StackObject top=null;
  try {
    top=this.peek();
    Spell topSpell=getSpell(top.getId());
    if (topSpell != null) {
      top.resolve(game);
      game.resetControlAfterSpellResolve(topSpell);
    }
 else {
      top.resolve(game);
    }
  }
  finally {
    if (top != null) {
      if (contains(top)) {
        logger.warn("String_Node_Str" + top.getName());
        this.remove(top,game);
      }
    }
  }
}

Fixed version (ground truth):
public void resolve(Game game){
  StackObject top=null;
  try {
    top=this.peek();
    top.resolve(game);
    game.resetControlAfterSpellResolve(top.getId());
  }
  finally {
    if (top != null) {
      if (contains(top)) {
        logger.warn("String_Node_Str" + top.getName());
        this.remove(top,game);
      }
    }
  }
}
Program: 157647
Project: 157647
Buggy source:
public ManaPool(final ManaPool pool){
  this.playerId=pool.playerId;
  for (  ManaPoolItem item : pool.manaItems) {
    manaItems.add(item.copy());
  }
  this.autoPayment=pool.autoPayment;
  this.autoPaymentRestricted=pool.autoPaymentRestricted;
  this.unlockedManaType=pool.unlockedManaType;
  this.forcedToPay=pool.forcedToPay;
  this.doNotEmptyManaTypes.addAll(pool.doNotEmptyManaTypes);
}

Fixed version (ground truth):
public ManaPool(final ManaPool pool){
  this.playerId=pool.playerId;
  for (  ManaPoolItem item : pool.manaItems) {
    manaItems.add(item.copy());
  }
  this.autoPayment=pool.autoPayment;
  this.autoPaymentRestricted=pool.autoPaymentRestricted;
  this.unlockedManaType=pool.unlockedManaType;
  this.forcedToPay=pool.forcedToPay;
  for (  ManaPoolItem item : pool.poolBookmark) {
    poolBookmark.add(item.copy());
  }
  this.doNotEmptyManaTypes.addAll(pool.doNotEmptyManaTypes);
}
Program: 157651
Project: 157651
Buggy source:
/** 
 * Manual player action for undoing all declared blockers  (used for single-blocker creatures and multi-blockers exceeding blocking limit)
 * @param blockerId
 * @param game
 */
public void removeBlocker(UUID blockerId,Game game){
  for (  CombatGroup group : groups) {
    if (group.blockers.contains(blockerId)) {
      group.blockers.remove(blockerId);
      group.blockerOrder.remove(blockerId);
      if (group.blockers.isEmpty()) {
        group.blocked=false;
      }
    }
  }
  boolean canRemove=false;
  for (  CombatGroup group : getBlockingGroups()) {
    if (group.blockers.contains(blockerId)) {
      group.blockers.remove(blockerId);
      group.attackerOrder.clear();
    }
    if (group.blockers.isEmpty()) {
      canRemove=true;
    }
  }
  if (canRemove) {
    blockingGroups.remove(blockerId);
  }
  Permanent creature=game.getPermanent(blockerId);
  if (creature != null) {
    creature.setBlocking(0);
  }
}

Fixed version (ground truth):
/** 
 * Manual player action for undoing all declared blockers (used for single-blocker creatures and multi-blockers exceeding blocking limit)
 * @param blockerId
 * @param game
 */
public void removeBlocker(UUID blockerId,Game game){
  for (  CombatGroup group : groups) {
    if (group.blockers.contains(blockerId)) {
      group.blockers.remove(blockerId);
      group.blockerOrder.remove(blockerId);
      if (group.blockers.isEmpty()) {
        group.blocked=false;
      }
    }
  }
  boolean canRemove=false;
  for (  CombatGroup group : getBlockingGroups()) {
    if (group.blockers.contains(blockerId)) {
      group.blockers.remove(blockerId);
      group.attackerOrder.clear();
    }
    if (group.blockers.isEmpty()) {
      canRemove=true;
    }
  }
  if (canRemove) {
    blockingGroups.remove(blockerId);
  }
  Permanent creature=game.getPermanent(blockerId);
  if (creature != null) {
    creature.setBlocking(0);
  }
}
Program: 157652
Project: 157652
Buggy source:
@Override public Mana produceMana(boolean netMana,Game game,Ability source){
  if (netMana) {
    return null;
  }
  Player controller=game.getPlayer(source.getControllerId());
  if (controller != null) {
    int manaCostExiled=0;
    for (    Cost cost : source.getCosts()) {
      if (cost.isPaid() && cost instanceof ExileTargetCost) {
        for (        Card card : ((ExileTargetCost)cost).getPermanents()) {
          manaCostExiled+=card.getConvertedManaCost();
        }
      }
    }
    ChoiceColor choice=new ChoiceColor();
    if (!controller.choose(Outcome.PutManaInPool,choice,game)) {
      return null;
    }
    Mana chosen=choice.getMana(manaCostExiled + 1);
    return new FoodChainManaBuilder().setMana(chosen,source,game).build();
  }
  return null;
}

Fixed version (ground truth):
@Override public Mana produceMana(boolean netMana,Game game,Ability source){
  if (netMana) {
    return null;
  }
  Player controller=game.getPlayer(source.getControllerId());
  if (controller != null) {
    int manaCostExiled=0;
    for (    Cost cost : source.getCosts()) {
      if (cost.isPaid() && cost instanceof ExileTargetCost) {
        for (        Card card : ((ExileTargetCost)cost).getPermanents()) {
          manaCostExiled+=card.getConvertedManaCost();
        }
      }
    }
    ChoiceColor choice=new ChoiceColor();
    if (!controller.choose(Outcome.PutManaInPool,choice,game)) {
      return null;
    }
    Mana chosen=choice.getMana(manaCostExiled + 1);
    return manaBuilder.setMana(chosen,source,game).build();
  }
  return null;
}
Program: 157653
Project: 157653
Buggy source:
/** 
 * Used to check the possible mana production to determine which spells and/or abilities can be used. (player.getPlayable()).
 * @param game
 * @return
 */
@Override public List<Mana> getNetMana(Game game){
  if (netMana.isEmpty()) {
    for (    Effect effect : getEffects()) {
      if (effect instanceof ManaEffect) {
        netMana.addAll(((ManaEffect)effect).getNetMana(game,this));
      }
    }
  }
  ArrayList<Mana> netManaCopy=new ArrayList<>();
  for (  Mana mana : netMana) {
    netManaCopy.add(mana.copy());
  }
  return netManaCopy;
}

Fixed version (ground truth):
/** 
 * Used to check the possible mana production to determine which spells and/or abilities can be used. (player.getPlayable()).
 * @param game
 * @return
 */
@Override public List<Mana> getNetMana(Game game){
  if (netMana.isEmpty()) {
    ArrayList<Mana> dynamicNetMana=new ArrayList<>();
    for (    Effect effect : getEffects()) {
      if (effect instanceof ManaEffect) {
        dynamicNetMana.addAll(((ManaEffect)effect).getNetMana(game,this));
      }
    }
    return dynamicNetMana;
  }
  ArrayList<Mana> netManaCopy=new ArrayList<>();
  for (  Mana mana : netMana) {
    netManaCopy.add(mana.copy());
  }
  return netManaCopy;
}
Program: 157654
Project: 157654
Buggy source:
@Override public boolean applies(GameEvent event,Ability source,Game game){
  if (event.getTargetId().equals(source.getSourceId())) {
    ZoneChangeEvent zEvent=(ZoneChangeEvent)event;
    if (zEvent.getFromZone() == Zone.BATTLEFIELD && zEvent.getToZone() != Zone.EXILED) {
      return source.getSourceObjectZoneChangeCounter() + 1 == game.getState().getZoneChangeCounter(source.getSourceId());
    }
  }
  return false;
}

Fixed version (ground truth):
@Override public boolean applies(GameEvent event,Ability source,Game game){
  if (event.getTargetId().equals(source.getSourceId())) {
    ZoneChangeEvent zEvent=(ZoneChangeEvent)event;
    if (zEvent.getFromZone() == Zone.BATTLEFIELD && zEvent.getToZone() != Zone.EXILED) {
      return source.getSourceObjectZoneChangeCounter() == game.getState().getZoneChangeCounter(source.getSourceId());
    }
  }
  return false;
}
Program: 157655
Project: 157655
Buggy source:
@Override public void addEffect(ContinuousEffect continuousEffect,Ability source){
  Ability newAbility=source.copy();
  ContinuousEffect newEffect=continuousEffect.copy();
  newEffect.newId();
  newEffect.init(newAbility,this);
  state.addEffect(newEffect,newAbility);
}

Fixed version (ground truth):
@Override public void addEffect(ContinuousEffect continuousEffect,Ability source){
  Ability newAbility=source.copy();
  newAbility.setSourceObject(null,this);
  ContinuousEffect newEffect=continuousEffect.copy();
  newEffect.newId();
  newEffect.init(newAbility,this);
  state.addEffect(newEffect,newAbility);
}
Program: 157656
Project: 157656
Buggy source:
/** 
 * Returns an iterator over all listeners for the specified classes. the listener classes are in the specified order. for every class, listeners are in the reverse order of registering. A listener contained multiple times (for a single or multiple classes) is only returned the first time it occurs.
 * @param < T >
 * @param listenerClass
 * @return
 */
public <T extends EventListener>Iterator<T> getIterator(Class<? extends T>... listenerClass){
  return getIterable(listenerClass).iterator();
}

Fixed version (ground truth):
/** 
 * Returns an iterator over all listeners for the specified classes. the listener classes are in the specified order. for every class, listeners are in the reverse order of registering. A listener contained multiple times (for a single or multiple classes) is only returned the first time it occurs.
 * @param < T >
 * @param listenerClass
 * @return
 */
public <T extends EventListener>Iterator<T> getIterator(Class<T>... listenerClass){
  return getIterable(listenerClass).iterator();
}
Program: 157658
Project: 157658
Buggy source:
@Override public boolean apply(Game game,Ability source){
  Player controller=game.getPlayer(source.getControllerId());
  if (controller == null) {
    return false;
  }
  FilterLandPermanent filter=new FilterLandPermanent();
  filter.add(new ControllerPredicate(TargetController.YOU));
  int amount=new PermanentsOnBattlefieldCount(filter).calculate(game,source,this);
  TargetCardInLibrary target=new TargetCardInLibrary(0,amount,StaticFilters.FILTER_BASIC_LAND_CARD);
  if (controller.searchLibrary(target,game)) {
    controller.moveCards(new CardsImpl(target.getTargets()).getCards(game),Zone.BATTLEFIELD,source,game,true,false,false,null);
  }
  controller.shuffleLibrary(source,game);
  return true;
}

Fixed version (ground truth):
@Override public boolean apply(Game game,Ability source){
  Player controller=game.getPlayer(source.getControllerId());
  if (controller == null) {
    return false;
  }
  FilterLandPermanent filter=new FilterLandPermanent();
  filter.add(new ControllerPredicate(TargetController.YOU));
  int amount=new PermanentsOnBattlefieldCount(filter).calculate(game,source,this);
  TargetCardInLibrary target=new TargetCardInLibrary(0,amount,StaticFilters.FILTER_CARD_BASIC_LAND);
  if (controller.searchLibrary(target,game)) {
    controller.moveCards(new CardsImpl(target.getTargets()).getCards(game),Zone.BATTLEFIELD,source,game,true,false,false,null);
  }
  controller.shuffleLibrary(source,game);
  return true;
}
Program: 157659
Project: 157659
Buggy source:
@Override public boolean apply(Game game,Ability source){
  Player controller=game.getPlayer(source.getControllerId());
  MageObject sourceObject=source.getSourceObject(game);
  if (sourceObject != null && controller != null) {
    TargetCardInLibrary target=new TargetCardInLibrary(StaticFilters.FILTER_BASIC_LAND_CARD);
    if (controller.searchLibrary(target,game)) {
      Card card=controller.getLibrary().getCard(target.getFirstTarget(),game);
      if (card != null) {
        Cards cards=new CardsImpl(card);
        if (MorbidCondition.instance.apply(game,source) && controller.chooseUse(Outcome.PutLandInPlay,"String_Node_Str",source,game)) {
          controller.moveCards(card,Zone.BATTLEFIELD,source,game);
        }
 else {
          controller.moveCards(card,Zone.HAND,source,game);
        }
        controller.revealCards(sourceObject.getIdName(),cards,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());
  MageObject sourceObject=source.getSourceObject(game);
  if (sourceObject != null && controller != null) {
    TargetCardInLibrary target=new TargetCardInLibrary(StaticFilters.FILTER_CARD_BASIC_LAND);
    if (controller.searchLibrary(target,game)) {
      Card card=controller.getLibrary().getCard(target.getFirstTarget(),game);
      if (card != null) {
        Cards cards=new CardsImpl(card);
        if (MorbidCondition.instance.apply(game,source) && controller.chooseUse(Outcome.PutLandInPlay,"String_Node_Str",source,game)) {
          controller.moveCards(card,Zone.BATTLEFIELD,source,game);
        }
 else {
          controller.moveCards(card,Zone.HAND,source,game);
        }
        controller.revealCards(sourceObject.getIdName(),cards,game);
      }
    }
    controller.shuffleLibrary(source,game);
    return true;
  }
  return false;
}
Program: 157660
Project: 157660
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 (!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,StaticFilters.FILTER_BASIC_LAND_CARD);
        if (player.searchLibrary(target,game)) {
          player.moveCards(new CardsImpl(target.getTargets()).getCards(game),Zone.BATTLEFIELD,source,game,true,false,true,null);
          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,StaticFilters.FILTER_CARD_BASIC_LAND);
        if (player.searchLibrary(target,game)) {
          player.moveCards(new CardsImpl(target.getTargets()).getCards(game),Zone.BATTLEFIELD,source,game,true,false,true,null);
          player.shuffleLibrary(source,game);
        }
      }
    }
    controller.resetStoredBookmark(game);
    return true;
  }
  return false;
}
Program: 157661
Project: 157661
Buggy source:
@Override public boolean apply(Game game,Ability source){
  Player controller=game.getPlayer(source.getControllerId());
  MageObject sourceObject=game.getObject(source.getSourceId());
  if (controller == null || sourceObject == null) {
    return false;
  }
  TargetCardInLibrary target=new TargetCardInLibrary(0,2,StaticFilters.FILTER_BASIC_LAND_CARD);
  if (controller.searchLibrary(target,game)) {
    if (!target.getTargets().isEmpty()) {
      Cards revealed=new CardsImpl(target.getTargets());
      controller.revealCards(sourceObject.getIdName(),revealed,game);
      if (target.getTargets().size() == 2) {
        TargetCard target2=new TargetCard(Zone.LIBRARY,filter);
        controller.choose(Outcome.Benefit,revealed,target2,game);
        Card card=revealed.get(target2.getFirstTarget(),game);
        if (card != null) {
          controller.moveCards(card,Zone.BATTLEFIELD,source,game,true,false,false,null);
          revealed.remove(card);
        }
        card=revealed.getCards(game).iterator().next();
        if (card != null) {
          controller.moveCards(card,Zone.HAND,source,game);
        }
      }
 else       if (target.getTargets().size() == 1) {
        Card card=revealed.getCards(game).iterator().next();
        if (card != null) {
          controller.moveCards(card,Zone.BATTLEFIELD,source,game,true,false,false,null);
        }
      }
    }
  }
  controller.shuffleLibrary(source,game);
  return true;
}

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 (controller == null || sourceObject == null) {
    return false;
  }
  TargetCardInLibrary target=new TargetCardInLibrary(0,2,StaticFilters.FILTER_CARD_BASIC_LAND);
  if (controller.searchLibrary(target,game)) {
    if (!target.getTargets().isEmpty()) {
      Cards revealed=new CardsImpl(target.getTargets());
      controller.revealCards(sourceObject.getIdName(),revealed,game);
      if (target.getTargets().size() == 2) {
        TargetCard target2=new TargetCard(Zone.LIBRARY,filter);
        controller.choose(Outcome.Benefit,revealed,target2,game);
        Card card=revealed.get(target2.getFirstTarget(),game);
        if (card != null) {
          controller.moveCards(card,Zone.BATTLEFIELD,source,game,true,false,false,null);
          revealed.remove(card);
        }
        card=revealed.getCards(game).iterator().next();
        if (card != null) {
          controller.moveCards(card,Zone.HAND,source,game);
        }
      }
 else       if (target.getTargets().size() == 1) {
        Card card=revealed.getCards(game).iterator().next();
        if (card != null) {
          controller.moveCards(card,Zone.BATTLEFIELD,source,game,true,false,false,null);
        }
      }
    }
  }
  controller.shuffleLibrary(source,game);
  return true;
}
Program: 157662
Project: 157662
Buggy source:
@Override public boolean apply(Game game,Ability source){
  Permanent thisCreature=game.getPermanent(source.getId());
  FilterCreatureCard filter=new FilterCreatureCard("String_Node_Str");
  filter.add(new AbilityPredicate(MorphAbility.class));
  Effect effect=new PutCardFromHandOntoBattlefieldEffect(new FilterCreatureCard(filter));
  if (effect.apply(game,source)) {
    if (thisCreature != null) {
      effect=new ReturnToHandTargetEffect();
      effect.setTargetPointer(new FixedTarget(thisCreature.getId()));
      effect.apply(game,source);
      return true;
    }
  }
  return false;
}

Fixed version (ground truth):
@Override public boolean apply(Game game,Ability source){
  Permanent thisCreature=game.getPermanent(source.getId());
  FilterCreatureCard filter=new FilterCreatureCard("String_Node_Str");
  filter.add(new AbilityPredicate(MorphAbility.class));
  Effect effect=new PutCardFromHandOntoBattlefieldEffect(filter);
  if (effect.apply(game,source)) {
    if (thisCreature != null) {
      effect=new ReturnToHandTargetEffect();
      effect.setTargetPointer(new FixedTarget(thisCreature.getId()));
      effect.apply(game,source);
      return true;
    }
  }
  return false;
}