* Fraying Sanity - Fixed possible null pointer exception.
@@ -33,16 +33,17 @@ import mage.abilities.Ability;
import mage.abilities.TriggeredAbilityImpl;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.AttachEffect;
-import mage.constants.Outcome;
import mage.abilities.keyword.EnchantAbility;
import mage.cards.Card;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
+import mage.constants.Outcome;
import mage.constants.Zone;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.events.GameEvent.EventType;
+import mage.game.permanent.Permanent;
import mage.players.Player;
import mage.target.TargetPlayer;
import mage.watchers.common.CardsPutIntoGraveyardWatcher;
@@ -132,7 +133,11 @@ class FrayingSanityEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
- Player enchantedPlayer = game.getPlayer(game.getPermanent(source.getSourceId()).getAttachedTo());
+ Permanent enchantment = game.getPermanentOrLKIBattlefield(source.getSourceId());
+ if (enchantment == null || enchantment.getAttachedTo() == null) {
+ return false;
+ }
+ Player enchantedPlayer = game.getPlayer(enchantment.getAttachedTo());
if (enchantedPlayer != null) {
CardsPutIntoGraveyardWatcher watcher = (CardsPutIntoGraveyardWatcher) game.getState().getWatchers().get(CardsPutIntoGraveyardWatcher.class.getSimpleName());
if (watcher != null) {
