Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some NPEs from Sentry #6746

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions forge-game/src/main/java/forge/game/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,7 @@
*/
package forge.game;

import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.HashBasedTable;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Multimap;
import com.google.common.collect.Table;
import com.google.common.collect.*;
import com.google.common.eventbus.EventBus;
import forge.GameCommand;
import forge.card.CardRarity;
Expand All @@ -49,7 +44,10 @@
import forge.game.zone.Zone;
import forge.game.zone.ZoneType;
import forge.trackable.Tracker;
import forge.util.*;
import forge.util.Aggregates;
import forge.util.IterableUtil;
import forge.util.MyRandom;
import forge.util.Visitor;
import forge.util.collect.FCollection;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.tuple.Pair;
Expand Down Expand Up @@ -593,7 +591,7 @@ public synchronized void setGameOver(GameEndReason reason) {
}

public Zone getZoneOf(final Card card) {
return card.getLastKnownZone();
return card == null ? null : card.getLastKnownZone();
}

public synchronized CardCollectionView getCardsIn(final ZoneType zone) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
package forge.gui.framework;

import java.awt.Container;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionAdapter;
import java.awt.event.MouseMotionListener;
import java.util.ArrayList;
import java.util.List;

import javax.swing.JPanel;

import forge.gui.MouseUtil;
import forge.localinstance.skin.FSkinProp;
import forge.toolbox.FSkin;
import forge.toolbox.FSkin.SkinCursor;
import forge.toolbox.FSkin.SkinnedLayeredPane;
import forge.view.FView;

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.ArrayList;
import java.util.List;

/**
* Package-private utilities for rearranging drag behavior using
* the draggable panels registered in FView.
Expand Down Expand Up @@ -291,7 +286,7 @@ private static void endRearrange() {
}

// Remove old cell if necessary, or, enforce rough bounds on new cell.
if (cellSrc.getDocs().size() == 0) {
if (cellSrc.getDocs().isEmpty()) {
fillGap();
FView.SINGLETON_INSTANCE.removeDragCell(cellSrc);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,6 @@
*/
package forge.screens.deckeditor;

import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.util.HashMap;
import java.util.Map.Entry;

import javax.swing.SwingUtilities;

import forge.Singletons;
import forge.deck.DeckBase;
import forge.deck.DeckProxy;
Expand All @@ -34,16 +27,17 @@
import forge.gui.framework.ICDoc;
import forge.item.InventoryItem;
import forge.itemmanager.ItemManager;
import forge.screens.deckeditor.controllers.ACEditorBase;
import forge.screens.deckeditor.controllers.CEditorConstructed;
import forge.screens.deckeditor.controllers.CEditorQuestCardShop;
import forge.screens.deckeditor.controllers.CProbabilities;
import forge.screens.deckeditor.controllers.CStatistics;
import forge.screens.deckeditor.controllers.DeckController;
import forge.screens.deckeditor.controllers.*;
import forge.screens.deckeditor.views.*;
import forge.screens.match.controllers.CDetailPicture;
import forge.util.ItemPool;

import javax.swing.*;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.util.HashMap;
import java.util.Map.Entry;

/**
* Constructs instance of deck editor UI controller, used as a single point of
* top-level control for child UIs. Tasks targeting the view of individual
Expand Down Expand Up @@ -184,6 +178,10 @@ private <T extends InventoryItem> void moveSelectedItems(final ItemManager<T> it

@SuppressWarnings("unchecked")
public void addSelectedCards(final boolean toAlternate, final int number) {
if (childController == null || childController.getCatalogManager() == null) {
return;
}

moveSelectedItems(childController.getCatalogManager(), new _MoveAction() {
@Override public <T extends InventoryItem> void move(final Iterable<Entry<T, Integer>> items) {
((ACEditorBase<T, ?>)childController).addItems(items, toAlternate);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package forge.screens.match.controllers;

import com.google.common.collect.Iterables;
import org.apache.commons.lang3.StringUtils;

import forge.game.GameEntityView;
import forge.game.card.CardView;
import forge.game.card.CardView.CardStateView;
Expand All @@ -12,6 +10,7 @@
import forge.screens.match.views.VCombat;
import forge.util.Lang;
import forge.util.collect.FCollection;
import org.apache.commons.lang3.StringUtils;

/**
* Controls the combat panel in the match UI.
Expand Down Expand Up @@ -79,13 +78,14 @@ private static String getCombatDescription(final CombatView localCombat, final G
display.append("\n");
if (defender instanceof CardView) {
PlayerView controller = ((CardView) defender).getController();
if (controller == null)
if (controller == null) {
//shouldn't be null but display card's + controller ie Black Knight's controller
display.append(Lang.getInstance().getPossesive(defender.getName())).append(" controller");
else
} else {
display.append(Lang.getInstance().getPossesive(controller.getName())).append(" ");
}
}
display.append(defender).append(" is attacked by:\n");
display.append(defender).append(" is attacked by:\n`");

// Associate Bands, Attackers Blockers
boolean previousBand = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,9 @@ public CCombat getLayoutControl() {

//========= Observer update methods

/** @param s0 &emsp; {@link java.lang.String} */
public void updateCombat(final int cntAttackers, final String desc) {
// No need to update this unless it's showing
if (!this.equals(parentCell.getSelected())) { return; }
if (parentCell == null || !this.equals(parentCell.getSelected())) { return; }

tab.setText(cntAttackers > 0 ? (Localizer.getInstance().getMessage("lblCombatTab") + " : " + cntAttackers) : Localizer.getInstance().getMessage("lblCombatTab"));
tar.setText(desc);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,7 @@
*/
package forge.screens.match.views;

import java.util.ArrayList;
import java.util.List;

import javax.swing.JPanel;

import com.google.common.collect.Lists;

import forge.game.GameLogEntry;
import forge.game.GameLogEntryType;
import forge.game.GameView;
Expand All @@ -40,6 +34,10 @@
import forge.util.Localizer;
import net.miginfocom.swing.MigLayout;

import javax.swing.*;
import java.util.ArrayList;
import java.util.List;

/**
* Assembles Swing components of game log report.
*
Expand Down Expand Up @@ -135,7 +133,7 @@ public void updateConsole() {
}

private boolean isGameLogConsoleVisible() {
return parentCell.getSelected().equals(this);
return parentCell != null && parentCell.getSelected().equals(this);
}

private void resetDisplayIfNewGame(final GameView model) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,6 @@
*/
package forge.screens.match.views;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.image.BufferedImage;

import javax.swing.JCheckBoxMenuItem;
import javax.swing.JPopupMenu;
import javax.swing.ScrollPaneConstants;
import javax.swing.SwingUtilities;
import javax.swing.border.EmptyBorder;

import forge.CachedCardImage;
import forge.game.GameView;
import forge.game.card.CardView.CardStateView;
Expand All @@ -52,6 +37,13 @@
import forge.util.collect.FCollectionView;
import net.miginfocom.swing.MigLayout;

import javax.swing.*;
import javax.swing.border.EmptyBorder;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.image.BufferedImage;

/**
* Assembles Swing components of stack report.
*
Expand Down Expand Up @@ -123,7 +115,7 @@ public void updateStack() {
tab.setText(Localizer.getInstance().getMessage("lblStack") + " : " + items.size());

// No need to update the rest unless it's showing
if (!parentCell.getSelected().equals(this)) { return; }
if (parentCell == null || !parentCell.getSelected().equals(this)) { return; }

hoveredItem = null;
scroller.removeAll();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,6 @@
*/
package forge.view.arcane;

import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;
import java.util.ArrayList;
import java.util.List;

import javax.swing.SwingUtilities;

import forge.game.card.CardView;
import forge.gui.FThreads;
import forge.screens.match.CMatchUI;
Expand All @@ -35,6 +25,14 @@
import forge.toolbox.special.CardZoomer;
import forge.view.arcane.util.CardPanelMouseListener;

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;
import java.util.ArrayList;
import java.util.List;

/**
* Manages mouse events and common functionality for CardPanel containing
* components.
Expand Down Expand Up @@ -278,7 +276,7 @@ public CardPanel addCard(final CardView card) {

public final CardPanel getCardPanel(final int gameCardID) {
for (final CardPanel panel : this.getCardPanels()) {
if (panel.getCard().getId() == gameCardID) {
if (panel.getCard() != null && panel.getCard().getId() == gameCardID) {
return panel;
}
}
Expand Down
Loading