Program: 158242
Project: 158242
Buggy source:
public boolean putOntoBattlefield(int amount,Game game,UUID sourceId,UUID controllerId,boolean tapped,boolean attacking,UUID attackedPlayer){
  Player controller=game.getPlayer(controllerId);
  if (controller == null) {
    return false;
  }
  lastAddedTokenIds.clear();
  String setCode=null;
  if (this.getOriginalExpansionSetCode() != null && !this.getOriginalExpansionSetCode().isEmpty()) {
    setCode=this.getOriginalExpansionSetCode();
  }
 else {
    Card source=game.getCard(sourceId);
    if (source != null) {
      setCode=source.getExpansionSetCode();
    }
 else {
      MageObject object=game.getObject(sourceId);
      if (object instanceof PermanentToken) {
        setCode=((PermanentToken)object).getExpansionSetCode();
      }
    }
  }
  if (!expansionSetCodeChecked) {
    expansionSetCodeChecked=this.updateExpansionSetCode(setCode);
  }
  GameEvent event=new GameEvent(EventType.CREATE_TOKEN,null,sourceId,controllerId,amount,this.getCardType().contains(CardType.CREATURE));
  if (!game.replaceEvent(event)) {
    amount=event.getAmount();
    List<Permanent> permanents=new ArrayList<>();
    List<Permanent> permanentsEntered=new ArrayList<>();
    for (int i=0; i < amount; i++) {
      PermanentToken newToken=new PermanentToken(this,event.getPlayerId(),setCode,game);
      game.getState().addCard(newToken);
      permanents.add(newToken);
      game.getPermanentsEntering().put(newToken.getId(),newToken);
      newToken.setTapped(tapped);
    }
    game.setScopeRelevant(true);
    for (    Permanent permanent : permanents) {
      if (permanent.entersBattlefield(sourceId,game,Zone.OUTSIDE,true)) {
        permanentsEntered.add(permanent);
      }
 else {
        game.getPermanentsEntering().remove(permanent.getId());
      }
    }
    game.setScopeRelevant(false);
    for (    Permanent permanent : permanentsEntered) {
      game.addPermanent(permanent);
      permanent.setZone(Zone.BATTLEFIELD,game);
      game.getPermanentsEntering().remove(permanent.getId());
      this.lastAddedTokenIds.add(permanent.getId());
      this.lastAddedTokenId=permanent.getId();
      game.addSimultaneousEvent(new ZoneChangeEvent(permanent,permanent.getControllerId(),Zone.OUTSIDE,Zone.BATTLEFIELD));
      if (attacking && game.getCombat() != null) {
        game.getCombat().addAttackingCreature(permanent.getId(),game,attackedPlayer);
      }
      if (!game.isSimulation()) {
        game.informPlayers(controller.getLogName() + "String_Node_Str" + permanent.getLogName()+ "String_Node_Str");
      }
    }
    return true;
  }
  return false;
}

Fixed version (ground truth):
public boolean putOntoBattlefield(int amount,Game game,UUID sourceId,UUID controllerId,boolean tapped,boolean attacking,UUID attackedPlayer){
  Player controller=game.getPlayer(controllerId);
  if (controller == null) {
    return false;
  }
  lastAddedTokenIds.clear();
  String setCode=null;
  if (this.getOriginalExpansionSetCode() != null && !this.getOriginalExpansionSetCode().isEmpty()) {
    setCode=this.getOriginalExpansionSetCode();
  }
 else {
    Card source=game.getCard(sourceId);
    if (source != null) {
      setCode=source.getExpansionSetCode();
    }
 else {
      MageObject object=game.getObject(sourceId);
      if (object instanceof PermanentToken) {
        setCode=((PermanentToken)object).getExpansionSetCode();
      }
    }
  }
  if (!expansionSetCodeChecked) {
    expansionSetCodeChecked=this.updateExpansionSetCode(setCode);
  }
  GameEvent event=new GameEvent(EventType.CREATE_TOKEN,null,sourceId,controllerId,amount,this.getCardType().contains(CardType.CREATURE));
  if (!game.replaceEvent(event)) {
    amount=event.getAmount();
    List<Permanent> permanents=new ArrayList<>();
    List<Permanent> permanentsEntered=new ArrayList<>();
    for (int i=0; i < amount; i++) {
      PermanentToken newToken=new PermanentToken(this,event.getPlayerId(),setCode,game);
      game.getState().addCard(newToken);
      permanents.add(newToken);
      game.getPermanentsEntering().put(newToken.getId(),newToken);
      newToken.setTapped(tapped);
    }
    game.setScopeRelevant(true);
    for (    Permanent permanent : permanents) {
      if (permanent.entersBattlefield(sourceId,game,Zone.OUTSIDE,true)) {
        permanentsEntered.add(permanent);
      }
 else {
        game.getPermanentsEntering().remove(permanent.getId());
      }
    }
    game.setScopeRelevant(false);
    for (    Permanent permanent : permanentsEntered) {
      game.addPermanent(permanent);
      permanent.setZone(Zone.BATTLEFIELD,game);
      game.getPermanentsEntering().remove(permanent.getId());
      this.lastAddedTokenIds.add(permanent.getId());
      this.lastAddedTokenId=permanent.getId();
      game.addSimultaneousEvent(new ZoneChangeEvent(permanent,permanent.getControllerId(),Zone.OUTSIDE,Zone.BATTLEFIELD));
      if (attacking && game.getCombat() != null) {
        game.getCombat().addAttackingCreature(permanent.getId(),game,attackedPlayer);
      }
      if (!game.isSimulation()) {
        game.informPlayers(controller.getLogName() + "String_Node_Str" + permanent.getLogName()+ "String_Node_Str");
      }
    }
    game.getState().applyEffects(game);
    return true;
  }
  return false;
}