nus-yam/ex-repair huggingface dataset:
Program: 157664
Project: 157664
Buggy source:
public MuldrothaTheGravetideWatcher(final MuldrothaTheGravetideWatcher watcher){
  super(watcher);
  playerPlayedPermanentTypes.putAll(watcher.playerPlayedPermanentTypes);
}

Fixed version (ground truth):
public MuldrothaTheGravetideWatcher(final MuldrothaTheGravetideWatcher watcher){
  super(watcher);
  sourcePlayedPermanentTypes.putAll(watcher.sourcePlayedPermanentTypes);
}
Program: 157665
Project: 157665
Buggy source:
@Override public boolean applies(UUID objectId,Ability source,UUID affectedControllerId,Game game){
  if (source.getControllerId().equals(affectedControllerId) && source.getControllerId().equals(game.getOwnerId(objectId)) && affectedControllerId.equals(game.getActivePlayerId())&& Zone.GRAVEYARD.equals(game.getState().getZone(objectId))) {
    MuldrothaTheGravetideWatcher watcher=(MuldrothaTheGravetideWatcher)game.getState().getWatchers().get(MuldrothaTheGravetideWatcher.class.getSimpleName());
    MageObject mageObject=game.getObject(objectId);
    if (mageObject != null && watcher != null) {
      for (      CardType cardType : mageObject.getCardType()) {
        if (cardType.isPermanentType()) {
          if (!watcher.permanentTypePlayedFromGraveyard(affectedControllerId,cardType)) {
            return true;
          }
        }
      }
    }
  }
  return false;
}

Fixed version (ground truth):
@Override public boolean applies(UUID objectId,Ability source,UUID affectedControllerId,Game game){
  if (source.getControllerId().equals(affectedControllerId) && source.getControllerId().equals(game.getOwnerId(objectId)) && affectedControllerId.equals(game.getActivePlayerId())&& Zone.GRAVEYARD.equals(game.getState().getZone(objectId))) {
    MuldrothaTheGravetideWatcher watcher=(MuldrothaTheGravetideWatcher)game.getState().getWatchers().get(MuldrothaTheGravetideWatcher.class.getSimpleName());
    MageObject mageObject=game.getObject(objectId);
    if (mageObject != null && watcher != null) {
      for (      CardType cardType : mageObject.getCardType()) {
        if (cardType.isPermanentType()) {
          MageObjectReference mor=new MageObjectReference(source.getSourceObject(game),game);
          if (!watcher.permanentTypePlayedFromGraveyard(mor,cardType)) {
            return true;
          }
        }
      }
    }
  }
  return false;
}
Program: 157666
Project: 157666
Buggy source:
@Override public void reset(){
  playerPlayedPermanentTypes.clear();
  super.reset();
}

Fixed version (ground truth):
@Override public void reset(){
  sourcePlayedPermanentTypes.clear();
  super.reset();
}
Program: 157667
Project: 157667
Buggy source:
public boolean permanentTypePlayedFromGraveyard(UUID playerId,CardType cardType){
  Set<CardType> permanentTypes=playerPlayedPermanentTypes.get(playerId);
  if (permanentTypes != null) {
    return permanentTypes.contains(cardType);
  }
  return false;
}

Fixed version (ground truth):
public boolean permanentTypePlayedFromGraveyard(MageObjectReference sourceMor,CardType cardType){
  Set<CardType> permanentTypes=sourcePlayedPermanentTypes.get(sourceMor);
  if (permanentTypes != null) {
    return permanentTypes.contains(cardType);
  }
  return false;
}
Program: 157669
Project: 157669
Buggy source:
@Override public int compare(CardView a,CardView b){
  Comparable aCom=null;
  Comparable bCom=null;
switch (column) {
case 0:
    aCom=1;
  bCom=1;
break;
case 1:
aCom=a.getName();
bCom=b.getName();
if (aCom.equals(bCom) && a.getExpansionSetCode().equals(b.getExpansionSetCode())) {
aCom=a.getCardNumber();
bCom=b.getCardNumber();
}
break;
case 2:
aCom=a.getConvertedManaCost();
bCom=b.getConvertedManaCost();
break;
case 3:
aCom=a.getColorText();
bCom=a.getColorText();
break;
case 4:
aCom=a.getTypeText();
bCom=b.getTypeText();
break;
case 5:
aCom=(float)-1;
bCom=(float)-1;
if (a.isCreature()) {
aCom=new Float(a.getPower() + '.' + (a.getToughness().startsWith("String_Node_Str") ? "String_Node_Str" : a.getToughness()));
}
if (b.isCreature()) {
bCom=new Float(b.getPower() + '.' + (b.getToughness().startsWith("String_Node_Str") ? "String_Node_Str" : b.getToughness()));
}
break;
case 6:
aCom=a.getRarity().toString();
bCom=b.getRarity().toString();
break;
case 7:
aCom=a.getExpansionSetCode();
bCom=b.getExpansionSetCode();
break;
case 8:
aCom=Integer.parseInt(a.getCardNumber().replaceAll("String_Node_Str","String_Node_Str"));
bCom=Integer.parseInt(b.getCardNumber().replaceAll("String_Node_Str","String_Node_Str"));
break;
default :
break;
}
if (ascending) {
return aCom.compareTo(bCom);
}
 else {
return bCom.compareTo(aCom);
}
}

Fixed version (ground truth):
@Override public int compare(CardView a,CardView b){
  Comparable aCom=null;
  Comparable bCom=null;
switch (column) {
case 0:
    aCom=1;
  bCom=1;
break;
case 1:
aCom=a.getName();
bCom=b.getName();
if (aCom.equals(bCom) && a.getExpansionSetCode().equals(b.getExpansionSetCode())) {
aCom=a.getCardNumber();
bCom=b.getCardNumber();
}
break;
case 2:
aCom=a.getConvertedManaCost();
bCom=b.getConvertedManaCost();
break;
case 3:
aCom=a.getColorText();
bCom=b.getColorText();
break;
case 4:
aCom=a.getTypeText();
bCom=b.getTypeText();
break;
case 5:
aCom=(float)-1;
bCom=(float)-1;
if (a.isCreature()) {
aCom=new Float(a.getPower() + '.' + (a.getToughness().startsWith("String_Node_Str") ? "String_Node_Str" : a.getToughness()));
}
if (b.isCreature()) {
bCom=new Float(b.getPower() + '.' + (b.getToughness().startsWith("String_Node_Str") ? "String_Node_Str" : b.getToughness()));
}
break;
case 6:
aCom=a.getRarity().toString();
bCom=b.getRarity().toString();
break;
case 7:
aCom=a.getExpansionSetCode();
bCom=b.getExpansionSetCode();
break;
case 8:
aCom=Integer.parseInt(a.getCardNumber().replaceAll("String_Node_Str","String_Node_Str"));
bCom=Integer.parseInt(b.getCardNumber().replaceAll("String_Node_Str","String_Node_Str"));
break;
default :
break;
}
if (ascending) {
return aCom.compareTo(bCom);
}
 else {
return bCom.compareTo(aCom);
}
}
Program: 157670
Project: 157670
Buggy source:
/** 
 * Creates new form TableWaitingDialog
 */
public TableWaitingDialog(){
  tableWaitModel=new TableWaitModel();
  initComponents();
  int prefWidth=Integer.parseInt(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_TABLE_WAITING_WIDTH,"String_Node_Str"));
  int prefHeight=Integer.parseInt(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_TABLE_WAITING_HEIGHT,"String_Node_Str"));
  if (prefWidth > 40 && prefHeight > 40) {
    this.setSize(prefWidth,prefHeight);
  }
  setGUISize();
  chatPanel.useExtendedView(ChatPanelBasic.VIEW_MODE.NONE);
  jTableSeats.createDefaultColumnsFromModel();
  TableUtil.setColumnWidthAndOrder(jTableSeats,DEFAULT_COLUMNS_WIDTH,KEY_TABLE_WAITING_COLUMNS_WIDTH,KEY_TABLE_WAITING_COLUMNS_ORDER);
  jTableSeats.setDefaultRenderer(Icon.class,new CountryCellRenderer());
  MageFrame.getUI().addButton(MageComponents.TABLE_WAITING_START_BUTTON,btnStart);
}

Fixed version (ground truth):
/** 
 * Creates new form TableWaitingDialog
 */
public TableWaitingDialog(){
  tableWaitModel=new TableWaitModel();
  initComponents();
  int prefWidth=Integer.parseInt(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_TABLE_WAITING_WIDTH,"String_Node_Str"));
  int prefHeight=Integer.parseInt(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_TABLE_WAITING_HEIGHT,"String_Node_Str"));
  if (prefWidth > 40 && prefHeight > 40) {
    this.setSize(prefWidth,prefHeight);
  }
  setGUISize();
  jTableSeats.createDefaultColumnsFromModel();
  jTableSeats.setAutoCreateColumnsFromModel(false);
  jTableSeats.setDefaultRenderer(Icon.class,new CountryCellRenderer());
  TableUtil.setColumnWidthAndOrder(jTableSeats,DEFAULT_COLUMNS_WIDTH,KEY_TABLE_WAITING_COLUMNS_WIDTH,KEY_TABLE_WAITING_COLUMNS_ORDER);
  chatPanel.useExtendedView(ChatPanelBasic.VIEW_MODE.NONE);
  MageFrame.getUI().addButton(MageComponents.TABLE_WAITING_START_BUTTON,btnStart);
}
Program: 157671
Project: 157671
Buggy source:
public void showDialog(UUID roomId,UUID tableId,boolean isTournament){
  this.roomId=roomId;
  this.tableId=tableId;
  this.isTournament=isTournament;
  updateTask=new UpdateSeatsTask(SessionHandler.getSession(),roomId,tableId,this);
  if (SessionHandler.isTableOwner(roomId,tableId)) {
    this.btnStart.setVisible(true);
    this.btnMoveDown.setVisible(true);
    this.btnMoveUp.setVisible(true);
  }
 else {
    this.btnStart.setVisible(false);
    this.btnMoveDown.setVisible(false);
    this.btnMoveUp.setVisible(false);
  }
  Optional<UUID> chatId=SessionHandler.getTableChatId(tableId);
  if (chatId.isPresent()) {
    this.chatPanel.connect(chatId.get());
    updateTask.execute();
    this.setModal(false);
    this.setLocation(100,100);
    this.setVisible(true);
  }
 else {
    closeDialog();
  }
}

Fixed version (ground truth):
public void showDialog(UUID roomId,UUID tableId,boolean isTournament){
  Rectangle currentBounds=MageFrame.getDesktop().getBounds();
  Optional<UUID> chatId=SessionHandler.getTableChatId(tableId);
  String tournamentChatDivider=PreferencesDialog.getCachedValue(KEY_TABLES_DIVIDER_LOCATION_4,null);
  updateTask=new UpdateSeatsTask(SessionHandler.getSession(),roomId,tableId,this);
  this.roomId=roomId;
  this.tableId=tableId;
  this.isTournament=isTournament;
  if (SessionHandler.isTableOwner(roomId,tableId)) {
    this.btnStart.setVisible(true);
    this.btnMoveDown.setVisible(true);
    this.btnMoveUp.setVisible(true);
  }
 else {
    this.btnStart.setVisible(false);
    this.btnMoveDown.setVisible(false);
    this.btnMoveUp.setVisible(false);
  }
  if (chatId.isPresent()) {
    this.chatPanel.connect(chatId.get());
    updateTask.execute();
    this.setModal(false);
    this.setLocation(100,100);
    this.setVisible(true);
    GuiDisplayUtil.restoreDividerLocations(currentBounds,tournamentChatDivider,jSplitPane1);
  }
 else {
    closeDialog();
  }
}
Program: 157672
Project: 157672
Buggy source:
public void closeDialog(){
  if (updateTask != null) {
    updateTask.cancel(true);
  }
  this.chatPanel.disconnect();
  MageFrame.getUI().removeButton(MageComponents.TABLE_WAITING_START_BUTTON);
  this.removeDialog();
  TableUtil.saveColumnWidthAndOrderToPrefs(jTableSeats,KEY_TABLE_WAITING_COLUMNS_WIDTH,KEY_TABLE_WAITING_COLUMNS_ORDER);
}

Fixed version (ground truth):
public void closeDialog(){
  if (updateTask != null) {
    updateTask.cancel(true);
  }
  this.chatPanel.disconnect();
  MageFrame.getUI().removeButton(MageComponents.TABLE_WAITING_START_BUTTON);
  this.removeDialog();
  TableUtil.saveColumnWidthAndOrderToPrefs(jTableSeats,KEY_TABLE_WAITING_COLUMNS_WIDTH,KEY_TABLE_WAITING_COLUMNS_ORDER);
  GuiDisplayUtil.saveCurrentBoundsToPrefs();
  GuiDisplayUtil.saveDividerLocationToPrefs(KEY_TABLES_DIVIDER_LOCATION_4,this.jSplitPane1.getDividerLocation());
}
Program: 157673
Project: 157673
Buggy source:
public void showTables(UUID roomId){
  this.roomId=roomId;
  UUID chatRoomId=null;
  if (SessionHandler.getSession() != null) {
    btnQuickStart.setVisible(SessionHandler.isTestMode());
    gameChooser.init();
    chatRoomId=SessionHandler.getRoomChatId(roomId).orElse(null);
  }
  if (newTableDialog == null) {
    newTableDialog=new NewTableDialog();
    MageFrame.getDesktop().add(newTableDialog,JLayeredPane.MODAL_LAYER);
  }
  if (newTournamentDialog == null) {
    newTournamentDialog=new NewTournamentDialog();
    MageFrame.getDesktop().add(newTournamentDialog,JLayeredPane.MODAL_LAYER);
  }
  if (joinTableDialog == null) {
    joinTableDialog=new JoinTableDialog();
    MageFrame.getDesktop().add(joinTableDialog,JLayeredPane.MODAL_LAYER);
  }
  if (chatRoomId != null) {
    this.chatPanelMain.getUserChatPanel().connect(chatRoomId);
    startTasks();
    this.setVisible(true);
    this.repaint();
  }
 else {
    hideTables();
  }
  reloadMessages();
  MageFrame.getUI().addButton(MageComponents.NEW_GAME_BUTTON,btnNewTable);
  Executors.newSingleThreadScheduledExecutor().schedule(() -> restoreDividerLocations(),300,TimeUnit.MILLISECONDS);
}

Fixed version (ground truth):
public void showTables(UUID roomId){
  this.roomId=roomId;
  UUID chatRoomId=null;
  if (SessionHandler.getSession() != null) {
    btnQuickStart.setVisible(SessionHandler.isTestMode());
    gameChooser.init();
    chatRoomId=SessionHandler.getRoomChatId(roomId).orElse(null);
  }
  if (newTableDialog == null) {
    newTableDialog=new NewTableDialog();
    MageFrame.getDesktop().add(newTableDialog,JLayeredPane.MODAL_LAYER);
  }
  if (newTournamentDialog == null) {
    newTournamentDialog=new NewTournamentDialog();
    MageFrame.getDesktop().add(newTournamentDialog,JLayeredPane.MODAL_LAYER);
  }
  if (joinTableDialog == null) {
    joinTableDialog=new JoinTableDialog();
    MageFrame.getDesktop().add(joinTableDialog,JLayeredPane.MODAL_LAYER);
  }
  if (chatRoomId != null) {
    this.chatPanelMain.getUserChatPanel().connect(chatRoomId);
    startTasks();
    this.setVisible(true);
    this.repaint();
  }
 else {
    hideTables();
  }
  reloadMessages();
  MageFrame.getUI().addButton(MageComponents.NEW_GAME_BUTTON,btnNewTable);
  Executors.newSingleThreadScheduledExecutor().schedule(() -> restoreDividers(),300,TimeUnit.MILLISECONDS);
}
Program: 157674
Project: 157674
Buggy source:
private void saveDividerLocations(){
  Rectangle rec=MageFrame.getDesktop().getBounds();
  String sb=Double.toString(rec.getWidth()) + 'x' + Double.toString(rec.getHeight());
  PreferencesDialog.saveValue(PreferencesDialog.KEY_MAGE_PANEL_LAST_SIZE,sb);
  PreferencesDialog.saveValue(PreferencesDialog.KEY_TABLES_DIVIDER_LOCATION_1,Integer.toString(this.jSplitPane1.getDividerLocation()));
  PreferencesDialog.saveValue(PreferencesDialog.KEY_TABLES_DIVIDER_LOCATION_2,Integer.toString(this.jSplitPaneTables.getDividerLocation()));
  PreferencesDialog.saveValue(PreferencesDialog.KEY_TABLES_DIVIDER_LOCATION_3,Integer.toString(chatPanelMain.getSplitDividerLocation()));
}

Fixed version (ground truth):
private void saveDividerLocations(){
  GuiDisplayUtil.saveCurrentBoundsToPrefs();
  GuiDisplayUtil.saveDividerLocationToPrefs(KEY_TABLES_DIVIDER_LOCATION_1,this.jSplitPane1.getDividerLocation());
  GuiDisplayUtil.saveDividerLocationToPrefs(KEY_TABLES_DIVIDER_LOCATION_2,this.jSplitPaneTables.getDividerLocation());
  GuiDisplayUtil.saveDividerLocationToPrefs(KEY_TABLES_DIVIDER_LOCATION_3,chatPanelMain.getSplitDividerLocation());
}
Program: 157676
Project: 157676
Buggy source:
public void cleanUp(){
  saveSettings();
  chatPanelMain.cleanUp();
}

Fixed version (ground truth):
public void cleanUp(){
  saveGuiSettings();
  chatPanelMain.cleanUp();
}
Program: 157677
Project: 157677
Buggy source:
static public void setColumnWidthAndOrder(JTable table,int[] defaultColumnsWidth,String widthPrefKey,String orderPrefKey){
  table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
  int[] widths=getIntArrayFromString(PreferencesDialog.getCachedValue(widthPrefKey,null));
  LOGGER.info("String_Node_Str" + Arrays.toString(widths));
  int i=0;
  for (  int width : defaultColumnsWidth) {
    if (widths != null && widths.length > i) {
      width=widths[i];
    }
    if (table.getColumnModel().getColumnCount() >= i) {
      TableColumn column=table.getColumnModel().getColumn(i++);
      column.setWidth(width);
      column.setPreferredWidth(width);
    }
 else {
      break;
    }
  }
  int[] order=getIntArrayFromString(PreferencesDialog.getCachedValue(orderPrefKey,null));
  LOGGER.info("String_Node_Str" + Arrays.toString(order));
  if (order != null && order.length == table.getColumnCount()) {
    for (int j=0; j < table.getColumnCount(); j++) {
      table.moveColumn(table.convertColumnIndexToView(order[j]),j);
    }
  }
}

Fixed version (ground truth):
public static void setColumnWidthAndOrder(JTable table,int[] defaultColumnsWidth,String widthPrefKey,String orderPrefKey){
  table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
  int[] widths=getIntArrayFromString(PreferencesDialog.getCachedValue(widthPrefKey,null));
  int i=0;
  for (  int width : defaultColumnsWidth) {
    if (widths != null && widths.length > i) {
      width=widths[i];
    }
    if (table.getColumnModel().getColumnCount() >= i) {
      TableColumn column=table.getColumnModel().getColumn(i++);
      column.setWidth(width);
      column.setPreferredWidth(width);
    }
 else {
      break;
    }
  }
  int[] order=getIntArrayFromString(PreferencesDialog.getCachedValue(orderPrefKey,null));
  if (order != null && order.length == table.getColumnCount()) {
    for (int j=0; j < table.getColumnCount(); j++) {
      table.moveColumn(table.convertColumnIndexToView(order[j]),j);
    }
  }
}
Program: 157678
Project: 157678
Buggy source:
static public void saveColumnWidthAndOrderToPrefs(JTable table,String widthPrefKey,String orderPrefKey){
  StringBuilder columnWidthSettings=new StringBuilder();
  StringBuilder columnOrderSettings=new StringBuilder();
  boolean firstValue=true;
  for (int i=0; i < table.getColumnModel().getColumnCount(); i++) {
    TableColumn column=table.getColumnModel().getColumn(table.convertColumnIndexToView(i));
    if (!firstValue) {
      columnWidthSettings.append(',');
      columnOrderSettings.append(',');
    }
 else {
      firstValue=false;
    }
    columnWidthSettings.append(column.getWidth());
    columnOrderSettings.append(table.convertColumnIndexToModel(i));
  }
  PreferencesDialog.saveValue(widthPrefKey,columnWidthSettings.toString());
  PreferencesDialog.saveValue(orderPrefKey,columnOrderSettings.toString());
  LOGGER.info("String_Node_Str" + columnWidthSettings.toString());
  LOGGER.info("String_Node_Str" + columnOrderSettings.toString());
}

Fixed version (ground truth):
public static void saveColumnWidthAndOrderToPrefs(JTable table,String widthPrefKey,String orderPrefKey){
  StringBuilder columnWidthSettings=new StringBuilder();
  StringBuilder columnOrderSettings=new StringBuilder();
  boolean firstValue=true;
  for (int i=0; i < table.getColumnModel().getColumnCount(); i++) {
    TableColumn column=table.getColumnModel().getColumn(table.convertColumnIndexToView(i));
    if (!firstValue) {
      columnWidthSettings.append(',');
      columnOrderSettings.append(',');
    }
 else {
      firstValue=false;
    }
    columnWidthSettings.append(column.getWidth());
    columnOrderSettings.append(table.convertColumnIndexToModel(i));
  }
  PreferencesDialog.saveValue(widthPrefKey,columnWidthSettings.toString());
  PreferencesDialog.saveValue(orderPrefKey,columnOrderSettings.toString());
}
Program: 157679
Project: 157679
Buggy source:
public static int[] getIntArrayFromString(String stringData){
  int[] intArray=null;
  if (stringData != null && !stringData.isEmpty()) {
    String[] items=stringData.split("String_Node_Str");
    int lengthW=items.length;
    intArray=new int[lengthW];
    for (int i=0; i < lengthW; i++) {
      try {
        intArray[i]=Integer.parseInt(items[i]);
      }
 catch (      NumberFormatException nfe) {
      }
    }
  }
  return intArray;
}

Fixed version (ground truth):
private static int[] getIntArrayFromString(String stringData){
  int[] intArray=null;
  if (stringData != null && !stringData.isEmpty()) {
    String[] items=stringData.split("String_Node_Str");
    int lengthW=items.length;
    intArray=new int[lengthW];
    for (int i=0; i < lengthW; i++) {
      try {
        intArray[i]=Integer.parseInt(items[i]);
      }
 catch (      NumberFormatException nfe) {
      }
    }
  }
  return intArray;
}
Program: 157680
Project: 157680
Buggy source:
@Override public boolean apply(Game game,Ability source){
  UUID controllerId=source.getControllerId();
  Target target=new TargetCreaturePermanent();
  target.setNotTarget(true);
  target.setTargetName("String_Node_Str");
  if (!target.canChoose(source.getSourceId(),controllerId,game)) {
    return false;
  }
  Player player=game.getPlayer(controllerId);
  if (player != null) {
    player.chooseTarget(Outcome.Sacrifice,target,source,game);
    Permanent creatureToSacrifice=game.getPermanent(target.getTargets().get(0));
    int amount=creatureToSacrifice.getPower().getValue();
    if (!creatureToSacrifice.sacrifice(creatureToSacrifice.getId(),game)) {
      return false;
    }
    if (amount > 0) {
      Permanent permanent=game.getPermanent(source.getFirstTarget());
      if (permanent != null) {
        permanent.damage(amount,source.getSourceId(),game,false,true);
        return true;
      }
      player=game.getPlayer(source.getFirstTarget());
      if (player != null) {
        player.damage(amount,source.getSourceId(),game,false,true);
        return true;
      }
    }
 else {
      return true;
    }
  }
  return false;
}

Fixed version (ground truth):
@Override public boolean apply(Game game,Ability source){
  UUID controllerId=source.getControllerId();
  Target target=new TargetControlledCreaturePermanent();
  target.setNotTarget(true);
  target.setTargetName("String_Node_Str");
  if (!target.canChoose(source.getSourceId(),controllerId,game)) {
    return false;
  }
  Player player=game.getPlayer(controllerId);
  if (player != null) {
    player.chooseTarget(Outcome.Sacrifice,target,source,game);
    Permanent creatureToSacrifice=game.getPermanent(target.getTargets().get(0));
    int amount=creatureToSacrifice.getPower().getValue();
    if (!creatureToSacrifice.sacrifice(creatureToSacrifice.getId(),game)) {
      return false;
    }
    if (amount > 0) {
      Permanent permanent=game.getPermanent(source.getFirstTarget());
      if (permanent != null) {
        permanent.damage(amount,source.getSourceId(),game,false,true);
        return true;
      }
      player=game.getPlayer(source.getFirstTarget());
      if (player != null) {
        player.damage(amount,source.getSourceId(),game,false,true);
        return true;
      }
    }
 else {
      return true;
    }
  }
  return false;
}
Program: 157682
Project: 157682
Buggy source:
private void handlePopup(TransferData transferData){
  MageCard mageCard=(MageCard)transferData.component;
  if (!popupTextWindowOpen || mageCard.getOriginal().getId() != bigCard.getCardId()) {
    if (bigCard.getWidth() > 0) {
synchronized (MageActionCallback.class) {
        if (!popupTextWindowOpen || mageCard.getOriginal().getId() != bigCard.getCardId()) {
          if (!popupTextWindowOpen) {
            bigCard.resetCardId();
          }
          popupTextWindowOpen=true;
          Image image=mageCard.getImage();
          displayCardInfo(mageCard,image,bigCard);
        }
      }
    }
 else {
      popupTextWindowOpen=true;
    }
    if (enlargedWindowState != EnlargedWindowState.CLOSED) {
      cancelTimeout();
      displayEnlargedCard(mageCard.getOriginal(),transferData);
    }
  }
}

Fixed version (ground truth):
private void handlePopup(TransferData transferData){
  MageCard mageCard=(MageCard)transferData.component;
  if (!popupTextWindowOpen || !Objects.equals(mageCard.getOriginal().getId(),bigCard.getCardId())) {
    if (bigCard.getWidth() > 0) {
synchronized (MageActionCallback.class) {
        if (!popupTextWindowOpen || !Objects.equals(mageCard.getOriginal().getId(),bigCard.getCardId())) {
          if (!popupTextWindowOpen) {
            bigCard.resetCardId();
          }
          popupTextWindowOpen=true;
          Image image=mageCard.getImage();
          displayCardInfo(mageCard,image,bigCard);
        }
      }
    }
 else {
      popupTextWindowOpen=true;
    }
    if (enlargedWindowState != EnlargedWindowState.CLOSED) {
      cancelTimeout();
      displayEnlargedCard(mageCard.getOriginal(),transferData);
    }
  }
}
Program: 157683
Project: 157683
Buggy source:
@Override public boolean equals(Object obj){
  if (obj == null) {
    return false;
  }
  if (getClass() != obj.getClass()) {
    return false;
  }
  final CardDownloadData other=(CardDownloadData)obj;
  if ((this.name == null) ? (other.name != null) : !this.name.equals(other.name)) {
    return false;
  }
  if ((this.set == null) ? (other.set != null) : !this.set.equals(other.set)) {
    return false;
  }
  if (!Objects.equals(this.collectorId,other.collectorId) && (this.collectorId == null || !this.collectorId.equals(other.collectorId))) {
    return false;
  }
  if (this.token != other.token) {
    return false;
  }
  if (this.twoFacedCard != other.twoFacedCard) {
    return false;
  }
  if (this.secondSide != other.secondSide) {
    return false;
  }
  if (this.isType2 != other.isType2) {
    return false;
  }
  return true;
}

Fixed version (ground truth):
@Override public boolean equals(Object obj){
  if (obj == null) {
    return false;
  }
  if (!getClass().equals(obj.getClass())) {
    return false;
  }
  final CardDownloadData other=(CardDownloadData)obj;
  if ((this.name == null) ? (other.name != null) : !this.name.equals(other.name)) {
    return false;
  }
  if ((this.set == null) ? (other.set != null) : !this.set.equals(other.set)) {
    return false;
  }
  if (!Objects.equals(this.collectorId,other.collectorId) && (this.collectorId == null || !this.collectorId.equals(other.collectorId))) {
    return false;
  }
  if (this.token != other.token) {
    return false;
  }
  if (this.twoFacedCard != other.twoFacedCard) {
    return false;
  }
  if (this.secondSide != other.secondSide) {
    return false;
  }
  if (this.isType2 != other.isType2) {
    return false;
  }
  return true;
}
Program: 157684
Project: 157684
Buggy source:
private void showProxySettings(){
  if (cbProxyType.getSelectedItem() == Connection.ProxyType.SOCKS) {
    this.pnlProxy.setVisible(true);
    this.pnlProxyAuth.setVisible(false);
    this.pnlProxySettings.setVisible(true);
  }
 else   if (cbProxyType.getSelectedItem() == Connection.ProxyType.HTTP) {
    this.pnlProxy.setVisible(true);
    this.pnlProxyAuth.setVisible(true);
    this.pnlProxySettings.setVisible(true);
  }
 else   if (cbProxyType.getSelectedItem() == Connection.ProxyType.NONE) {
    this.pnlProxy.setVisible(false);
    this.pnlProxyAuth.setVisible(false);
    this.pnlProxySettings.setVisible(false);
  }
  this.pack();
  this.repaint();
}

Fixed version (ground truth):
private void showProxySettings(){
  if (Objects.equals(cbProxyType.getSelectedItem(),ProxyType.SOCKS)) {
    this.pnlProxy.setVisible(true);
    this.pnlProxyAuth.setVisible(false);
    this.pnlProxySettings.setVisible(true);
  }
 else   if (Objects.equals(cbProxyType.getSelectedItem(),ProxyType.HTTP)) {
    this.pnlProxy.setVisible(true);
    this.pnlProxyAuth.setVisible(true);
    this.pnlProxySettings.setVisible(true);
  }
 else   if (Objects.equals(cbProxyType.getSelectedItem(),ProxyType.NONE)) {
    this.pnlProxy.setVisible(false);
    this.pnlProxyAuth.setVisible(false);
    this.pnlProxySettings.setVisible(false);
  }
  this.pack();
  this.repaint();
}
Program: 157687
Project: 157687
Buggy source:
@Override public boolean applies(GameEvent event,Ability source,Game game){
  Permanent brand=game.getPermanent(source.getSourceId());
  if (brand != null && brand.getAttachedTo() != null) {
    UUID enchantedController=game.getPermanent(brand.getAttachedTo()).getControllerId();
    if (enchantedController == event.getPlayerId() && game.getObject(event.getSourceId()).isCreature()) {
      return true;
    }
  }
  return false;
}

Fixed version (ground truth):
@Override public boolean applies(GameEvent event,Ability source,Game game){
  Permanent brand=game.getPermanent(source.getSourceId());
  if (brand != null && brand.getAttachedTo() != null) {
    UUID enchantedController=game.getPermanent(brand.getAttachedTo()).getControllerId();
    if (Objects.equals(enchantedController,event.getPlayerId()) && game.getObject(event.getSourceId()).isCreature()) {
      return true;
    }
  }
  return false;
}
Program: 157688
Project: 157688
Buggy source:
@Override public Set<UUID> possibleTargets(UUID sourceControllerId,Game game){
  Set<UUID> possibleTargets=new HashSet<>();
  for (  StackObject stackObject : game.getStack()) {
    if (game.getState().getPlayersInRange(sourceControllerId,game).contains(stackObject.getControllerId()) && stackObject.getControllerId() == sourceControllerId) {
      possibleTargets.add(stackObject.getId());
    }
  }
  for (  Permanent permanent : game.getBattlefield().getActivePermanents(sourceControllerId,game)) {
    if (permanent.getControllerId() == sourceControllerId) {
      possibleTargets.add(permanent.getId());
    }
  }
  for (  Player player : game.getPlayers().values()) {
    if (player == game.getPlayer(sourceControllerId)) {
      for (      Card card : player.getGraveyard().getCards(game)) {
        possibleTargets.add(card.getId());
      }
      for (      Card card : game.getExile().getAllCards(game)) {
        if (card.getOwnerId() == sourceControllerId) {
          possibleTargets.add(card.getId());
        }
      }
    }
  }
  return possibleTargets;
}

Fixed version (ground truth):
@Override public Set<UUID> possibleTargets(UUID sourceControllerId,Game game){
  Set<UUID> possibleTargets=new HashSet<>();
  for (  StackObject stackObject : game.getStack()) {
    if (game.getState().getPlayersInRange(sourceControllerId,game).contains(stackObject.getControllerId()) && Objects.equals(stackObject.getControllerId(),sourceControllerId)) {
      possibleTargets.add(stackObject.getId());
    }
  }
  for (  Permanent permanent : game.getBattlefield().getActivePermanents(sourceControllerId,game)) {
    if (Objects.equals(permanent.getControllerId(),sourceControllerId)) {
      possibleTargets.add(permanent.getId());
    }
  }
  for (  Player player : game.getPlayers().values()) {
    if (Objects.equals(player,game.getPlayer(sourceControllerId))) {
      for (      Card card : player.getGraveyard().getCards(game)) {
        possibleTargets.add(card.getId());
      }
      for (      Card card : game.getExile().getAllCards(game)) {
        if (Objects.equals(card.getOwnerId(),sourceControllerId)) {
          possibleTargets.add(card.getId());
        }
      }
    }
  }
  return possibleTargets;
}
Program: 157689
Project: 157689
Buggy source:
@Override public boolean canChoose(UUID sourceControllerId,Game game){
  int count=0;
  for (  StackObject stackObject : game.getStack()) {
    if (game.getState().getPlayersInRange(sourceControllerId,game).contains(stackObject.getControllerId()) && stackObject.getControllerId() == sourceControllerId) {
      count++;
      if (count >= this.minNumberOfTargets) {
        return true;
      }
    }
  }
  for (  Permanent permanent : game.getBattlefield().getActivePermanents(sourceControllerId,game)) {
    if (permanent.getControllerId() == sourceControllerId) {
      count++;
      if (count >= this.minNumberOfTargets) {
        return true;
      }
    }
  }
  for (  Player player : game.getPlayers().values()) {
    if (player == game.getPlayer(sourceControllerId)) {
      for (      Card card : player.getGraveyard().getCards(game)) {
        count++;
        if (count >= this.minNumberOfTargets) {
          return true;
        }
      }
      for (      Card card : game.getExile().getAllCards(game)) {
        if (card.getOwnerId() == sourceControllerId) {
          count++;
          if (count >= this.minNumberOfTargets) {
            return true;
          }
        }
      }
    }
  }
  return false;
}

Fixed version (ground truth):
@Override public boolean canChoose(UUID sourceControllerId,Game game){
  int count=0;
  for (  StackObject stackObject : game.getStack()) {
    if (game.getState().getPlayersInRange(sourceControllerId,game).contains(stackObject.getControllerId()) && Objects.equals(stackObject.getControllerId(),sourceControllerId)) {
      count++;
      if (count >= this.minNumberOfTargets) {
        return true;
      }
    }
  }
  for (  Permanent permanent : game.getBattlefield().getActivePermanents(sourceControllerId,game)) {
    if (Objects.equals(permanent.getControllerId(),sourceControllerId)) {
      count++;
      if (count >= this.minNumberOfTargets) {
        return true;
      }
    }
  }
  for (  Player player : game.getPlayers().values()) {
    if (Objects.equals(player,game.getPlayer(sourceControllerId))) {
      for (      Card card : player.getGraveyard().getCards(game)) {
        count++;
        if (count >= this.minNumberOfTargets) {
          return true;
        }
      }
      for (      Card card : game.getExile().getAllCards(game)) {
        if (Objects.equals(card.getOwnerId(),sourceControllerId)) {
          count++;
          if (count >= this.minNumberOfTargets) {
            return true;
          }
        }
      }
    }
  }
  return false;
}
Program: 157690
Project: 157690
Buggy source:
@Override public boolean applies(GameEvent event,Ability source,Game game){
  Player controller=game.getPlayer(source.getControllerId());
  DamageEvent damageEvent=(DamageEvent)event;
  if (controller != null) {
    if (controller.getId() == damageEvent.getTargetId() && damageEvent.getSourceId().equals(damageSource.getFirstTarget())) {
      this.discard();
      return true;
    }
  }
  return false;
}

Fixed version (ground truth):
@Override public boolean applies(GameEvent event,Ability source,Game game){
  Player controller=game.getPlayer(source.getControllerId());
  DamageEvent damageEvent=(DamageEvent)event;
  if (controller != null) {
    if (controller.getId().equals(damageEvent.getTargetId()) && damageEvent.getSourceId().equals(damageSource.getFirstTarget())) {
      this.discard();
      return true;
    }
  }
  return false;
}
Program: 157691
Project: 157691
Buggy source:
@Override public boolean apply(Game game,Ability source){
  Player activePlayer=game.getPlayer(game.getActivePlayerId());
  if (activePlayer == null) {
    return false;
  }
  int landCount=game.getBattlefield().getAllActivePermanents(filter,activePlayer.getId(),game).size();
  if (landCount == 0) {
    return false;
  }
  for (  UUID playerId : game.getPlayerList()) {
    if (playerId != activePlayer.getId()) {
      if (game.getBattlefield().getAllActivePermanents(filter,playerId,game).size() >= landCount) {
        return false;
      }
    }
  }
  return true;
}

Fixed version (ground truth):
@Override public boolean apply(Game game,Ability source){
  Player activePlayer=game.getPlayer(game.getActivePlayerId());
  if (activePlayer == null) {
    return false;
  }
  int landCount=game.getBattlefield().getAllActivePermanents(filter,activePlayer.getId(),game).size();
  if (landCount == 0) {
    return false;
  }
  for (  UUID playerId : game.getPlayerList()) {
    if (!playerId.equals(activePlayer.getId())) {
      if (game.getBattlefield().getAllActivePermanents(filter,playerId,game).size() >= landCount) {
        return false;
      }
    }
  }
  return true;
}
Program: 157692
Project: 157692
Buggy source:
@Override public boolean apply(Game game,Ability source){
  Player controller=game.getPlayer(source.getControllerId());
  if (controller != null) {
    Set<Player> playersThatSearched=new HashSet<>(1);
    for (    UUID playerId : game.getState().getPlayersInRange(controller.getId(),game)) {
      if (playerId != controller.getId()) {
        Player player=game.getPlayer(playerId);
        if (player != null && player.chooseUse(Outcome.PutCreatureInPlay,"String_Node_Str",source,game)) {
          TargetCardInLibrary target=new TargetCardInLibrary(new FilterLandCard());
          if (player.searchLibrary(target,game)) {
            Card targetCard=player.getLibrary().getCard(target.getFirstTarget(),game);
            if (targetCard != null) {
              player.moveCards(targetCard,Zone.BATTLEFIELD,source,game);
              playersThatSearched.add(player);
            }
          }
        }
      }
    }
    for (    Player player : playersThatSearched) {
      player.shuffleLibrary(source,game);
    }
    return true;
  }
  return false;
}

Fixed version (ground truth):
@Override public boolean apply(Game game,Ability source){
  Player controller=game.getPlayer(source.getControllerId());
  if (controller != null) {
    Set<Player> playersThatSearched=new HashSet<>(1);
    for (    UUID playerId : game.getState().getPlayersInRange(controller.getId(),game)) {
      if (!playerId.equals(controller.getId())) {
        Player player=game.getPlayer(playerId);
        if (player != null && player.chooseUse(Outcome.PutCreatureInPlay,"String_Node_Str",source,game)) {
          TargetCardInLibrary target=new TargetCardInLibrary(new FilterLandCard());
          if (player.searchLibrary(target,game)) {
            Card targetCard=player.getLibrary().getCard(target.getFirstTarget(),game);
            if (targetCard != null) {
              player.moveCards(targetCard,Zone.BATTLEFIELD,source,game);
              playersThatSearched.add(player);
            }
          }
        }
      }
    }
    for (    Player player : playersThatSearched) {
      player.shuffleLibrary(source,game);
    }
    return true;
  }
  return false;
}
Program: 157693
Project: 157693
Buggy source:
@Override public boolean apply(Game game,Ability source){
  Player controller=game.getPlayer(source.getControllerId());
  Permanent sourcePermanent=game.getPermanentOrLKIBattlefield(source.getSourceId());
  Spell spell=(Spell)game.getStack().getStackObject(targetPointer.getFirst(game,source));
  if (sourcePermanent != null && spell != null && controller != null) {
    Player spellController=game.getPlayer(spell.getControllerId());
    Cost cost=new ManaCostsImpl(spell.getSpellAbility().getManaCosts().getText());
    if (spellController != null) {
      for (      UUID playerId : game.getState().getPlayersInRange(source.getControllerId(),game)) {
        Player player=game.getPlayer(playerId);
        if (player != null && player != spellController) {
          cost.clearPaid();
          if (cost.canPay(source,source.getSourceId(),player.getId(),game) && player.chooseUse(outcome,"String_Node_Str" + cost.getText() + "String_Node_Str"+ spell.getIdName()+ '?',source,game)) {
            if (cost.pay(source,game,source.getSourceId(),playerId,false,null)) {
              game.informPlayers(player.getLogName() + "String_Node_Str" + cost.getText()+ "String_Node_Str"+ spell.getIdName()+ '.');
              game.getStack().counter(spell.getId(),source.getSourceId(),game);
              break;
            }
          }
        }
      }
    }
  }
  return true;
}

Fixed version (ground truth):
@Override public boolean apply(Game game,Ability source){
  Player controller=game.getPlayer(source.getControllerId());
  Permanent sourcePermanent=game.getPermanentOrLKIBattlefield(source.getSourceId());
  Spell spell=(Spell)game.getStack().getStackObject(targetPointer.getFirst(game,source));
  if (sourcePermanent != null && spell != null && controller != null) {
    Player spellController=game.getPlayer(spell.getControllerId());
    Cost cost=new ManaCostsImpl(spell.getSpellAbility().getManaCosts().getText());
    if (spellController != null) {
      for (      UUID playerId : game.getState().getPlayersInRange(source.getControllerId(),game)) {
        Player player=game.getPlayer(playerId);
        if (player != null && !player.equals(spellController)) {
          cost.clearPaid();
          if (cost.canPay(source,source.getSourceId(),player.getId(),game) && player.chooseUse(outcome,"String_Node_Str" + cost.getText() + "String_Node_Str"+ spell.getIdName()+ '?',source,game)) {
            if (cost.pay(source,game,source.getSourceId(),playerId,false,null)) {
              game.informPlayers(player.getLogName() + "String_Node_Str" + cost.getText()+ "String_Node_Str"+ spell.getIdName()+ '.');
              game.getStack().counter(spell.getId(),source.getSourceId(),game);
              break;
            }
          }
        }
      }
    }
  }
  return true;
}
Program: 157694
Project: 157694
Buggy source:
@Override public boolean checkTrigger(GameEvent event,Game game){
  if (event == null) {
    return false;
  }
  Permanent permanent=game.getPermanentOrLKIBattlefield(event.getTargetId());
  if (permanent == null) {
    return false;
  }
  if (permanent.getControllerId() == this.getControllerId()) {
    return false;
  }
  return true;
}

Fixed version (ground truth):
@Override public boolean checkTrigger(GameEvent event,Game game){
  if (event == null) {
    return false;
  }
  Permanent permanent=game.getPermanentOrLKIBattlefield(event.getTargetId());
  if (permanent == null) {
    return false;
  }
  if (permanent.getControllerId().equals(this.getControllerId())) {
    return false;
  }
  return true;
}
Program: 157695
Project: 157695
Buggy source:
@Override public boolean apply(Game game,Ability source){
  Permanent perm=game.getPermanent(source.getSourceId());
  if (perm == null) {
    return false;
  }
  for (  Card card : game.getExile().getAllCards(game)) {
    if (filter.match(card,game) && card.getOwnerId() == perm.getControllerId()) {
      for (      Ability ability : card.getAbilities()) {
        if (ability instanceof ActivatedAbility) {
          ActivatedAbilityImpl copyAbility=(ActivatedAbilityImpl)ability.copy();
          copyAbility.setMaxActivationsPerTurn(1);
          perm.addAbility(copyAbility,card.getId(),game);
        }
      }
    }
  }
  return true;
}

Fixed version (ground truth):
@Override public boolean apply(Game game,Ability source){
  Permanent perm=game.getPermanent(source.getSourceId());
  if (perm == null) {
    return false;
  }
  for (  Card card : game.getExile().getAllCards(game)) {
    if (filter.match(card,game) && Objects.equals(card.getOwnerId(),perm.getControllerId())) {
      for (      Ability ability : card.getAbilities()) {
        if (ability instanceof ActivatedAbility) {
          ActivatedAbilityImpl copyAbility=(ActivatedAbilityImpl)ability.copy();
          copyAbility.setMaxActivationsPerTurn(1);
          perm.addAbility(copyAbility,card.getId(),game);
        }
      }
    }
  }
  return true;
}
Program: 157696
Project: 157696
Buggy source:
@Override public boolean applies(GameEvent event,Ability source,Game game){
  Player controller=game.getPlayer(source.getControllerId());
  DamageEvent damageEvent=(DamageEvent)event;
  Permanent targetPermanent=game.getPermanent(source.getFirstTarget());
  if (controller != null && targetPermanent != null) {
    return (damageEvent.isCombatDamage() && controller.getId() == damageEvent.getTargetId() && targetPermanent.getId() == damageEvent.getSourceId());
  }
  return false;
}

Fixed version (ground truth):
@Override public boolean applies(GameEvent event,Ability source,Game game){
  Player controller=game.getPlayer(source.getControllerId());
  DamageEvent damageEvent=(DamageEvent)event;
  Permanent targetPermanent=game.getPermanent(source.getFirstTarget());
  if (controller != null && targetPermanent != null) {
    return (damageEvent.isCombatDamage() && Objects.equals(controller.getId(),damageEvent.getTargetId()) && Objects.equals(targetPermanent.getId(),damageEvent.getSourceId()));
  }
  return false;
}
Program: 157697
Project: 157697
Buggy source:
@Override public boolean checkTrigger(GameEvent event,Game game){
  Permanent source=game.getPermanent(event.getSourceId());
  if (source != null && source.getId() == this.getSourceId()) {
    UUID defenderId=game.getCombat().getDefenderId(event.getSourceId());
    this.getEffects().get(0).setTargetPointer(new FixedTarget(defenderId));
    return true;
  }
  return false;
}

Fixed version (ground truth):
@Override public boolean checkTrigger(GameEvent event,Game game){
  Permanent source=game.getPermanent(event.getSourceId());
  if (source != null && source.getId().equals(this.getSourceId())) {
    UUID defenderId=game.getCombat().getDefenderId(event.getSourceId());
    this.getEffects().get(0).setTargetPointer(new FixedTarget(defenderId));
    return true;
  }
  return false;
}
Program: 157700
Project: 157700
Buggy source:
@Override public void watch(GameEvent event,Game game){
  if (event.getType() == GameEvent.EventType.DECLARE_ATTACKERS_STEP_PRE) {
    Player activePlayer=game.getPlayer(game.getActivePlayerId());
    for (    Permanent permanent : game.getBattlefield().getAllActivePermanents(activePlayer.getId())) {
      if (permanent.isCreature()) {
        for (        UUID defender : game.getCombat().getDefenders()) {
          if (defender != activePlayer.getId()) {
            if (permanent.canAttack(defender,game)) {
              if (!game.getContinuousEffects().checkIfThereArePayCostToAttackBlockEffects(GameEvent.getEvent(GameEvent.EventType.DECLARE_ATTACKER,defender,permanent.getId(),permanent.getControllerId()),game)) {
                this.couldAttackThisTurnCreatures.add(new MageObjectReference(permanent.getId(),game));
                break;
              }
            }
          }
        }
      }
    }
  }
}

Fixed version (ground truth):
@Override public void watch(GameEvent event,Game game){
  if (event.getType() == GameEvent.EventType.DECLARE_ATTACKERS_STEP_PRE) {
    Player activePlayer=game.getPlayer(game.getActivePlayerId());
    for (    Permanent permanent : game.getBattlefield().getAllActivePermanents(activePlayer.getId())) {
      if (permanent.isCreature()) {
        for (        UUID defender : game.getCombat().getDefenders()) {
          if (!defender.equals(activePlayer.getId())) {
            if (permanent.canAttack(defender,game)) {
              if (!game.getContinuousEffects().checkIfThereArePayCostToAttackBlockEffects(GameEvent.getEvent(GameEvent.EventType.DECLARE_ATTACKER,defender,permanent.getId(),permanent.getControllerId()),game)) {
                this.couldAttackThisTurnCreatures.add(new MageObjectReference(permanent.getId(),game));
                break;
              }
            }
          }
        }
      }
    }
  }
}
Program: 157701
Project: 157701
Buggy source:
@Override public boolean applies(GameEvent event,Ability source,Game game){
  Player controller=game.getPlayer(source.getControllerId());
  DamageEvent damageEvent=(DamageEvent)event;
  Permanent targetPermanent=game.getPermanent(source.getFirstTarget());
  if (controller != null && targetPermanent != null) {
    return targetPermanent.getId() == damageEvent.getTargetId();
  }
  return false;
}

Fixed version (ground truth):
@Override public boolean applies(GameEvent event,Ability source,Game game){
  Player controller=game.getPlayer(source.getControllerId());
  DamageEvent damageEvent=(DamageEvent)event;
  Permanent targetPermanent=game.getPermanent(source.getFirstTarget());
  if (controller != null && targetPermanent != null) {
    return targetPermanent.getId().equals(damageEvent.getTargetId());
  }
  return false;
}
Program: 157702
Project: 157702
Buggy source:
@Override public boolean apply(Game game,Ability source){
  Player targetPlayer=game.getPlayer(targetPointer.getFirst(game,source));
  if (targetPlayer != null && targetPlayer.isInGame()) {
    for (    Permanent permanent : game.getBattlefield().getAllActivePermanents(filter,source.getControllerId(),game)) {
      if (permanent != null && permanent.getId() != source.getSourceId()) {
        permanent.changeControllerId(targetPlayer.getId(),game);
      }
    }
  }
 else {
    discard();
  }
  return true;
}

Fixed version (ground truth):
@Override public boolean apply(Game game,Ability source){
  Player targetPlayer=game.getPlayer(targetPointer.getFirst(game,source));
  if (targetPlayer != null && targetPlayer.isInGame()) {
    for (    Permanent permanent : game.getBattlefield().getAllActivePermanents(filter,source.getControllerId(),game)) {
      if (permanent != null && !permanent.getId().equals(source.getSourceId())) {
        permanent.changeControllerId(targetPlayer.getId(),game);
      }
    }
  }
 else {
    discard();
  }
  return true;
}
Program: 157703
Project: 157703
Buggy source:
@Override public boolean checkTrigger(GameEvent event,Game game){
  StackObject stackObject=game.getStack().getStackObject(event.getSourceId());
  if (stackObject != null) {
    if (game.getOpponents(this.getControllerId()).contains(stackObject.getControllerId())) {
      Permanent permanent=game.getPermanent(getSourceId());
      if (permanent != null) {
        if (permanent.getControllerId() == event.getPlayerId()) {
          return true;
        }
      }
    }
  }
  return false;
}

Fixed version (ground truth):
@Override public boolean checkTrigger(GameEvent event,Game game){
  StackObject stackObject=game.getStack().getStackObject(event.getSourceId());
  if (stackObject != null) {
    if (game.getOpponents(this.getControllerId()).contains(stackObject.getControllerId())) {
      Permanent permanent=game.getPermanent(getSourceId());
      if (permanent != null) {
        if (Objects.equals(permanent.getControllerId(),event.getPlayerId())) {
          return true;
        }
      }
    }
  }
  return false;
}