nus-yam/ex-repair huggingface dataset:
Program: 159336
Project: 159336
Buggy source:
@Override public boolean apply(Game game,Ability source){
  Permanent copyFromPermanent=null;
  for (  Effect effect : game.getState().getContinuousEffects().getLayeredEffects(game)) {
    if (effect instanceof CopyEffect) {
      CopyEffect copyEffect=(CopyEffect)effect;
      if (copyEffect.getSourceId().equals(source.getSourceId())) {
        MageObject object=((CopyEffect)effect).getTarget();
        if (object instanceof Permanent) {
          copyFromPermanent=(Permanent)object;
        }
      }
    }
  }
  if (copyFromPermanent != null) {
    EmptyToken token=new EmptyToken();
    token.putOntoBattlefield(1,game,source.getSourceId(),source.getControllerId());
    Permanent sourcePermanent=game.getPermanent(token.getLastAddedToken());
    if (sourcePermanent != null) {
      game.copyPermanent(copyFromPermanent,sourcePermanent,source,new ProgenitorMimicApplyToPermanent());
      return true;
    }
  }
  return false;
}

Fixed version (ground truth):
@Override public boolean apply(Game game,Ability source){
  Permanent copyFromPermanent=null;
  for (  Effect effect : game.getState().getContinuousEffects().getLayeredEffects(game)) {
    if (effect instanceof CopyEffect) {
      CopyEffect copyEffect=(CopyEffect)effect;
      if (copyEffect.getSourceId().equals(source.getSourceId())) {
        MageObject object=((CopyEffect)effect).getTarget();
        if (object instanceof Permanent) {
          copyFromPermanent=(Permanent)object;
        }
      }
    }
  }
  if (copyFromPermanent != null) {
    EmptyToken token=new EmptyToken();
    CardUtil.copyTo(token).from(copyFromPermanent);
    token.putOntoBattlefield(1,game,source.getSourceId(),source.getControllerId());
    Permanent sourcePermanent=game.getPermanent(token.getLastAddedToken());
    if (sourcePermanent != null) {
      game.copyPermanent(copyFromPermanent,sourcePermanent,source,new ProgenitorMimicApplyToPermanent());
      return true;
    }
  }
  return false;
}
Program: 159337
Project: 159337
Buggy source:
/** 
 * Returns function that copies params\abilities from one card to   {@link Token}.
 * @param target
 */
public static CopyTokenFunction copyTo(Token target){
  return new CopyTokenFunction(target);
}

Fixed version (ground truth):
/** 
 * Returns function that copies params\abilities from one card to   {@link Token}.
 * @param target
 * @return
 */
public static CopyTokenFunction copyTo(Token target){
  return new CopyTokenFunction(target);
}
Program: 159338
Project: 159338
Buggy source:
@Override public boolean apply(Game game,Ability source){
  Player controller=game.getPlayer(source.getControllerId());
  if (controller != null) {
    MageObject target=game.getObject(source.getSourceId());
    if (target != null) {
      ArrayList<CardType> foundCardTypes=new ArrayList<>();
      for (      UUID playerId : controller.getInRange()) {
        Player player=game.getPlayer(playerId);
        if (player != null) {
          for (          Card card : player.getGraveyard().getCards(game)) {
            foundCardTypes.addAll(card.getCardType());
          }
        }
      }
      int number=foundCardTypes.size();
      target.getPower().setValue(number);
      target.getToughness().setValue(number + 1);
      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) {
    MageObject target=game.getObject(source.getSourceId());
    if (target != null) {
      HashSet<CardType> foundCardTypes=new HashSet<>();
      for (      UUID playerId : controller.getInRange()) {
        Player player=game.getPlayer(playerId);
        if (player != null) {
          for (          Card card : player.getGraveyard().getCards(game)) {
            foundCardTypes.addAll(card.getCardType());
          }
        }
      }
      int number=foundCardTypes.size();
      target.getPower().setValue(number);
      target.getToughness().setValue(number + 1);
      return true;
    }
  }
  return false;
}
Program: 159340
Project: 159340
Buggy source:
@Override public void setResponseManaType(UUID playerId,ManaType manaType){
synchronized (response) {
    response.setManaType(manaType);
    response.setResponseManaTypePlayerId(playerId);
    response.notify();
    log.debug("String_Node_Str" + getId());
  }
}

Fixed version (ground truth):
@Override public void setResponseManaType(UUID manaTypePlayerId,ManaType manaType){
synchronized (response) {
    response.setManaType(manaType);
    response.setResponseManaTypePlayerId(manaTypePlayerId);
    response.notify();
    log.debug("String_Node_Str" + getId());
  }
}
Program: 159341
Project: 159341
Buggy source:
public void sendPlayerManaType(UUID userId,UUID playerId,final ManaType data){
  sendMessage(userId,new Command(){
    @Override public void execute(    UUID playerId){
      getGameSession(playerId).sendPlayerManaType(data,playerId);
    }
  }
);
}

Fixed version (ground truth):
public void sendPlayerManaType(UUID userId,final UUID manaTypePlayerId,final ManaType data){
  sendMessage(userId,new Command(){
    @Override public void execute(    UUID playerId){
      getGameSession(playerId).sendPlayerManaType(data,manaTypePlayerId);
    }
  }
);
}
Program: 159342
Project: 159342
Buggy source:
public void sendPlayerManaType(ManaType manaType,UUID playerId){
  cancelTimeout();
  game.getPlayer(playerId).setResponseManaType(playerId,manaType);
}

Fixed version (ground truth):
public void sendPlayerManaType(ManaType manaType,UUID manaTypePlayerId){
  cancelTimeout();
  game.getPlayer(playerId).setResponseManaType(manaTypePlayerId,manaType);
}
Program: 159343
Project: 159343
Buggy source:
void setResponseManaType(UUID playerId,ManaType responseManaType);

Fixed version (ground truth):
void setResponseManaType(UUID manaTypePlayerId,ManaType responseManaType);
Program: 159344
Project: 159344
Buggy source:
@Override public void setResponseManaType(UUID playerId,ManaType responseManaType){
}

Fixed version (ground truth):
@Override public void setResponseManaType(UUID manaTypePlayerId,ManaType responseManaType){
}
Program: 159345
Project: 159345
Buggy source:
@Override public boolean applies(GameEvent event,Ability source,Game game){
  if (!this.used && super.applies(event,source,game)) {
    MageObject object=game.getObject(event.getSourceId());
    if (object == null) {
      game.informPlayers("String_Node_Str");
      return false;
    }
    if (!object.getId().equals(source.getFirstTarget())) {
      return false;
    }
    Permanent permanent=game.getPermanent(event.getTargetId());
    if (permanent != null) {
      if (permanent.getControllerId().equals(source.getControllerId())) {
        return true;
      }
    }
    Player player=game.getPlayer(event.getTargetId());
    if (player != null) {
      if (player.getId().equals(source.getControllerId())) {
        return true;
      }
    }
  }
  return false;
}

Fixed version (ground truth):
@Override public boolean applies(GameEvent event,Ability source,Game game){
  if (!this.used && super.applies(event,source,game)) {
    MageObject object=game.getObject(event.getSourceId());
    if (object == null) {
      game.informPlayers("String_Node_Str");
      return false;
    }
    if (!object.getId().equals(source.getFirstTarget()) && (!(object instanceof Spell) || !((Spell)object).getSourceId().equals(source.getFirstTarget()))) {
      return false;
    }
    Permanent permanent=game.getPermanent(event.getTargetId());
    if (permanent != null) {
      if (permanent.getControllerId().equals(source.getControllerId())) {
        return true;
      }
    }
    Player player=game.getPlayer(event.getTargetId());
    if (player != null) {
      if (player.getId().equals(source.getControllerId())) {
        return true;
      }
    }
  }
  return false;
}
Program: 159346
Project: 159346
Buggy source:
@Override public boolean replaceEvent(GameEvent event,Ability source,Game game){
  GameEvent preventEvent=new GameEvent(GameEvent.EventType.PREVENT_DAMAGE,source.getFirstTarget(),source.getId(),source.getControllerId(),event.getAmount(),false);
  if (!game.replaceEvent(preventEvent)) {
    int prevented=0;
    if (event.getAmount() >= this.amount) {
      int damage=amount;
      event.setAmount(event.getAmount() - amount);
      this.used=true;
      game.fireEvent(GameEvent.getEvent(GameEvent.EventType.PREVENTED_DAMAGE,source.getFirstTarget(),source.getId(),source.getControllerId(),damage));
      prevented=damage;
    }
 else {
      int damage=event.getAmount();
      event.setAmount(0);
      amount-=damage;
      game.fireEvent(GameEvent.getEvent(GameEvent.EventType.PREVENTED_DAMAGE,source.getFirstTarget(),source.getId(),source.getControllerId(),damage));
      prevented=damage;
    }
    if (prevented > 0) {
      UUID redirectTo=source.getTargets().get(1).getFirstTarget();
      Permanent permanent=game.getPermanent(redirectTo);
      if (permanent != null) {
        game.informPlayers("String_Node_Str" + prevented + "String_Node_Str"+ permanent.getName()+ "String_Node_Str");
        permanent.damage(prevented,event.getSourceId(),game,true,false);
      }
      Player player=game.getPlayer(redirectTo);
      if (player != null) {
        game.informPlayers("String_Node_Str" + prevented + "String_Node_Str"+ player.getName()+ "String_Node_Str");
        player.damage(prevented,event.getSourceId(),game,true,false);
      }
    }
  }
  return false;
}

Fixed version (ground truth):
@Override public boolean replaceEvent(GameEvent event,Ability source,Game game){
  PreventionEffectData preventionData=preventDamageAction(event,source,game);
  if (preventionData.getPreventedDamage() > 0) {
    UUID redirectTo=source.getTargets().get(1).getFirstTarget();
    Permanent permanent=game.getPermanent(redirectTo);
    if (permanent != null) {
      game.informPlayers("String_Node_Str" + preventionData.getPreventedDamage() + "String_Node_Str"+ permanent.getName()+ "String_Node_Str");
      permanent.damage(preventionData.getPreventedDamage(),event.getSourceId(),game,true,false);
    }
    Player player=game.getPlayer(redirectTo);
    if (player != null) {
      game.informPlayers("String_Node_Str" + preventionData.getPreventedDamage() + "String_Node_Str"+ player.getName()+ "String_Node_Str");
      player.damage(preventionData.getPreventedDamage(),event.getSourceId(),game,false,true);
    }
  }
  return false;
}
Program: 159347
Project: 159347
Buggy source:
public HarmsWayPreventDamageTargetEffect(final HarmsWayPreventDamageTargetEffect effect){
  super(effect);
  this.amount=effect.amount;
}

Fixed version (ground truth):
public HarmsWayPreventDamageTargetEffect(final HarmsWayPreventDamageTargetEffect effect){
  super(effect);
}
Program: 159348
Project: 159348
Buggy source:
/** 
 * Tests redirecting from triggered ability
 */
@Test @Ignore public void testRedirectTriggeredAbilityDamage(){
  addCard(Zone.HAND,playerA,"String_Node_Str");
  addCard(Zone.HAND,playerA,"String_Node_Str");
  addCard(Zone.BATTLEFIELD,playerA,"String_Node_Str");
  addCard(Zone.BATTLEFIELD,playerA,"String_Node_Str");
  addCard(Zone.BATTLEFIELD,playerB,"String_Node_Str");
  castSpell(1,PhaseStep.PRECOMBAT_MAIN,playerA,"String_Node_Str","String_Node_Str");
  castSpell(1,PhaseStep.PRECOMBAT_MAIN,playerA,"String_Node_Str","String_Node_Str");
  setStopAt(1,PhaseStep.BEGIN_COMBAT);
  execute();
  assertLife(playerA,19);
  assertLife(playerB,15);
}

Fixed version (ground truth):
/** 
 * Tests redirecting from triggered ability
 */
@Test public void testRedirectTriggeredAbilityDamage(){
  addCard(Zone.HAND,playerA,"String_Node_Str");
  addCard(Zone.HAND,playerA,"String_Node_Str");
  addCard(Zone.BATTLEFIELD,playerA,"String_Node_Str");
  addCard(Zone.BATTLEFIELD,playerA,"String_Node_Str");
  addCard(Zone.BATTLEFIELD,playerB,"String_Node_Str");
  castSpell(1,PhaseStep.PRECOMBAT_MAIN,playerA,"String_Node_Str","String_Node_Str");
  castSpell(1,PhaseStep.POSTCOMBAT_MAIN,playerA,"String_Node_Str","String_Node_Str");
  setStopAt(1,PhaseStep.POSTCOMBAT_MAIN);
  execute();
  assertLife(playerA,19);
  assertLife(playerB,15);
}
Program: 159349
Project: 159349
Buggy source:
private Set<CardType> getOpponentPermanentCardTypes(UUID sourceId,UUID sourceControllerId,Game game){
  Player controller=game.getPlayer(sourceControllerId);
  Set<CardType> cardTypes=new HashSet<>();
  if (controller != null) {
    for (    Permanent permanent : game.getBattlefield().getActivePermanents(sourceId,game)) {
      if (controller.hasOpponent(permanent.getControllerId(),game)) {
        cardTypes.addAll(permanent.getCardType());
      }
    }
  }
  return cardTypes;
}

Fixed version (ground truth):
private Set<CardType> getOpponentPermanentCardTypes(UUID sourceId,UUID sourceControllerId,Game game){
  Player controller=game.getPlayer(sourceControllerId);
  Set<CardType> cardTypes=new HashSet<>();
  if (controller != null) {
    for (    Permanent permanent : game.getBattlefield().getActivePermanents(sourceControllerId,game)) {
      if (controller.hasOpponent(permanent.getControllerId(),game)) {
        cardTypes.addAll(permanent.getCardType());
      }
    }
  }
  return cardTypes;
}
Program: 159350
Project: 159350
Buggy source:
@Override public AsceticismEffect copy(){
  return new AsceticismEffect(this);
}

Fixed version (ground truth):
@Override public Asceticism copy(){
  return new Asceticism(this);
}
Program: 159351
Project: 159351
Buggy source:
/** 
 * Tests copying already transformed creature Makes sure it still has "When this creature becomes the target of a spell or ability, sacrifice it"
 */
@Test public void testCopyAlreadyTransformed(){
  addCard(Zone.BATTLEFIELD,playerA,"String_Node_Str",5);
  addCard(Zone.BATTLEFIELD,playerB,"String_Node_Str",2);
  addCard(Zone.BATTLEFIELD,playerB,"String_Node_Str",2);
  addCard(Zone.HAND,playerB,"String_Node_Str");
  addCard(Zone.HAND,playerB,"String_Node_Str");
  addCard(Zone.HAND,playerA,"String_Node_Str");
  addCard(Zone.BATTLEFIELD,playerA,"String_Node_Str");
  castSpell(2,PhaseStep.PRECOMBAT_MAIN,playerB,"String_Node_Str");
  castSpell(3,PhaseStep.PRECOMBAT_MAIN,playerA,"String_Node_Str");
  castSpell(3,PhaseStep.POSTCOMBAT_MAIN,playerB,"String_Node_Str","String_Node_Str");
  setStopAt(3,PhaseStep.END_TURN);
  execute();
  assertLife(playerB,18);
  assertPowerToughness(playerA,"String_Node_Str",4,4);
  assertPermanentCount(playerB,"String_Node_Str",0);
  assertGraveyardCount(playerB,"String_Node_Str",1);
}

Fixed version (ground truth):
/** 
 * Tests copying already transformed creature Makes sure it still has "When this creature becomes the target of a spell or ability, sacrifice it"
 */
@Test public void testCopyAlreadyTransformed(){
  addCard(Zone.BATTLEFIELD,playerA,"String_Node_Str",5);
  addCard(Zone.BATTLEFIELD,playerB,"String_Node_Str",2);
  addCard(Zone.BATTLEFIELD,playerB,"String_Node_Str",2);
  addCard(Zone.HAND,playerB,"String_Node_Str");
  addCard(Zone.HAND,playerB,"String_Node_Str");
  addCard(Zone.HAND,playerA,"String_Node_Str");
  addCard(Zone.BATTLEFIELD,playerA,"String_Node_Str");
  castSpell(2,PhaseStep.PRECOMBAT_MAIN,playerB,"String_Node_Str");
  castSpell(3,PhaseStep.PRECOMBAT_MAIN,playerA,"String_Node_Str");
  castSpell(3,PhaseStep.POSTCOMBAT_MAIN,playerB,"String_Node_Str","String_Node_Str");
  setStopAt(3,PhaseStep.END_TURN);
  execute();
  assertLife(playerB,18);
  assertPowerToughness(playerA,"String_Node_Str",4,4);
  assertGraveyardCount(playerB,"String_Node_Str",1);
  assertGraveyardCount(playerB,"String_Node_Str",1);
  assertPermanentCount(playerB,"String_Node_Str",0);
}
Program: 159352
Project: 159352
Buggy source:
@Override public boolean apply(Game game,Ability source){
  int affectedTargets=0;
  for (  UUID permanentId : targetPointer.getTargets(game,source)) {
    Permanent target=(Permanent)game.getPermanent(permanentId);
    if (target != null) {
      target.addPower(power.calculate(game,source));
      target.addToughness(toughness.calculate(game,source));
      affectedTargets++;
    }
  }
  return affectedTargets > 0;
}

Fixed version (ground truth):
@Override public boolean apply(Game game,Ability source){
  int affectedTargets=0;
  for (  UUID permanentId : targetPointer.getTargets(game,source)) {
    Permanent target=game.getPermanent(permanentId);
    if (target != null) {
      target.addPower(power.calculate(game,source));
      target.addToughness(toughness.calculate(game,source));
      affectedTargets++;
    }
  }
  return affectedTargets > 0;
}
Program: 159353
Project: 159353
Buggy source:
@Override public void init(Ability source,Game game){
  super.init(source,game);
  for (  Permanent perm : game.getBattlefield().getActivePermanents(filter,source.getControllerId(),source.getSourceId(),game)) {
    objects.add(perm.getId());
  }
  if (lockedInPT) {
    power=new StaticValue(power.calculate(game,source));
    toughness=new StaticValue(toughness.calculate(game,source));
  }
}

Fixed version (ground truth):
@Override public void init(Ability source,Game game){
  super.init(source,game);
  if (affectedObjectsSet) {
    for (    Permanent perm : game.getBattlefield().getActivePermanents(filter,source.getControllerId(),source.getSourceId(),game)) {
      objects.add(perm.getId());
    }
  }
  if (lockedInPT) {
    power=new StaticValue(power.calculate(game,source));
    toughness=new StaticValue(toughness.calculate(game,source));
  }
}
Program: 159354
Project: 159354
Buggy source:
@Override public boolean apply(Game game,Ability source){
  int newPower=power.calculate(game,source);
  int newToughness=toughness.calculate(game,source);
  for (  Permanent permanent : game.getBattlefield().getActivePermanents(filter,source.getControllerId(),source.getSourceId(),game)) {
    if (objects.contains(permanent.getId())) {
      permanent.getPower().setValue(newPower);
      permanent.getToughness().setValue(newToughness);
    }
  }
  return true;
}

Fixed version (ground truth):
@Override public boolean apply(Game game,Ability source){
  int newPower=power.calculate(game,source);
  int newToughness=toughness.calculate(game,source);
  if (affectedObjectsSet) {
    for (    UUID permanentId : objects) {
      Permanent permanent=game.getPermanent(permanentId);
      if (permanent != null) {
        permanent.getPower().setValue(newPower);
        permanent.getToughness().setValue(newToughness);
      }
    }
  }
 else {
    for (    Permanent permanent : game.getBattlefield().getActivePermanents(filter,source.getControllerId(),source.getSourceId(),game)) {
      permanent.getPower().setValue(newPower);
      permanent.getToughness().setValue(newToughness);
    }
  }
  return true;
}
Program: 159355
Project: 159355
Buggy source:
public CopyEffect(final CopyEffect effect){
  super(effect);
  this.target=effect.target.copy();
  this.sourceId=effect.sourceId;
}

Fixed version (ground truth):
public CopyEffect(final CopyEffect effect){
  super(effect);
  this.target=effect.target.copy();
  this.sourceId=effect.sourceId;
  this.zoneChangeCounter=effect.zoneChangeCounter;
}
Program: 159356
Project: 159356
Buggy source:
@Override public boolean isInactive(Ability source,Game game){
  Permanent permanent=game.getPermanent(this.sourceId);
  if (permanent == null) {
    return true;
  }
  return false;
}

Fixed version (ground truth):
@Override public boolean isInactive(Ability source,Game game){
  Permanent permanent=game.getPermanent(this.sourceId);
  return permanent == null || permanent.getZoneChangeCounter() != this.zoneChangeCounter;
}
Program: 159357
Project: 159357
Buggy source:
@Override public boolean moveToExile(UUID exileId,String name,UUID sourceId,Game game,ArrayList<UUID> appliedEffects){
  Zone fromZone=game.getState().getZone(objectId);
  ZoneChangeEvent event=new ZoneChangeEvent(this.objectId,sourceId,ownerId,fromZone,Zone.EXILED,appliedEffects);
  if (!game.replaceEvent(event)) {
    if (fromZone != null) {
switch (fromZone) {
case GRAVEYARD:
        game.getPlayer(ownerId).removeFromGraveyard(this,game);
      break;
case HAND:
    game.getPlayer(ownerId).removeFromHand(this,game);
  break;
case LIBRARY:
game.getPlayer(ownerId).removeFromLibrary(this,game);
break;
case EXILED:
game.getExile().removeCard(this,game);
break;
case STACK:
case PICK:
break;
default :
MageObject object=game.getObject(sourceId);
logger.warn(new StringBuilder("String_Node_Str").append(fromZone).append("String_Node_Str").append(object != null ? object.getName() : "String_Node_Str"));
}
game.rememberLKI(objectId,event.getFromZone(),this);
}
if (exileId == null) {
game.getExile().getPermanentExile().add(this);
}
 else {
game.getExile().createZone(exileId,name).add(this);
}
updateZoneChangeCounter();
game.setZone(objectId,event.getToZone());
game.fireEvent(event);
return true;
}
return false;
}

Fixed version (ground truth):
@Override public boolean moveToExile(UUID exileId,String name,UUID sourceId,Game game,ArrayList<UUID> appliedEffects){
  Zone fromZone=game.getState().getZone(objectId);
  ZoneChangeEvent event=new ZoneChangeEvent(this.objectId,sourceId,ownerId,fromZone,Zone.EXILED,appliedEffects);
  if (!game.replaceEvent(event)) {
    if (fromZone != null) {
switch (fromZone) {
case GRAVEYARD:
        game.getPlayer(ownerId).removeFromGraveyard(this,game);
      break;
case HAND:
    game.getPlayer(ownerId).removeFromHand(this,game);
  break;
case LIBRARY:
game.getPlayer(ownerId).removeFromLibrary(this,game);
break;
case EXILED:
game.getExile().removeCard(this,game);
break;
case STACK:
case PICK:
break;
default :
MageObject object=game.getObject(sourceId);
logger.warn(new StringBuilder("String_Node_Str").append(fromZone).append("String_Node_Str").append(object != null ? object.getName() : "String_Node_Str"));
}
game.rememberLKI(objectId,event.getFromZone(),this);
}
if (exileId == null) {
game.getExile().getPermanentExile().add(this);
}
 else {
game.getExile().createZone(exileId,name).add(this);
}
updateZoneChangeCounter();
game.setZone(objectId,event.getToZone());
game.addSimultaneousEvent(event);
return true;
}
return false;
}
Program: 159358
Project: 159358
Buggy source:
@Override public void addInfo(String key,String value){
  if (info == null) {
    info=new HashMap<String,String>();
  }
  info.put(key,value);
}

Fixed version (ground truth):
@Override public void addInfo(String key,String value){
  if (info == null) {
    info=new HashMap<>();
  }
  info.put(key,value);
}
Program: 159359
Project: 159359
Buggy source:
@Override public boolean moveToExile(UUID exileId,String name,UUID sourceId,Game game,ArrayList<UUID> appliedEffects){
  Zone fromZone=game.getState().getZone(objectId);
  Player controller=game.getPlayer(controllerId);
  if (controller != null && controller.removeFromBattlefield(this,game)) {
    ZoneChangeEvent event=new ZoneChangeEvent(this,sourceId,ownerId,fromZone,Zone.EXILED,appliedEffects);
    if (!game.replaceEvent(event)) {
      game.rememberLKI(objectId,Zone.BATTLEFIELD,this);
      if (exileId == null) {
        game.getExile().getPermanentExile().add(card);
      }
 else {
        game.getExile().createZone(exileId,name).add(card);
      }
      game.setZone(objectId,event.getToZone());
      game.fireEvent(event);
      if (event.getFromZone().equals(Zone.BATTLEFIELD)) {
        game.resetForSourceId(getId());
        game.applyEffects();
      }
      return true;
    }
  }
  return false;
}

Fixed version (ground truth):
@Override public boolean moveToExile(UUID exileId,String name,UUID sourceId,Game game,ArrayList<UUID> appliedEffects){
  Zone fromZone=game.getState().getZone(objectId);
  Player controller=game.getPlayer(controllerId);
  if (controller != null && controller.removeFromBattlefield(this,game)) {
    ZoneChangeEvent event=new ZoneChangeEvent(this,sourceId,ownerId,fromZone,Zone.EXILED,appliedEffects);
    if (!game.replaceEvent(event)) {
      game.rememberLKI(objectId,Zone.BATTLEFIELD,this);
      if (exileId == null) {
        game.getExile().getPermanentExile().add(card);
      }
 else {
        game.getExile().createZone(exileId,name).add(card);
      }
      game.setZone(objectId,event.getToZone());
      game.addSimultaneousEvent(event);
      return true;
    }
  }
  return false;
}
Program: 159360
Project: 159360
Buggy source:
protected void copyFromCard(Card card){
  this.name=card.getName();
  this.abilities.clear();
  this.abilities.addAll(card.getAbilities());
  this.abilities.setControllerId(this.controllerId);
  this.watchers.addAll(card.getWatchers());
  this.cardType.clear();
  this.cardType.addAll(card.getCardType());
  this.color=card.getColor().copy();
  this.manaCost=card.getManaCost().copy();
  this.power=card.getPower().copy();
  this.toughness=card.getToughness().copy();
  if (card instanceof PermanentCard) {
    this.maxLevelCounters=((PermanentCard)card).maxLevelCounters;
  }
  this.subtype.clear();
  this.subtype.addAll(card.getSubtype());
  this.supertype.clear();
  this.supertype.addAll(card.getSupertype());
  this.expansionSetCode=card.getExpansionSetCode();
  this.rarity=card.getRarity();
  this.cardNumber=card.getCardNumber();
  this.usesVariousArt=card.getUsesVariousArt();
  canTransform=card.canTransform();
  if (canTransform) {
    secondSideCard=card.getSecondCardFace();
    nightCard=card.isNightCard();
  }
  this.flipCard=card.isFlipCard();
  this.flipCardName=card.getFlipCardName();
}

Fixed version (ground truth):
protected void copyFromCard(Card card){
  this.name=card.getName();
  this.abilities.clear();
  this.abilities.addAll(card.getAbilities());
  this.abilities.setControllerId(this.controllerId);
  this.watchers.addAll(card.getWatchers());
  this.cardType.clear();
  this.cardType.addAll(card.getCardType());
  this.color=card.getColor().copy();
  this.manaCost=card.getManaCost().copy();
  this.power=card.getPower().copy();
  this.toughness=card.getToughness().copy();
  if (card instanceof PermanentCard) {
    this.maxLevelCounters=((PermanentCard)card).maxLevelCounters;
  }
  this.subtype.clear();
  this.subtype.addAll(card.getSubtype());
  this.supertype.clear();
  this.supertype.addAll(card.getSupertype());
  this.expansionSetCode=card.getExpansionSetCode();
  this.rarity=card.getRarity();
  this.cardNumber=card.getCardNumber();
  this.usesVariousArt=card.getUsesVariousArt();
  this.zoneChangeCounter=card.getZoneChangeCounter();
  canTransform=card.canTransform();
  if (canTransform) {
    secondSideCard=card.getSecondCardFace();
    nightCard=card.isNightCard();
  }
  this.flipCard=card.isFlipCard();
  this.flipCardName=card.getFlipCardName();
}
Program: 159361
Project: 159361
Buggy source:
@Override public boolean moveToZone(Zone toZone,UUID sourceId,Game game,boolean flag,ArrayList<UUID> appliedEffects){
  Zone fromZone=game.getState().getZone(objectId);
  Player controller=game.getPlayer(controllerId);
  if (controller != null && controller.removeFromBattlefield(this,game)) {
    ZoneChangeEvent event=new ZoneChangeEvent(this,sourceId,controllerId,fromZone,toZone,appliedEffects);
    if (!game.replaceEvent(event)) {
      Player owner=game.getPlayer(ownerId);
      game.rememberLKI(objectId,Zone.BATTLEFIELD,this);
      if (owner != null) {
        this.setControllerId(ownerId);
switch (event.getToZone()) {
case GRAVEYARD:
          owner.putInGraveyard(card,game,!flag);
        break;
case HAND:
      owner.getHand().add(card);
    break;
case EXILED:
  game.getExile().getPermanentExile().add(card);
break;
case COMMAND:
game.addCommander(new Commander(card));
break;
case LIBRARY:
if (flag) {
owner.getLibrary().putOnTop(card,game);
}
 else {
owner.getLibrary().putOnBottom(card,game);
}
break;
case BATTLEFIELD:
break;
}
game.setZone(objectId,event.getToZone());
game.addSimultaneousEvent(event);
if (event.getFromZone().equals(Zone.BATTLEFIELD)) {
game.getState().handleSimultaneousEvent(game);
game.resetForSourceId(getId());
game.applyEffects();
}
return game.getState().getZone(objectId) == toZone;
}
}
}
return false;
}

Fixed version (ground truth):
@Override public boolean moveToZone(Zone toZone,UUID sourceId,Game game,boolean flag,ArrayList<UUID> appliedEffects){
  Zone fromZone=game.getState().getZone(objectId);
  Player controller=game.getPlayer(controllerId);
  if (controller != null && controller.removeFromBattlefield(this,game)) {
    ZoneChangeEvent event=new ZoneChangeEvent(this,sourceId,controllerId,fromZone,toZone,appliedEffects);
    if (!game.replaceEvent(event)) {
      Player owner=game.getPlayer(ownerId);
      game.rememberLKI(objectId,Zone.BATTLEFIELD,this);
      if (owner != null) {
        this.setControllerId(ownerId);
switch (event.getToZone()) {
case GRAVEYARD:
          owner.putInGraveyard(card,game,!flag);
        break;
case HAND:
      owner.getHand().add(card);
    break;
case EXILED:
  game.getExile().getPermanentExile().add(card);
break;
case COMMAND:
game.addCommander(new Commander(card));
break;
case LIBRARY:
if (flag) {
owner.getLibrary().putOnTop(card,game);
}
 else {
owner.getLibrary().putOnBottom(card,game);
}
break;
case BATTLEFIELD:
break;
}
game.setZone(objectId,event.getToZone());
game.addSimultaneousEvent(event);
return game.getState().getZone(objectId) == toZone;
}
}
}
return false;
}
Program: 159362
Project: 159362
Buggy source:
protected List<Card> getHandCards(TestPlayer player){
  if (handCards.containsKey(player)) {
    return handCards.get(player);
  }
  List<Card> hand=new ArrayList<Card>();
  handCards.put(player,hand);
  return hand;
}

Fixed version (ground truth):
protected List<Card> getHandCards(TestPlayer player){
  if (handCards.containsKey(player)) {
    return handCards.get(player);
  }
  List<Card> hand=new ArrayList<>();
  handCards.put(player,hand);
  return hand;
}
Program: 159363
Project: 159363
Buggy source:
private static void deleteSavedGames(){
  File directory=new File("String_Node_Str");
  if (!directory.exists())   directory.mkdirs();
  File[] files=directory.listFiles(new FilenameFilter(){
    @Override public boolean accept(    File dir,    String name){
      return name.endsWith("String_Node_Str");
    }
  }
);
  for (  File file : files) {
    file.delete();
  }
}

Fixed version (ground truth):
private static void deleteSavedGames(){
  File directory=new File("String_Node_Str");
  if (!directory.exists()) {
    directory.mkdirs();
  }
  File[] files=directory.listFiles(new FilenameFilter(){
    @Override public boolean accept(    File dir,    String name){
      return name.endsWith("String_Node_Str");
    }
  }
);
  for (  File file : files) {
    file.delete();
  }
}
Program: 159364
Project: 159364
Buggy source:
protected List<Card> getLibraryCards(TestPlayer player){
  if (libraryCards.containsKey(player)) {
    return libraryCards.get(player);
  }
  List<Card> library=new ArrayList<Card>();
  libraryCards.put(player,library);
  return library;
}

Fixed version (ground truth):
protected List<Card> getLibraryCards(TestPlayer player){
  if (libraryCards.containsKey(player)) {
    return libraryCards.get(player);
  }
  List<Card> library=new ArrayList<>();
  libraryCards.put(player,library);
  return library;
}
Program: 159365
Project: 159365
Buggy source:
protected Map<Zone,String> getCommands(TestPlayer player){
  if (commands.containsKey(player)) {
    return commands.get(player);
  }
  Map<Zone,String> command=new HashMap<Zone,String>();
  commands.put(player,command);
  return command;
}

Fixed version (ground truth):
protected Map<Zone,String> getCommands(TestPlayer player){
  if (commands.containsKey(player)) {
    return commands.get(player);
  }
  Map<Zone,String> command=new HashMap<>();
  commands.put(player,command);
  return command;
}
Program: 159366
Project: 159366
Buggy source:
protected void parseScenario(String filename) throws FileNotFoundException {
  parserState=ParserState.INIT;
  File f=new File(filename);
  Scanner scanner=new Scanner(f);
  try {
    while (scanner.hasNextLine()) {
      String line=scanner.nextLine().trim();
      if (line == null || line.isEmpty() || line.startsWith("String_Node_Str"))       continue;
      if (line.startsWith("String_Node_Str")) {
        includeFrom(line);
        continue;
      }
      if (line.startsWith("String_Node_Str")) {
        parserState=ParserState.EXPECTED;
        continue;
      }
      parseLine(line);
    }
  }
  finally {
    scanner.close();
  }
}

Fixed version (ground truth):
protected void parseScenario(String filename) throws FileNotFoundException {
  parserState=ParserState.INIT;
  File f=new File(filename);
  Scanner scanner=new Scanner(f);
  try {
    while (scanner.hasNextLine()) {
      String line=scanner.nextLine().trim();
      if (line == null || line.isEmpty() || line.startsWith("String_Node_Str")) {
        continue;
      }
      if (line.startsWith("String_Node_Str")) {
        includeFrom(line);
        continue;
      }
      if (line.startsWith("String_Node_Str")) {
        parserState=ParserState.EXPECTED;
        continue;
      }
      parseLine(line);
    }
  }
  finally {
    scanner.close();
  }
}
Program: 159367
Project: 159367
Buggy source:
protected List<Card> getGraveCards(TestPlayer player){
  if (graveyardCards.containsKey(player)) {
    return graveyardCards.get(player);
  }
  List<Card> grave=new ArrayList<Card>();
  graveyardCards.put(player,grave);
  return grave;
}

Fixed version (ground truth):
protected List<Card> getGraveCards(TestPlayer player){
  if (graveyardCards.containsKey(player)) {
    return graveyardCards.get(player);
  }
  List<Card> grave=new ArrayList<>();
  graveyardCards.put(player,grave);
  return grave;
}
Program: 159368
Project: 159368
Buggy source:
protected List<PermanentCard> getBattlefieldCards(TestPlayer player){
  if (battlefieldCards.containsKey(player)) {
    return battlefieldCards.get(player);
  }
  List<PermanentCard> battlefield=new ArrayList<PermanentCard>();
  battlefieldCards.put(player,battlefield);
  return battlefield;
}

Fixed version (ground truth):
protected List<PermanentCard> getBattlefieldCards(TestPlayer player){
  if (battlefieldCards.containsKey(player)) {
    return battlefieldCards.get(player);
  }
  List<PermanentCard> battlefield=new ArrayList<>();
  battlefieldCards.put(player,battlefield);
  return battlefield;
}
Program: 159369
Project: 159369
Buggy source:
/** 
 * Define turn number and step to stop the game on.
 * @param turn
 * @param step
 */
@Override public void setStopAt(int turn,PhaseStep step){
  stopOnTurn=turn == -1 ? null : Integer.valueOf(turn);
  stopAtStep=step;
}

Fixed version (ground truth):
/** 
 * Define turn number and step to stop the game on. The game stops after executing the step
 * @param turn
 * @param step
 */
@Override public void setStopAt(int turn,PhaseStep step){
  stopOnTurn=turn == -1 ? null : Integer.valueOf(turn);
  stopAtStep=step;
}
Program: 159370
Project: 159370
Buggy source:
protected void resolve(){
  StackObject top=null;
  try {
    top=state.getStack().peek();
    top.resolve(this);
  }
  finally {
    if (top != null) {
      state.getStack().remove(top);
      state.handleSimultaneousEvent(this);
    }
  }
}

Fixed version (ground truth):
protected void resolve(){
  StackObject top=null;
  try {
    top=state.getStack().peek();
    top.resolve(this);
  }
  finally {
    if (top != null) {
      state.getStack().remove(top);
      while (state.hasSimultaneousEvents()) {
        state.handleSimultaneousEvent(this);
      }
    }
  }
}
Program: 159372
Project: 159372
Buggy source:
public boolean play(Game game,UUID activePlayerId){
  if (game.isPaused() || game.gameOver(null)) {
    return false;
  }
  this.activePlayerId=activePlayerId;
  if (beginPhase(game,activePlayerId)) {
    for (    Step step : steps) {
      if (game.isPaused() || game.gameOver(null)) {
        return false;
      }
      currentStep=step;
      if (!game.isSimulation() && checkStopOnStepOption(game)) {
        return false;
      }
      if (!game.getState().getTurnMods().skipStep(activePlayerId,getStep().getType())) {
        playStep(game);
      }
    }
    if (game.isPaused() || game.gameOver(null)) {
      return false;
    }
    count++;
    endPhase(game,activePlayerId);
    return true;
  }
  return false;
}

Fixed version (ground truth):
public boolean play(Game game,UUID activePlayerId){
  if (game.isPaused() || game.gameOver(null)) {
    return false;
  }
  this.activePlayerId=activePlayerId;
  if (beginPhase(game,activePlayerId)) {
    for (    Step step : steps) {
      if (game.isPaused() || game.gameOver(null)) {
        return false;
      }
      currentStep=step;
      if (!game.getState().getTurnMods().skipStep(activePlayerId,getStep().getType())) {
        playStep(game);
      }
      if (!game.isSimulation() && checkStopOnStepOption(game)) {
        return false;
      }
    }
    if (game.isPaused() || game.gameOver(null)) {
      return false;
    }
    count++;
    endPhase(game,activePlayerId);
    return true;
  }
  return false;
}
Program: 159373
Project: 159373
Buggy source:
public void resumeSelectAttackers(Game game){
  Player player=game.getPlayer(attackerId);
  for (  CombatGroup group : groups) {
    for (    UUID attacker : group.getAttackers()) {
      game.fireEvent(GameEvent.getEvent(GameEvent.EventType.ATTACKER_DECLARED,group.defenderId,attacker,attackerId));
    }
  }
  game.fireEvent(GameEvent.getEvent(GameEvent.EventType.DECLARED_ATTACKERS,attackerId,attackerId));
  game.informPlayers(new StringBuilder(player.getName()).append("String_Node_Str").append(groups.size()).append("String_Node_Str").toString());
}

Fixed version (ground truth):
public void resumeSelectAttackers(Game game){
  Player player=game.getPlayer(attackerId);
  for (  CombatGroup group : groups) {
    for (    UUID attacker : group.getAttackers()) {
      game.fireEvent(GameEvent.getEvent(GameEvent.EventType.ATTACKER_DECLARED,group.defenderId,attacker,attackerId));
    }
  }
  game.fireEvent(GameEvent.getEvent(GameEvent.EventType.DECLARED_ATTACKERS,attackerId,attackerId));
  game.informPlayers(new StringBuilder(player.getName()).append("String_Node_Str").append(groups.size()).append(groups.size() == 1 ? "String_Node_Str" : "String_Node_Str").toString());
}
Program: 159374
Project: 159374
Buggy source:
public PermanentView(Permanent permanent,Card card){
  super(permanent);
  this.rules=permanent.getRules();
  this.tapped=permanent.isTapped();
  this.flipped=permanent.isFlipped();
  this.phasedIn=permanent.isPhasedIn();
  this.faceUp=permanent.isFaceUp();
  this.summoningSickness=permanent.hasSummoningSickness();
  this.damage=permanent.getDamage();
  if (permanent.getAttachments().size() > 0) {
    attachments=new ArrayList<>();
    attachments.addAll(permanent.getAttachments());
  }
  if (isToken()) {
    original=new CardView(((PermanentToken)permanent).getToken());
    original.expansionSetCode=permanent.getExpansionSetCode();
    tokenSetCode=original.getTokenSetCode();
  }
 else {
    if (card != null) {
      original=new CardView(card);
    }
 else {
      original=null;
    }
  }
  this.transformed=permanent.isTransformed();
  this.copy=permanent.isCopy();
  if (!original.getName().equals(this.getName())) {
    if (permanent.isCopy() && permanent.isFlipCard()) {
      this.alternateName=permanent.getFlipCardName();
      this.originalName=this.getName();
    }
 else {
      this.alternateName=original.getName();
      this.originalName=this.getName();
    }
  }
}

Fixed version (ground truth):
public PermanentView(Permanent permanent,Card card){
  super(permanent);
  this.rules=permanent.getRules();
  this.tapped=permanent.isTapped();
  this.flipped=permanent.isFlipped();
  this.phasedIn=permanent.isPhasedIn();
  this.faceUp=permanent.isFaceUp();
  this.summoningSickness=permanent.hasSummoningSickness();
  this.damage=permanent.getDamage();
  if (permanent.getAttachments().size() > 0) {
    attachments=new ArrayList<>();
    attachments.addAll(permanent.getAttachments());
  }
  if (isToken()) {
    original=new CardView(((PermanentToken)permanent).getToken());
    original.expansionSetCode=permanent.getExpansionSetCode();
    tokenSetCode=original.getTokenSetCode();
  }
 else {
    if (card != null) {
      original=new CardView(card);
    }
 else {
      original=null;
    }
  }
  this.transformed=permanent.isTransformed();
  this.copy=permanent.isCopy();
  if (original != null && !original.getName().equals(this.getName())) {
    if (permanent.isCopy() && permanent.isFlipCard()) {
      this.alternateName=permanent.getFlipCardName();
      this.originalName=this.getName();
    }
 else {
      this.alternateName=original.getName();
      this.originalName=this.getName();
    }
  }
}
Program: 159375
Project: 159375
Buggy source:
@Override public boolean apply(Game game,Ability source){
  Player opponent=game.getPlayer(this.getTargetPointer().getFirst(game,source));
  if (opponent != null) {
    FilterCreaturePermanent filter=new FilterCreaturePermanent();
    filter.add(new TappedPredicate());
    filter.add(new ControllerIdPredicate(opponent.getId()));
    return new DrawCardSourceControllerEffect(game.getBattlefield().count(filter,source.getSourceId(),source.getSourceId(),game)).apply(game,source);
  }
  return false;
}

Fixed version (ground truth):
@Override public boolean apply(Game game,Ability source){
  Player opponent=game.getPlayer(this.getTargetPointer().getFirst(game,source));
  if (opponent != null) {
    FilterCreaturePermanent filter=new FilterCreaturePermanent();
    filter.add(new TappedPredicate());
    filter.add(new ControllerIdPredicate(opponent.getId()));
    return new DrawCardSourceControllerEffect(game.getBattlefield().count(filter,source.getSourceId(),source.getControllerId(),game)).apply(game,source);
  }
  return false;
}
Program: 159376
Project: 159376
Buggy source:
@Override public Set<UUID> possibleTargets(UUID sourceControllerId,Game game){
  Set<UUID> possibleTargets=new HashSet<UUID>();
  for (  StackObject stackObject : game.getStack()) {
    Spell spell=game.getStack().getSpell(stackObject.getId());
    if (spell != null && filter.match(spell,null,sourceControllerId,game) && filter.match(spell,game)) {
      possibleTargets.add(spell.getId());
    }
  }
  for (  Permanent permanent : game.getBattlefield().getActivePermanents(new FilterCreaturePermanent(),sourceControllerId,game)) {
    if (filter.match(permanent,null,sourceControllerId,game)) {
      possibleTargets.add(permanent.getId());
    }
  }
  return possibleTargets;
}

Fixed version (ground truth):
@Override public Set<UUID> possibleTargets(UUID sourceControllerId,Game game){
  Set<UUID> possibleTargets=new HashSet<UUID>();
  for (  StackObject stackObject : game.getStack()) {
    Spell spell=game.getStack().getSpell(stackObject.getId());
    if (spell != null && filter.match(spell,null,sourceControllerId,game) && filter.match(spell,game)) {
      possibleTargets.add(spell.getId());
    }
  }
  for (  Permanent permanent : game.getBattlefield().getActivePermanents(filterPermanent,sourceControllerId,game)) {
    if (filter.match(permanent,null,sourceControllerId,game)) {
      possibleTargets.add(permanent.getId());
    }
  }
  return possibleTargets;
}
Program: 159377
Project: 159377
Buggy source:
@Override public boolean checkTrigger(GameEvent event,Game game){
  if (event.getType().equals(GameEvent.EventType.DAMAGED_PLAYER) && event.getTargetId().equals(this.getControllerId())) {
    DamageEvent damageEvent=(DamageEvent)event;
    return damageEvent.isCombatDamage();
  }
  return false;
}

Fixed version (ground truth):
@Override public boolean checkTrigger(GameEvent event,Game game){
  if (event.getType().equals(GameEvent.EventType.DAMAGED_PLAYER) && event.getTargetId().equals(this.getControllerId())) {
    DamagedEvent damagedEvent=(DamagedEvent)event;
    return damagedEvent.isCombatDamage();
  }
  return false;
}
Program: 159378
Project: 159378
Buggy source:
protected PreventionEffectData preventDamageAction(GameEvent event,Ability source,Game game){
  PreventionEffectData preventionData=game.preventDamage(event,source,game,amountToPrevent);
  if (!preventionData.isError() && !preventionData.isReplaced()) {
    if (consumable) {
      amountToPrevent=preventionData.getRemainingAmount();
    }
    if (amountToPrevent == 0) {
      this.used=true;
    }
  }
  return preventionData;
}

Fixed version (ground truth):
protected PreventionEffectData preventDamageAction(GameEvent event,Ability source,Game game){
  PreventionEffectData preventionData=game.preventDamage(event,source,game,amountToPrevent);
  if (!preventionData.isError() && !preventionData.isReplaced()) {
    if (consumable) {
      amountToPrevent=preventionData.getRemainingAmount();
    }
    if (amountToPrevent == 0) {
      this.discard();
    }
  }
  return preventionData;
}
Program: 159379
Project: 159379
Buggy source:
public PreventDamageSourceEffect(final PreventDamageSourceEffect effect){
  super(effect);
  this.amount=effect.amount;
}

Fixed version (ground truth):
public PreventDamageSourceEffect(final PreventDamageSourceEffect effect){
  super(effect);
}
Program: 159380
Project: 159380
Buggy source:
@Override public boolean applies(GameEvent event,Ability source,Game game){
  if (!this.used && super.applies(event,source,game) && event.getTargetId().equals(source.getSourceId())) {
    return true;
  }
  return false;
}

Fixed version (ground truth):
@Override public boolean applies(GameEvent event,Ability source,Game game){
  return super.applies(event,source,game) && event.getTargetId().equals(source.getSourceId());
}
Program: 159381
Project: 159381
Buggy source:
@Override public String getText(Mode mode){
  if (staticText != null && !staticText.isEmpty()) {
    return staticText;
  }
  StringBuilder sb=new StringBuilder();
  if (amount == Integer.MAX_VALUE) {
    sb.append("String_Node_Str");
  }
 else {
    sb.append("String_Node_Str").append(amount).append("String_Node_Str");
  }
  sb.append("String_Node_Str").append(duration.toString());
  return sb.toString();
}

Fixed version (ground truth):
@Override public String getText(Mode mode){
  if (staticText != null && !staticText.isEmpty()) {
    return staticText;
  }
  StringBuilder sb=new StringBuilder();
  if (amountToPrevent == Integer.MAX_VALUE) {
    sb.append("String_Node_Str");
  }
 else {
    sb.append("String_Node_Str").append(amountToPrevent).append("String_Node_Str");
  }
  sb.append("String_Node_Str").append(duration.toString());
  return sb.toString();
}
Program: 159383
Project: 159383
Buggy source:
private String getOptionalTextSuffix(Game game,Spell spell){
  StringBuilder sb=new StringBuilder();
  for (  Ability ability : (Abilities<Ability>)spell.getAbilities()) {
    if (ability instanceof OptionalAdditionalSourceCosts) {
      sb.append(((OptionalAdditionalSourceCosts)ability).getCastMessageSuffix());
    }
    if (ability instanceof AlternativeSourceCosts) {
      sb.append(((AlternativeSourceCosts)ability).getCastMessageSuffix());
    }
  }
  return sb.toString();
}

Fixed version (ground truth):
private String getOptionalTextSuffix(Game game,Spell spell){
  StringBuilder sb=new StringBuilder();
  for (  Ability ability : (Abilities<Ability>)spell.getAbilities()) {
    if (ability instanceof OptionalAdditionalSourceCosts) {
      sb.append(((OptionalAdditionalSourceCosts)ability).getCastMessageSuffix());
    }
    if (ability instanceof AlternativeSourceCosts && ((AlternativeSourceCosts)ability).isActivated()) {
      sb.append(((AlternativeSourceCosts)ability).getCastMessageSuffix());
    }
  }
  return sb.toString();
}