From b3eb6f536ab089298aca155bec01e60a090db80e Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Mon, 7 Sep 2015 07:42:19 +0200 Subject: [PATCH] Fixed some bugs causing null pointer or concurrent modification exceptions. --- Mage.Common/src/mage/view/GameView.java | 12 ++++++++---- Mage/src/mage/abilities/keyword/AwakenAbility.java | 4 ---- Mage/src/mage/abilities/keyword/RetraceAbility.java | 4 ---- Mage/src/mage/cards/CardsImpl.java | 11 +++++++---- 4 files changed, 15 insertions(+), 16 deletions(-) diff --git a/Mage.Common/src/mage/view/GameView.java b/Mage.Common/src/mage/view/GameView.java index 9f078a75b9..9e4f6a457d 100644 --- a/Mage.Common/src/mage/view/GameView.java +++ b/Mage.Common/src/mage/view/GameView.java @@ -133,10 +133,14 @@ public class GameView implements Serializable { new StackAbilityView(game, (StackAbility) stackObject, object.getName(), new CardView(new EmblemView(((Emblem) object), sourceCard)))); checkPaid(stackObject.getId(), ((StackAbility) stackObject)); } else { - StackAbility stackAbility = ((StackAbility) object); - stackAbility.newId(); - stack.put(stackObject.getId(), new CardView(((StackAbility) stackObject))); - checkPaid(stackObject.getId(), ((StackAbility) stackObject)); + if (object instanceof StackAbility) { + StackAbility stackAbility = ((StackAbility) object); + stackAbility.newId(); + stack.put(stackObject.getId(), new CardView(((StackAbility) stackObject))); + checkPaid(stackObject.getId(), ((StackAbility) stackObject)); + } else { + logger.fatal("Object can't be cast to StackAbility: " + object.getName() + " " + object.toString()); + } } } else { logger.error("Stack Object for stack ability not found: " + stackObject.getStackAbility().getRule()); diff --git a/Mage/src/mage/abilities/keyword/AwakenAbility.java b/Mage/src/mage/abilities/keyword/AwakenAbility.java index 27508fe957..0fbd77b142 100644 --- a/Mage/src/mage/abilities/keyword/AwakenAbility.java +++ b/Mage/src/mage/abilities/keyword/AwakenAbility.java @@ -51,7 +51,6 @@ import mage.target.Target; import mage.target.common.TargetControlledPermanent; import mage.target.targetpointer.FixedTarget; import mage.util.CardUtil; -import mage.watchers.Watcher; /** * @@ -70,9 +69,6 @@ public class AwakenAbility extends SpellAbility { this.getEffects().addAll(card.getSpellAbility().getEffects().copy()); this.getTargets().addAll(card.getSpellAbility().getTargets().copy()); this.getChoices().addAll(card.getSpellAbility().getChoices().copy()); - for (Watcher watcher : card.getSpellAbility().getWatchers()) { - this.getWatchers().add(watcher.copy()); - } this.spellAbilityType = SpellAbilityType.BASE_ALTERNATE; this.timing = card.getSpellAbility().getTiming(); this.addTarget(new TargetControlledPermanent(new FilterControlledLandPermanent(filterMessage))); diff --git a/Mage/src/mage/abilities/keyword/RetraceAbility.java b/Mage/src/mage/abilities/keyword/RetraceAbility.java index d210607856..2ce121fc25 100644 --- a/Mage/src/mage/abilities/keyword/RetraceAbility.java +++ b/Mage/src/mage/abilities/keyword/RetraceAbility.java @@ -34,7 +34,6 @@ import mage.constants.SpellAbilityType; import mage.constants.Zone; import mage.filter.common.FilterLandCard; import mage.target.common.TargetCardInHand; -import mage.watchers.Watcher; /** * @@ -49,9 +48,6 @@ public class RetraceAbility extends SpellAbility { this.getEffects().addAll(card.getSpellAbility().getEffects().copy()); this.getTargets().addAll(card.getSpellAbility().getTargets().copy()); this.getChoices().addAll(card.getSpellAbility().getChoices().copy()); - for (Watcher watcher : card.getSpellAbility().getWatchers()) { - this.getWatchers().add(watcher.copy()); - } this.spellAbilityType = SpellAbilityType.BASE_ALTERNATE; this.timing = card.getSpellAbility().getTiming(); diff --git a/Mage/src/mage/cards/CardsImpl.java b/Mage/src/mage/cards/CardsImpl.java index d7799289e2..ee177f0741 100644 --- a/Mage/src/mage/cards/CardsImpl.java +++ b/Mage/src/mage/cards/CardsImpl.java @@ -169,10 +169,13 @@ public class CardsImpl extends LinkedHashSet implements Cards, Serializabl @Override public Set getCards(FilterCard filter, UUID sourceId, UUID playerId, Game game) { Set cards = new LinkedHashSet<>(); - for (UUID card : this) { - boolean match = filter.match(game.getCard(card), sourceId, playerId, game); - if (match) { - cards.add(game.getCard(card)); + for (UUID cardId : this) { + Card card = game.getCard(cardId); + if (card != null) { + boolean match = filter.match(card, sourceId, playerId, game); + if (match) { + cards.add(game.getCard(cardId)); + } } } return cards;