nus-yam/ex-repair huggingface dataset:
Program: 158922
Project: 158922
Buggy source:
@Override public String getValue(Game game){
  StringBuilder sb=threadLocalBuilder.get();
  SortedSet<String> cards=new TreeSet<>();
  for (  UUID cardId : this) {
    Card card=game.getCard(cardId);
    cards.add(card.getName());
  }
  for (  String name : cards) {
    sb.append(name).append("String_Node_Str");
  }
  return sb.toString();
}

Fixed version (ground truth):
@Override public String getValue(Game game){
  StringBuilder sb=threadLocalBuilder.get();
  List<String> cards=new ArrayList<>();
  for (  UUID cardId : this) {
    Card card=game.getCard(cardId);
    cards.add(card.getName());
  }
  Collections.sort(cards);
  for (  String name : cards) {
    sb.append(name).append("String_Node_Str");
  }
  return sb.toString();
}
Program: 158923
Project: 158923
Buggy source:
boolean canBeTargetedBy(MageObject source,Game game);

Fixed version (ground truth):
boolean canBeTargetedBy(MageObject source,UUID sourceControllerId,Game game);
Program: 158924
Project: 158924
Buggy source:
@Override public boolean canBeTargetedBy(MageObject source,Game game){
  if (this.hasLost() || this.hasLeft()) {
    return false;
  }
  if (source != null) {
    if (abilities.containsKey(ShroudAbility.getInstance().getId())) {
      return false;
    }
    if (abilities.containsKey(HexproofAbility.getInstance().getId())) {
      UUID controllerId=null;
      if (source instanceof Permanent) {
        controllerId=((Permanent)source).getControllerId();
      }
 else       if (source instanceof StackObject) {
        controllerId=((StackObject)source).getControllerId();
      }
      if (controllerId != null && this.hasOpponent(controllerId,game) && !game.getContinuousEffects().asThough(this.getId(),AsThoughEffectType.HEXPROOF,this.getId(),game)) {
        return false;
      }
    }
    if (hasProtectionFrom(source,game)) {
      return false;
    }
  }
  return true;
}

Fixed version (ground truth):
@Override public boolean canBeTargetedBy(MageObject source,UUID sourceControllerId,Game game){
  if (this.hasLost() || this.hasLeft()) {
    return false;
  }
  if (source != null) {
    if (abilities.containsKey(ShroudAbility.getInstance().getId())) {
      return false;
    }
    if (abilities.containsKey(HexproofAbility.getInstance().getId())) {
      if (sourceControllerId != null && this.hasOpponent(sourceControllerId,game) && !game.getContinuousEffects().asThough(this.getId(),AsThoughEffectType.HEXPROOF,this.getId(),game)) {
        return false;
      }
    }
    if (hasProtectionFrom(source,game)) {
      return false;
    }
  }
  return true;
}
Program: 158925
Project: 158925
Buggy source:
@Override public boolean canTarget(UUID controllerId,UUID id,Ability source,Game game){
  Permanent permanent=game.getPermanent(id);
  Player player=game.getPlayer(id);
  if (source != null) {
    MageObject targetSource=game.getObject(source.getSourceId());
    if (permanent != null) {
      return permanent.canBeTargetedBy(targetSource,source.getControllerId(),game) && filter.match(permanent,source.getSourceId(),source.getControllerId(),game);
    }
    if (player != null) {
      return player.canBeTargetedBy(targetSource,game) && filter.match(player,game);
    }
  }
  if (permanent != null) {
    return filter.match(permanent,game);
  }
  if (player != null) {
    return filter.match(player,game);
  }
  return false;
}

Fixed version (ground truth):
@Override public boolean canTarget(UUID controllerId,UUID id,Ability source,Game game){
  Permanent permanent=game.getPermanent(id);
  Player player=game.getPlayer(id);
  if (source != null) {
    MageObject targetSource=game.getObject(source.getSourceId());
    if (permanent != null) {
      return permanent.canBeTargetedBy(targetSource,source.getControllerId(),game) && filter.match(permanent,source.getSourceId(),source.getControllerId(),game);
    }
    if (player != null) {
      return player.canBeTargetedBy(targetSource,source.getControllerId(),game) && filter.match(player,game);
    }
  }
  if (permanent != null) {
    return filter.match(permanent,game);
  }
  if (player != null) {
    return filter.match(player,game);
  }
  return false;
}
Program: 158926
Project: 158926
Buggy source:
@Override public boolean canTarget(UUID id,Ability source,Game game){
  Permanent permanent=game.getPermanent(id);
  Player player=game.getPlayer(id);
  if (source != null) {
    MageObject targetSource=game.getObject(source.getSourceId());
    if (permanent != null) {
      if (!isNotTarget()) {
        if (!permanent.canBeTargetedBy(game.getObject(source.getId()),source.getControllerId(),game) || !permanent.canBeTargetedBy(game.getObject(source.getSourceId()),source.getControllerId(),game)) {
          return false;
        }
      }
      return filter.match(permanent,source.getSourceId(),source.getControllerId(),game);
    }
    if (player != null) {
      if (!isNotTarget()) {
        if (!player.canBeTargetedBy(targetSource,game)) {
          return false;
        }
      }
      return filter.match(player,game);
    }
  }
  if (permanent != null) {
    return filter.match(permanent,game);
  }
  if (player != null) {
    return filter.match(player,game);
  }
  return false;
}

Fixed version (ground truth):
@Override public boolean canTarget(UUID id,Ability source,Game game){
  Permanent permanent=game.getPermanent(id);
  Player player=game.getPlayer(id);
  if (source != null) {
    MageObject targetSource=game.getObject(source.getSourceId());
    if (permanent != null) {
      if (!isNotTarget()) {
        if (!permanent.canBeTargetedBy(game.getObject(source.getId()),source.getControllerId(),game) || !permanent.canBeTargetedBy(game.getObject(source.getSourceId()),source.getControllerId(),game)) {
          return false;
        }
      }
      return filter.match(permanent,source.getSourceId(),source.getControllerId(),game);
    }
    if (player != null) {
      if (!isNotTarget()) {
        if (!player.canBeTargetedBy(targetSource,source.getControllerId(),game)) {
          return false;
        }
      }
      return filter.match(player,game);
    }
  }
  if (permanent != null) {
    return filter.match(permanent,game);
  }
  if (player != null) {
    return filter.match(player,game);
  }
  return false;
}
Program: 158928
Project: 158928
Buggy source:
@Override public boolean apply(MageObject input,Game game){
  Spell spell=game.getStack().getSpell(input.getId());
  if (spell != null) {
    Targets spellTargets=spell.getSpellAbility().getTargets();
    int numberOfTargets=0;
    for (    Target target : spellTargets) {
      numberOfTargets+=target.getTargets().size();
    }
    if (numberOfTargets == targets) {
      return true;
    }
  }
  return false;
}

Fixed version (ground truth):
@Override public boolean apply(MageObject input,Game game){
  Spell spell=game.getStack().getSpell(input.getId());
  if (spell != null) {
    int numberOfTargets=0;
    for (    UUID modeId : spell.getSpellAbility().getModes().getSelectedModes()) {
      Mode mode=spell.getSpellAbility().getModes().get(modeId);
      for (      Target target : mode.getTargets()) {
        numberOfTargets+=target.getTargets().size();
      }
    }
    if (numberOfTargets == targets) {
      return true;
    }
  }
  return false;
}
Program: 158929
Project: 158929
Buggy source:
protected boolean isColoredPaid(ColoredManaSymbol mana){
switch (mana) {
case B:
    if (this.payment.getBlack() > 0) {
      return true;
    }
case U:
  if (this.payment.getBlue() > 0) {
    return true;
  }
case W:
if (this.payment.getWhite() > 0) {
  return true;
}
case G:
if (this.payment.getGreen() > 0) {
return true;
}
case R:
if (this.payment.getRed() > 0) {
return true;
}
}
return false;
}

Fixed version (ground truth):
protected boolean isColoredPaid(ColoredManaSymbol mana){
switch (mana) {
case B:
    return this.payment.getBlack() > 0;
case U:
  return this.payment.getBlue() > 0;
case W:
return this.payment.getWhite() > 0;
case G:
return this.payment.getGreen() > 0;
case R:
return this.payment.getRed() > 0;
}
return false;
}
Program: 158930
Project: 158930
Buggy source:
@Override public boolean applies(GameEvent event,Ability source,Game game){
  if (event.getType() == GameEvent.EventType.DRAW_CARD && event.getPlayerId().equals(source.getControllerId())) {
    return true;
  }
  return false;
}

Fixed version (ground truth):
@Override public boolean applies(GameEvent event,Ability source,Game game){
  return event.getPlayerId().equals(source.getControllerId());
}
Program: 158931
Project: 158931
Buggy source:
@Override public boolean applies(GameEvent event,Ability source,Game game){
  return EventType.DRAW_CARD.equals(event.getType()) && event.getPlayerId().equals(source.getControllerId());
}

Fixed version (ground truth):
@Override public boolean applies(GameEvent event,Ability source,Game game){
  return event.getPlayerId().equals(source.getControllerId());
}
Program: 158932
Project: 158932
Buggy source:
@Override public boolean applies(GameEvent event,Ability source,Game game){
  if (event.getType() == EventType.DRAW_CARD && event.getPlayerId().equals(source.getControllerId())) {
    Player player=game.getPlayer(event.getPlayerId());
    if (player.getHand().isEmpty()) {
      return true;
    }
  }
  return false;
}

Fixed version (ground truth):
@Override public boolean applies(GameEvent event,Ability source,Game game){
  if (event.getPlayerId().equals(source.getControllerId())) {
    Player player=game.getPlayer(event.getPlayerId());
    if (player.getHand().isEmpty()) {
      return true;
    }
  }
  return false;
}
Program: 158933
Project: 158933
Buggy source:
@Override public boolean applies(GameEvent event,Ability source,Game game){
  if (event.getType() == EventType.DRAW_CARD && game.getOpponents(source.getControllerId()).contains(event.getPlayerId())) {
    if (game.getActivePlayerId().equals(event.getPlayerId())) {
      CardsDrawnDuringDrawStepWatcher watcher=(CardsDrawnDuringDrawStepWatcher)game.getState().getWatchers().get("String_Node_Str");
      if (watcher != null && watcher.getAmountCardsDrawn(event.getPlayerId()) > 0) {
        return true;
      }
    }
 else {
      return true;
    }
  }
  return false;
}

Fixed version (ground truth):
@Override public boolean applies(GameEvent event,Ability source,Game game){
  if (game.getOpponents(source.getControllerId()).contains(event.getPlayerId())) {
    if (game.getActivePlayerId().equals(event.getPlayerId())) {
      CardsDrawnDuringDrawStepWatcher watcher=(CardsDrawnDuringDrawStepWatcher)game.getState().getWatchers().get("String_Node_Str");
      if (watcher != null && watcher.getAmountCardsDrawn(event.getPlayerId()) > 0) {
        return true;
      }
    }
 else {
      return true;
    }
  }
  return false;
}
Program: 158934
Project: 158934
Buggy source:
@Override public boolean applies(GameEvent event,Ability source,Game game){
  if (event.getType() == EventType.DRAW_CARD) {
    return true;
  }
  return false;
}

Fixed version (ground truth):
@Override public boolean applies(GameEvent event,Ability source,Game game){
  return true;
}
Program: 158935
Project: 158935
Buggy source:
@Override public boolean applies(GameEvent event,Ability source,Game game){
  if (event.getType() == EventType.DRAW_CARD) {
    if (game.getActivePlayerId().equals(event.getPlayerId()) && game.getPhase().getStep().getType().equals(PhaseStep.DRAW)) {
      CardsDrawnDuringDrawStepWatcher watcher=(CardsDrawnDuringDrawStepWatcher)game.getState().getWatchers().get("String_Node_Str");
      if (watcher != null && watcher.getAmountCardsDrawn(event.getPlayerId()) > 0) {
        return true;
      }
    }
 else {
      return true;
    }
  }
  return false;
}

Fixed version (ground truth):
@Override public boolean applies(GameEvent event,Ability source,Game game){
  if (game.getActivePlayerId().equals(event.getPlayerId()) && game.getPhase().getStep().getType().equals(PhaseStep.DRAW)) {
    CardsDrawnDuringDrawStepWatcher watcher=(CardsDrawnDuringDrawStepWatcher)game.getState().getWatchers().get("String_Node_Str");
    if (watcher != null && watcher.getAmountCardsDrawn(event.getPlayerId()) > 0) {
      return true;
    }
  }
 else {
    return true;
  }
  return false;
}
Program: 158936
Project: 158936
Buggy source:
@Override public boolean applies(GameEvent event,Ability source,Game game){
  if (event.getType() == EventType.ZONE_CHANGE && ((ZoneChangeEvent)event).getToZone() == Zone.GRAVEYARD) {
    Card card=game.getCard(event.getTargetId());
    if (card != null && card.getOwnerId().equals(source.getControllerId())) {
      Permanent permanent=((ZoneChangeEvent)event).getTarget();
      if (permanent == null || !(permanent instanceof PermanentToken)) {
        return true;
      }
    }
  }
  return false;
}

Fixed version (ground truth):
@Override public boolean applies(GameEvent event,Ability source,Game game){
  if (((ZoneChangeEvent)event).getToZone() == Zone.GRAVEYARD) {
    Card card=game.getCard(event.getTargetId());
    if (card != null && card.getOwnerId().equals(source.getControllerId())) {
      Permanent permanent=((ZoneChangeEvent)event).getTarget();
      if (permanent == null || !(permanent instanceof PermanentToken)) {
        return true;
      }
    }
  }
  return false;
}
Program: 158937
Project: 158937
Buggy source:
@Override public boolean applies(GameEvent event,Ability source,Game game){
  Permanent archmage=game.getPermanent(source.getSourceId());
  Player you=game.getPlayer(source.getControllerId());
  if (event.getType() == GameEvent.EventType.DRAW_CARD && event.getPlayerId().equals(source.getControllerId()) && archmage != null && you != null && you.chooseUse(Outcome.Benefit,"String_Node_Str",game)) {
    return true;
  }
  return false;
}

Fixed version (ground truth):
@Override public boolean applies(GameEvent event,Ability source,Game game){
  Permanent archmage=game.getPermanent(source.getSourceId());
  Player you=game.getPlayer(source.getControllerId());
  if (event.getPlayerId().equals(source.getControllerId()) && archmage != null && you != null && you.chooseUse(Outcome.Benefit,"String_Node_Str",game)) {
    return true;
  }
  return false;
}
Program: 158938
Project: 158938
Buggy source:
@Override public boolean applies(GameEvent event,Ability source,Game game){
  return event.getType() == EventType.DRAW_CARD && source.getControllerId().equals(event.getPlayerId()) && used == false;
}

Fixed version (ground truth):
@Override public boolean applies(GameEvent event,Ability source,Game game){
  return source.getControllerId().equals(event.getPlayerId());
}
Program: 158939
Project: 158939
Buggy source:
@Override public boolean replaceEvent(GameEvent event,Ability source,Game game){
  Player controller=game.getPlayer(source.getControllerId());
  if (controller != null) {
    Player player=game.getPlayer(targetPointer.getFirst(game,source));
    if (player != null) {
      player.damage(2,source.getSourceId(),game,false,true);
      used=true;
      return true;
    }
    Permanent permanent=game.getPermanent(targetPointer.getFirst(game,source));
    if (permanent != null) {
      permanent.damage(2,source.getSourceId(),game,false,true);
      used=true;
      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) {
    Player player=game.getPlayer(targetPointer.getFirst(game,source));
    if (player != null) {
      player.damage(2,source.getSourceId(),game,false,true);
      discard();
      return true;
    }
    Permanent permanent=game.getPermanent(targetPointer.getFirst(game,source));
    if (permanent != null) {
      permanent.damage(2,source.getSourceId(),game,false,true);
      discard();
      return true;
    }
  }
  return false;
}
Program: 158940
Project: 158940
Buggy source:
@Override public boolean applies(GameEvent event,Ability source,Game game){
  if (event.getType() == EventType.DRAW_CARD && source.getControllerId().equals(event.getPlayerId()) && used == false) {
    return true;
  }
  return false;
}

Fixed version (ground truth):
@Override public boolean applies(GameEvent event,Ability source,Game game){
  return source.getControllerId().equals(event.getPlayerId());
}
Program: 158941
Project: 158941
Buggy source:
@Override public boolean replaceEvent(GameEvent event,Ability source,Game game){
  game.informPlayers("String_Node_Str");
  for (  UUID playerId : game.getPlayerList()) {
    Player player=game.getPlayer(playerId);
    if (player != null) {
      TargetControlledPermanent target=new TargetControlledPermanent();
      List<Permanent> liste=game.getBattlefield().getActivePermanents(new FilterControlledPermanent(),playerId,game);
      if (!liste.isEmpty()) {
        while (!player.choose(Outcome.ReturnToHand,target,source.getSourceId(),game)) {
          if (!player.isInGame()) {
            return false;
          }
        }
        Permanent permanent=game.getPermanent(target.getFirstTarget());
        if (permanent != null) {
          permanent.moveToZone(Zone.HAND,source.getSourceId(),game,false);
        }
      }
    }
  }
  used=true;
  return apply(game,source);
}

Fixed version (ground truth):
@Override public boolean replaceEvent(GameEvent event,Ability source,Game game){
  game.informPlayers("String_Node_Str");
  for (  UUID playerId : game.getPlayerList()) {
    Player player=game.getPlayer(playerId);
    if (player != null) {
      TargetControlledPermanent target=new TargetControlledPermanent();
      List<Permanent> liste=game.getBattlefield().getActivePermanents(new FilterControlledPermanent(),playerId,game);
      if (!liste.isEmpty()) {
        while (!player.choose(Outcome.ReturnToHand,target,source.getSourceId(),game)) {
          if (!player.isInGame()) {
            return false;
          }
        }
        Permanent permanent=game.getPermanent(target.getFirstTarget());
        if (permanent != null) {
          permanent.moveToZone(Zone.HAND,source.getSourceId(),game,false);
        }
      }
    }
  }
  discard();
  return true;
}
Program: 158942
Project: 158942
Buggy source:
@Override public boolean applies(GameEvent event,Ability source,Game game){
  if (event.getType() == EventType.DRAW_CARD && event.getPlayerId().equals(source.getControllerId())) {
    Player player=game.getPlayer(source.getControllerId());
    if (player != null) {
      return player.chooseUse(Outcome.Benefit,"String_Node_Str",game);
    }
  }
  return false;
}

Fixed version (ground truth):
@Override public boolean applies(GameEvent event,Ability source,Game game){
  if (event.getPlayerId().equals(source.getControllerId())) {
    Player player=game.getPlayer(source.getControllerId());
    if (player != null) {
      return player.chooseUse(Outcome.Benefit,"String_Node_Str",game);
    }
  }
  return false;
}
Program: 158943
Project: 158943
Buggy source:
@Override public boolean applies(GameEvent event,Ability source,Game game){
  Permanent archmage=game.getPermanent(source.getSourceId());
  Player you=game.getPlayer(source.getControllerId());
  if (event.getType() == EventType.DRAW_CARD && event.getPlayerId().equals(source.getControllerId()) && archmage != null && archmage.getCounters().getCount(CounterType.QUEST) >= 6 && you != null && you.chooseUse(Outcome.Benefit,"String_Node_Str",game)) {
    return true;
  }
  return false;
}

Fixed version (ground truth):
@Override public boolean applies(GameEvent event,Ability source,Game game){
  Permanent archmage=game.getPermanent(source.getSourceId());
  Player you=game.getPlayer(source.getControllerId());
  if (event.getPlayerId().equals(source.getControllerId()) && archmage != null && archmage.getCounters().getCount(CounterType.QUEST) >= 6 && you != null && you.chooseUse(Outcome.Benefit,"String_Node_Str",game)) {
    return true;
  }
  return false;
}
Program: 158944
Project: 158944
Buggy source:
@Override public boolean checkTrigger(GameEvent event,Game game){
  Permanent archmage=game.getPermanent(super.getSourceId());
  CardsDrawnControllerWatcher watcher=(CardsDrawnControllerWatcher)game.getState().getWatchers().get("String_Node_Str");
  if (event.getType() == GameEvent.EventType.END_TURN_STEP_PRE && archmage != null && watcher != null && watcher.conditionMet()) {
    return true;
  }
  return false;
}

Fixed version (ground truth):
@Override public boolean checkTrigger(GameEvent event,Game game){
  Permanent archmage=game.getPermanent(super.getSourceId());
  CardsDrawnControllerWatcher watcher=(CardsDrawnControllerWatcher)game.getState().getWatchers().get("String_Node_Str");
  if (archmage != null && watcher != null && watcher.conditionMet()) {
    return true;
  }
  return false;
}
Program: 158945
Project: 158945
Buggy source:
@Override public boolean apply(Game game,Ability source){
  MageObject sourceObject=game.getObject(source.getSourceId());
  Player controller=game.getPlayer(source.getControllerId());
  if (sourceObject != null && controller != null) {
    Player owner=null;
    Cards cards=new CardsImpl();
    Permanent permanent=null;
    if (sourceObject instanceof Permanent) {
      permanent=(Permanent)sourceObject;
      owner=game.getPlayer(permanent.getOwnerId());
      if (sourceObject instanceof PermanentCard) {
        cards.add(permanent);
      }
    }
 else     if (sourceObject instanceof Card) {
      owner=game.getPlayer(((Card)sourceObject).getOwnerId());
      cards.add((Card)sourceObject);
    }
    if (owner != null) {
      Zone fromZone=game.getState().getZone(sourceObject.getId());
      if (!cards.isEmpty()) {
        controller.revealCards(sourceObject.getLogName(),cards,game);
      }
      if (permanent != null) {
        controller.moveCardToLibraryWithInfo(permanent,source.getSourceId(),game,fromZone,true,true);
      }
 else {
        controller.moveCardToLibraryWithInfo((Card)sourceObject,source.getSourceId(),game,fromZone,true,true);
      }
      if (!cards.isEmpty()) {
        controller.shuffleLibrary(game);
      }
    }
    return true;
  }
  return false;
}

Fixed version (ground truth):
@Override public boolean apply(Game game,Ability source){
  MageObject sourceObject=game.getObject(source.getSourceId());
  Player controller=game.getPlayer(source.getControllerId());
  if (sourceObject != null && controller != null) {
    Player owner=null;
    Cards cards=new CardsImpl();
    Permanent permanent=null;
    if (sourceObject instanceof Spell) {
      sourceObject=((Spell)sourceObject).getCard();
    }
    if (sourceObject instanceof Permanent) {
      permanent=(Permanent)sourceObject;
      owner=game.getPlayer(permanent.getOwnerId());
      if (sourceObject instanceof PermanentCard) {
        cards.add(permanent);
      }
    }
 else     if (sourceObject instanceof Card) {
      owner=game.getPlayer(((Card)sourceObject).getOwnerId());
      cards.add((Card)sourceObject);
    }
    if (owner != null) {
      Zone fromZone=game.getState().getZone(sourceObject.getId());
      if (!cards.isEmpty()) {
        controller.revealCards(sourceObject.getLogName(),cards,game);
      }
      if (permanent != null) {
        controller.moveCardToLibraryWithInfo(permanent,source.getSourceId(),game,fromZone,true,true);
      }
 else {
        controller.moveCardToLibraryWithInfo((Card)sourceObject,source.getSourceId(),game,fromZone,true,true);
      }
      if (!cards.isEmpty()) {
        controller.shuffleLibrary(game);
      }
    }
    return true;
  }
  return false;
}
Program: 158946
Project: 158946
Buggy source:
/** 
 * Checks if Copy Enchantment works for palyer auras
 */
@Test public void testCurseOfExhaustion3(){
  addCard(Zone.BATTLEFIELD,playerA,"String_Node_Str",4);
  addCard(Zone.BATTLEFIELD,playerA,"String_Node_Str",2);
  addCard(Zone.BATTLEFIELD,playerB,"String_Node_Str",3);
  addCard(Zone.HAND,playerA,"String_Node_Str");
  addCard(Zone.HAND,playerA,"String_Node_Str",2);
  addCard(Zone.HAND,playerB,"String_Node_Str",1);
  castSpell(1,PhaseStep.PRECOMBAT_MAIN,playerA,"String_Node_Str",playerB);
  castSpell(4,PhaseStep.POSTCOMBAT_MAIN,playerA,"String_Node_Str",playerB);
  castSpell(4,PhaseStep.PRECOMBAT_MAIN,playerB,"String_Node_Str");
  setChoice(playerB,"String_Node_Str");
  setChoice(playerB,"String_Node_Str");
  setChoice(playerB,"String_Node_Str");
  castSpell(4,PhaseStep.POSTCOMBAT_MAIN,playerA,"String_Node_Str",playerB);
  setStopAt(4,PhaseStep.END_TURN);
  execute();
  assertHandCount(playerB,"String_Node_Str",0);
  assertGraveyardCount(playerB,"String_Node_Str",0);
  assertPermanentCount(playerA,"String_Node_Str",1);
  assertPermanentCount(playerB,"String_Node_Str",1);
  assertLife(playerA,20);
  assertLife(playerB,17);
}

Fixed version (ground truth):
/** 
 * Checks if Copy Enchantment works for player auras
 */
@Test public void testCurseOfExhaustion3(){
  addCard(Zone.BATTLEFIELD,playerA,"String_Node_Str",4);
  addCard(Zone.BATTLEFIELD,playerA,"String_Node_Str",2);
  addCard(Zone.BATTLEFIELD,playerB,"String_Node_Str",3);
  addCard(Zone.HAND,playerA,"String_Node_Str");
  addCard(Zone.HAND,playerA,"String_Node_Str",2);
  addCard(Zone.HAND,playerB,"String_Node_Str",1);
  castSpell(1,PhaseStep.PRECOMBAT_MAIN,playerA,"String_Node_Str",playerB);
  castSpell(4,PhaseStep.POSTCOMBAT_MAIN,playerA,"String_Node_Str",playerB);
  castSpell(4,PhaseStep.PRECOMBAT_MAIN,playerB,"String_Node_Str");
  setChoice(playerB,"String_Node_Str");
  setChoice(playerB,"String_Node_Str");
  setChoice(playerB,"String_Node_Str");
  castSpell(4,PhaseStep.POSTCOMBAT_MAIN,playerA,"String_Node_Str",playerB);
  setStopAt(4,PhaseStep.END_TURN);
  execute();
  assertHandCount(playerB,"String_Node_Str",0);
  assertGraveyardCount(playerB,"String_Node_Str",0);
  assertPermanentCount(playerA,"String_Node_Str",1);
  assertPermanentCount(playerB,"String_Node_Str",1);
  assertLife(playerA,20);
  assertLife(playerB,17);
}
Program: 158947
Project: 158947
Buggy source:
public void removeEffects(UUID effectIdToRemove,Set<Ability> abilitiesToRemove){
  HashSet<Ability> abilities=effectAbilityMap.get(effectIdToRemove);
  if (abilitiesToRemove != null) {
    abilities.removeAll(abilitiesToRemove);
  }
  if (abilities.isEmpty()) {
    for (Iterator<T> iterator=this.iterator(); iterator.hasNext(); ) {
      ContinuousEffect effect=iterator.next();
      if (effect.getId().equals(effectIdToRemove)) {
        iterator.remove();
        break;
      }
    }
    effectAbilityMap.remove(effectIdToRemove);
  }
}

Fixed version (ground truth):
public void removeEffects(UUID effectIdToRemove,Set<Ability> abilitiesToRemove){
  HashSet<Ability> abilities=effectAbilityMap.get(effectIdToRemove);
  if (abilitiesToRemove != null && abilities != null) {
    abilities.removeAll(abilitiesToRemove);
  }
  if (abilities == null || abilities.isEmpty()) {
    for (Iterator<T> iterator=this.iterator(); iterator.hasNext(); ) {
      ContinuousEffect effect=iterator.next();
      if (effect.getId().equals(effectIdToRemove)) {
        iterator.remove();
        break;
      }
    }
    effectAbilityMap.remove(effectIdToRemove);
  }
}
Program: 158949
Project: 158949
Buggy source:
/** 
 * Tests that creature with Heavy Arbalest will use it and untap later after equip is equipped to another creature
 */
@Test public void testUntapsLater(){
  addCard(Zone.BATTLEFIELD,playerA,"String_Node_Str",8);
  addCard(Zone.BATTLEFIELD,playerA,"String_Node_Str");
  addCard(Zone.BATTLEFIELD,playerA,"String_Node_Str");
  addCard(Zone.BATTLEFIELD,playerA,"String_Node_Str");
  activateAbility(1,PhaseStep.PRECOMBAT_MAIN,playerA,"String_Node_Str","String_Node_Str");
  activateAbility(1,PhaseStep.PRECOMBAT_MAIN,playerA,"String_Node_Str",playerB);
  activateAbility(1,PhaseStep.PRECOMBAT_MAIN,playerA,"String_Node_Str","String_Node_Str");
  setStopAt(5,PhaseStep.BEGIN_COMBAT);
  execute();
  assertLife(playerA,20);
  assertLife(playerB,18);
  Permanent eliteVanguard=getPermanent("String_Node_Str",playerA.getId());
  Assert.assertTrue(eliteVanguard.getAttachments().size() == 0);
  Assert.assertFalse(eliteVanguard.isTapped());
}

Fixed version (ground truth):
/** 
 * Tests that creature with Heavy Arbalest will use it and untap later after equip is equipped to another creature
 */
@Test public void testUntapsLater(){
  addCard(Zone.BATTLEFIELD,playerA,"String_Node_Str",8);
  addCard(Zone.BATTLEFIELD,playerA,"String_Node_Str");
  addCard(Zone.BATTLEFIELD,playerA,"String_Node_Str");
  addCard(Zone.BATTLEFIELD,playerA,"String_Node_Str");
  activateAbility(1,PhaseStep.PRECOMBAT_MAIN,playerA,"String_Node_Str","String_Node_Str");
  activateAbility(1,PhaseStep.PRECOMBAT_MAIN,playerA,"String_Node_Str",playerB);
  activateAbility(1,PhaseStep.PRECOMBAT_MAIN,playerA,"String_Node_Str","String_Node_Str");
  setStopAt(5,PhaseStep.BEGIN_COMBAT);
  execute();
  assertLife(playerA,20);
  assertLife(playerB,18);
  Permanent eliteVanguard=getPermanent("String_Node_Str",playerA.getId());
  Assert.assertTrue(eliteVanguard.getAttachments().isEmpty());
  Assert.assertFalse(eliteVanguard.isTapped());
}
Program: 158950
Project: 158950
Buggy source:
@Override public boolean apply(Game game,Ability source){
  Permanent permanent=game.getPermanent(getTargetPointer().getFirst(game,source));
  if (permanent != null) {
    return permanent.addAttachment(source.getSourceId(),game);
  }
 else {
    Player player=game.getPlayer(getTargetPointer().getFirst(game,source));
    if (player != null) {
      return player.addAttachment(source.getSourceId(),game);
    }
  }
  return false;
}

Fixed version (ground truth):
@Override public boolean apply(Game game,Ability source){
  Permanent sourcePermanent=(Permanent)source.getSourceObjectIfItStillExists(game);
  if (sourcePermanent != null) {
    Permanent permanent=game.getPermanent(getTargetPointer().getFirst(game,source));
    if (permanent != null) {
      return permanent.addAttachment(source.getSourceId(),game);
    }
 else {
      Player player=game.getPlayer(getTargetPointer().getFirst(game,source));
      if (player != null) {
        return player.addAttachment(source.getSourceId(),game);
      }
    }
  }
  return false;
}
Program: 158951
Project: 158951
Buggy source:
@Override public boolean apply(Game game,Ability source){
  Permanent sourcePermanent=(Permanent)source.getSourceObjectIfItStillExists(game);
  if (sourcePermanent != null) {
    Permanent permanent=game.getPermanent(getTargetPointer().getFirst(game,source));
    if (permanent != null) {
      return permanent.addAttachment(source.getSourceId(),game);
    }
 else {
      Player player=game.getPlayer(getTargetPointer().getFirst(game,source));
      if (player != null) {
        return player.addAttachment(source.getSourceId(),game);
      }
    }
  }
  return false;
}

Fixed version (ground truth):
@Override public boolean apply(Game game,Ability source){
  Permanent sourcePermanent=game.getPermanent(source.getSourceId());
  if (sourcePermanent != null) {
    int zcc=game.getState().getZoneChangeCounter(sourcePermanent.getId());
    if (zcc == source.getSourceObjectZoneChangeCounter() || zcc == source.getSourceObjectZoneChangeCounter() + 1) {
      Permanent permanent=game.getPermanent(getTargetPointer().getFirst(game,source));
      if (permanent != null) {
        return permanent.addAttachment(source.getSourceId(),game);
      }
 else {
        Player player=game.getPlayer(getTargetPointer().getFirst(game,source));
        if (player != null) {
          return player.addAttachment(source.getSourceId(),game);
        }
      }
    }
  }
  return false;
}
Program: 158952
Project: 158952
Buggy source:
/** 
 * Tests first trigger happens both on enter battlefield and transform events
 */
@Test public void testCard2(){
  addCard(Zone.BATTLEFIELD,playerA,"String_Node_Str",3);
  addCard(Zone.BATTLEFIELD,playerA,"String_Node_Str");
  addCard(Zone.HAND,playerA,"String_Node_Str");
  addCard(Zone.BATTLEFIELD,playerB,"String_Node_Str");
  addCard(Zone.BATTLEFIELD,playerB,"String_Node_Str",2);
  addCard(Zone.HAND,playerB,"String_Node_Str",2);
  castSpell(1,PhaseStep.PRECOMBAT_MAIN,playerA,"String_Node_Str");
  castSpell(3,PhaseStep.PRECOMBAT_MAIN,playerB,"String_Node_Str",playerA);
  castSpell(3,PhaseStep.PRECOMBAT_MAIN,playerB,"String_Node_Str",playerA);
  setStopAt(4,PhaseStep.DRAW);
  execute();
  assertLife(playerA,18);
  assertLife(playerB,18);
  assertPermanentCount(playerA,"String_Node_Str",2);
  assertPermanentCount(playerA,"String_Node_Str",0);
  assertPermanentCount(playerA,"String_Node_Str",1);
  assertPermanentCount(playerB,"String_Node_Str",0);
}

Fixed version (ground truth):
/** 
 * Tests first trigger happens both on enter battlefield and transform events
 */
@Test public void testCard2(){
  addCard(Zone.BATTLEFIELD,playerA,"String_Node_Str",3);
  addCard(Zone.BATTLEFIELD,playerA,"String_Node_Str");
  addCard(Zone.HAND,playerA,"String_Node_Str");
  addCard(Zone.BATTLEFIELD,playerB,"String_Node_Str",2);
  addCard(Zone.HAND,playerB,"String_Node_Str",2);
  castSpell(1,PhaseStep.PRECOMBAT_MAIN,playerA,"String_Node_Str");
  castSpell(3,PhaseStep.PRECOMBAT_MAIN,playerB,"String_Node_Str",playerA);
  castSpell(3,PhaseStep.PRECOMBAT_MAIN,playerB,"String_Node_Str",playerA);
  setStopAt(4,PhaseStep.DRAW);
  execute();
  assertLife(playerA,18);
  assertLife(playerB,18);
  assertPermanentCount(playerA,"String_Node_Str",2);
  assertPermanentCount(playerA,"String_Node_Str",0);
  assertPermanentCount(playerA,"String_Node_Str",1);
}
Program: 158953
Project: 158953
Buggy source:
/** 
 * Ravager of the Fells Creature — Werewolf 4/4 Trample Whenever this creature transforms into Ravager of the Fells, it deals 2  damage to target opponent and 2 damage to up to one target creature that  player controls. At the beginning of each upkeep, if a player cast two or more spells last  turn, transform Ravager of the Fells.
 */
@Test public void testCard(){
  addCard(Zone.BATTLEFIELD,playerA,"String_Node_Str",3);
  addCard(Zone.BATTLEFIELD,playerA,"String_Node_Str");
  addCard(Zone.HAND,playerA,"String_Node_Str");
  addCard(Zone.BATTLEFIELD,playerB,"String_Node_Str");
  castSpell(1,PhaseStep.PRECOMBAT_MAIN,playerA,"String_Node_Str");
  setStopAt(3,PhaseStep.DRAW);
  execute();
  assertLife(playerA,22);
  assertLife(playerB,18);
  assertPermanentCount(playerA,"String_Node_Str",1);
  assertPermanentCount(playerA,"String_Node_Str",0);
  assertPermanentCount(playerA,"String_Node_Str",1);
  assertPermanentCount(playerB,"String_Node_Str",0);
}

Fixed version (ground truth):
/** 
 * Ravager of the Fells Creature — Werewolf 4/4 Trample Whenever this creature transforms into Ravager of the Fells, it deals 2  damage to target opponent and 2 damage to up to one target creature that  player controls. At the beginning of each upkeep, if a player cast two or more spells last  turn, transform Ravager of the Fells.
 */
@Test public void testCard(){
  addCard(Zone.BATTLEFIELD,playerA,"String_Node_Str",3);
  addCard(Zone.BATTLEFIELD,playerA,"String_Node_Str");
  addCard(Zone.HAND,playerA,"String_Node_Str");
  castSpell(1,PhaseStep.PRECOMBAT_MAIN,playerA,"String_Node_Str");
  setStopAt(3,PhaseStep.DRAW);
  execute();
  assertLife(playerA,22);
  assertLife(playerB,18);
  assertPermanentCount(playerA,"String_Node_Str",1);
  assertPermanentCount(playerA,"String_Node_Str",0);
  assertPermanentCount(playerA,"String_Node_Str",1);
}
Program: 158954
Project: 158954
Buggy source:
@Override public boolean isInUseableZone(Game game,MageObject source,GameEvent event){
  if (event != null && event.getTargetId() != null && event.getTargetId().equals(getSourceId())) {
switch (event.getType()) {
case ZONE_CHANGE:
      if (source == null && ((ZoneChangeEvent)event).getTarget() != null) {
        source=((ZoneChangeEvent)event).getTarget();
      }
case DESTROYED_PERMANENT:
case PHASED_OUT:
case PHASED_IN:
    if (game.getLastKnownInformation(getSourceId(),zone) != null) {
      return true;
    }
}
}
return super.isInUseableZone(game,source,event);
}

Fixed version (ground truth):
@Override public boolean isInUseableZone(Game game,MageObject source,GameEvent event){
  if (event != null && event.getTargetId() != null && event.getTargetId().equals(getSourceId())) {
switch (event.getType()) {
case ZONE_CHANGE:
      if (source == null && ((ZoneChangeEvent)event).getTarget() != null) {
        source=((ZoneChangeEvent)event).getTarget();
      }
case DESTROYED_PERMANENT:
case PHASED_OUT:
case PHASED_IN:
    if (this.zone == Zone.ALL || game.getLastKnownInformation(getSourceId(),zone) != null) {
      return true;
    }
}
}
return super.isInUseableZone(game,source,event);
}
Program: 158955
Project: 158955
Buggy source:
private String normalizeName(String name){
  return name.replace("String_Node_Str","String_Node_Str").replace("String_Node_Str","String_Node_Str").replace("String_Node_Str","String_Node_Str").replace("String_Node_Str","String_Node_Str").replace("String_Node_Str","String_Node_Str").replace("String_Node_Str","String_Node_Str").replace("String_Node_Str","String_Node_Str").replace("String_Node_Str","String_Node_Str").replace("String_Node_Str","String_Node_Str").replace("String_Node_Str","String_Node_Str").replace("String_Node_Str","String_Node_Str").replace("String_Node_Str","String_Node_Str").replace("String_Node_Str","String_Node_Str").replace("String_Node_Str","String_Node_Str").replace("String_Node_Str","String_Node_Str").replace("String_Node_Str","String_Node_Str").replace("String_Node_Str","String_Node_Str");
}

Fixed version (ground truth):
private String normalizeName(String name){
  return name.replace("String_Node_Str","String_Node_Str").replace("String_Node_Str","String_Node_Str").replace("String_Node_Str","String_Node_Str").replace("String_Node_Str","String_Node_Str").replace("String_Node_Str","String_Node_Str").replace("String_Node_Str","String_Node_Str").replace("String_Node_Str","String_Node_Str").replace("String_Node_Str","String_Node_Str").replace("String_Node_Str","String_Node_Str").replace("String_Node_Str","String_Node_Str").replace("String_Node_Str","String_Node_Str").replace("String_Node_Str","String_Node_Str").replace("String_Node_Str","String_Node_Str").replace("String_Node_Str","String_Node_Str").replace("String_Node_Str","String_Node_Str").replace("String_Node_Str","String_Node_Str").replace("String_Node_Str","String_Node_Str").replace("String_Node_Str","String_Node_Str");
}
Program: 158956
Project: 158956
Buggy source:
@Override public boolean applies(GameEvent event,Ability source,Game game){
  boolean applies=false;
  if (EventType.SEARCH_LIBRARY.equals(event.getType())) {
    applies=true;
    Permanent permanent=game.getPermanent(source.getSourceId());
    String key=permanent.getId() + keyString;
    Map.Entry<Long,Set<UUID>> turnIgnoringPlayersPair=(Map.Entry<Long,Set<UUID>>)game.getState().getValue(key);
    if (turnIgnoringPlayersPair != null) {
      long zoneChangeCount=permanent.getZoneChangeCounter(game);
      long turnNum=game.getTurnNum();
      Long activationState=zoneChangeCount << 32 | turnNum & 0xFFFFFFFFL;
      if (activationState.equals(turnIgnoringPlayersPair.getKey())) {
        applies=!turnIgnoringPlayersPair.getValue().contains(event.getPlayerId());
      }
    }
  }
  return applies;
}

Fixed version (ground truth):
@Override public boolean applies(GameEvent event,Ability source,Game game){
  Permanent permanent=game.getPermanent(source.getSourceId());
  if (permanent != null) {
    boolean applies=true;
    String key=permanent.getId() + keyString;
    Map.Entry<Long,Set<UUID>> turnIgnoringPlayersPair=(Map.Entry<Long,Set<UUID>>)game.getState().getValue(key);
    if (turnIgnoringPlayersPair != null) {
      long zoneChangeCount=permanent.getZoneChangeCounter(game);
      long turnNum=game.getTurnNum();
      Long activationState=zoneChangeCount << 32 | turnNum & 0xFFFFFFFFL;
      if (activationState.equals(turnIgnoringPlayersPair.getKey())) {
        applies=!turnIgnoringPlayersPair.getValue().contains(event.getPlayerId());
      }
    }
    return applies;
  }
  return false;
}
Program: 158957
Project: 158957
Buggy source:
@Override public boolean apply(Game game,Ability source){
  MageObject mageObject=game.getObject(source.getSourceId());
  if (mageObject == null) {
    if (duration.equals(Duration.Custom)) {
      discard();
    }
    return false;
  }
  if (amount != null) {
    int value=amount.calculate(game,source,this);
    mageObject.getPower().setValue(value);
    mageObject.getToughness().setValue(value);
    return true;
  }
 else {
    if (power != Integer.MIN_VALUE) {
      mageObject.getPower().setValue(power);
    }
    if (toughness != Integer.MIN_VALUE) {
      mageObject.getToughness().setValue(toughness);
    }
  }
  return true;
}

Fixed version (ground truth):
@Override public boolean apply(Game game,Ability source){
  MageObject mageObject;
  if (source.getZone() == Zone.BATTLEFIELD) {
    mageObject=source.getSourceObjectIfItStillExists(game);
  }
 else {
    mageObject=game.getObject(source.getSourceId());
  }
  if (mageObject == null) {
    if (duration.equals(Duration.Custom)) {
      discard();
    }
    return false;
  }
  if (amount != null) {
    int value=amount.calculate(game,source,this);
    mageObject.getPower().setValue(value);
    mageObject.getToughness().setValue(value);
    return true;
  }
 else {
    if (power != Integer.MIN_VALUE) {
      mageObject.getPower().setValue(power);
    }
    if (toughness != Integer.MIN_VALUE) {
      mageObject.getToughness().setValue(toughness);
    }
  }
  return true;
}
Program: 158959
Project: 158959
Buggy source:
public CavernOfSoulsWatcher(final CavernOfSoulsWatcher watcher){
  super(watcher);
  this.spells.addAll(watcher.spells);
}

Fixed version (ground truth):
public CavernOfSoulsWatcher(final CavernOfSoulsWatcher watcher){
  super(watcher);
  this.spells.addAll(watcher.spells);
  this.originalId=watcher.originalId;
}
Program: 158960
Project: 158960
Buggy source:
@Override public boolean applies(GameEvent event,Ability source,Game game){
  CavernOfSoulsWatcher watcher=(CavernOfSoulsWatcher)game.getState().getWatchers().get("String_Node_Str");
  Spell spell=game.getStack().getSpell(event.getTargetId());
  return spell != null && watcher.spells.contains(spell.getId());
}

Fixed version (ground truth):
@Override public boolean applies(GameEvent event,Ability source,Game game){
  CavernOfSoulsWatcher watcher=(CavernOfSoulsWatcher)game.getState().getWatchers().get("String_Node_Str",source.getSourceId());
  Spell spell=game.getStack().getSpell(event.getTargetId());
  return spell != null && watcher != null && watcher.spellCantBeCountered(spell.getId());
}
Program: 158961
Project: 158961
Buggy source:
@Override public ConditionalMana build(Object... options){
  this.mana.setFlag(true);
  return new CavernOfSoulsConditionalMana(this.mana,creatureType);
}

Fixed version (ground truth):
@Override public ConditionalMana build(Object... options){
  return new CavernOfSoulsConditionalMana(this.mana,creatureType);
}
Program: 158962
Project: 158962
Buggy source:
@Override public void watch(GameEvent event,Game game){
  if (event.getType() == GameEvent.EventType.MANA_PAYED) {
    MageObject object=game.getObject(event.getSourceId());
    if (object != null && object.getName().equals("String_Node_Str") && event.getFlag()) {
      spells.add(event.getTargetId());
    }
  }
}

Fixed version (ground truth):
@Override public void watch(GameEvent event,Game game){
  if (event.getType() == GameEvent.EventType.MANA_PAYED) {
    if (event.getData() != null && event.getData().equals(originalId)) {
      spells.add(event.getTargetId());
    }
  }
}
Program: 158963
Project: 158963
Buggy source:
public ConditionalMana(ConditionalMana conditionalMana){
  super(conditionalMana);
  conditions=conditionalMana.conditions;
  scope=conditionalMana.scope;
  staticText=conditionalMana.staticText;
  manaProducerId=conditionalMana.manaProducerId;
}

Fixed version (ground truth):
public ConditionalMana(final ConditionalMana conditionalMana){
  super(conditionalMana);
  conditions=conditionalMana.conditions;
  scope=conditionalMana.scope;
  staticText=conditionalMana.staticText;
  manaProducerId=conditionalMana.manaProducerId;
  manaProducerOriginalId=conditionalMana.manaProducerOriginalId;
}
Program: 158964
Project: 158964
Buggy source:
private void removeConditional(ManaType manaType,Ability ability,Game game){
  for (  ConditionalMana mana : getConditionalMana()) {
    if (mana.get(manaType) > 0 && mana.apply(ability,game,mana.getManaProducerId())) {
      mana.set(manaType,mana.get(manaType) - 1);
      game.fireEvent(new GameEvent(GameEvent.EventType.MANA_PAYED,ability.getId(),mana.getManaProducerId(),ability.getControllerId(),0,mana.getFlag()));
      break;
    }
  }
}

Fixed version (ground truth):
private void removeConditional(ManaType manaType,Ability ability,Game game){
  for (  ConditionalMana mana : getConditionalMana()) {
    if (mana.get(manaType) > 0 && mana.apply(ability,game,mana.getManaProducerId())) {
      mana.set(manaType,mana.get(manaType) - 1);
      GameEvent event=new GameEvent(GameEvent.EventType.MANA_PAYED,ability.getId(),mana.getManaProducerId(),ability.getControllerId(),0,mana.getFlag());
      event.setData(mana.getManaProducerOriginalId().toString());
      game.fireEvent(event);
      break;
    }
  }
}
Program: 158965
Project: 158965
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(),source.getControllerId(),mana))) {
    if (mana instanceof ConditionalMana) {
      ManaPoolItem item=new ManaPoolItem((ConditionalMana)mana,source.getSourceId());
      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.getColorless(),source.getSourceId(),mana.getFlag());
      if (emptyOnTurnsEnd) {
        item.setDuration(Duration.EndOfTurn);
      }
      this.manaItems.add(item);
    }
    GameEvent event=GameEvent.getEvent(GameEvent.EventType.MANA_ADDED,source.getId(),source.getSourceId(),source.getControllerId());
    event.setData(mana.toString());
    game.fireEvent(event);
  }
}

Fixed version (ground truth):
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(),source.getControllerId(),mana))) {
    if (mana instanceof ConditionalMana) {
      ManaPoolItem item=new ManaPoolItem((ConditionalMana)mana,source.getSourceId(),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.getColorless(),source.getSourceId(),source.getOriginalId(),mana.getFlag());
      if (emptyOnTurnsEnd) {
        item.setDuration(Duration.EndOfTurn);
      }
      this.manaItems.add(item);
    }
    GameEvent event=GameEvent.getEvent(GameEvent.EventType.MANA_ADDED,source.getId(),source.getSourceId(),source.getControllerId());
    event.setData(mana.toString());
    game.fireEvent(event);
  }
}