From 577719fad0aa53de144f58ddc6bac8a16a570169 Mon Sep 17 00:00:00 2001 From: asvitkine Date: Tue, 28 May 2024 00:05:09 -0400 Subject: [PATCH] Fix NPE in PlacementPicker. (#12602) Make placements field never null. Fixes https://github.com/triplea-game/triplea/issues/12589. --- .../src/main/java/tools/map/making/PlacementPicker.java | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/game-app/game-core/src/main/java/tools/map/making/PlacementPicker.java b/game-app/game-core/src/main/java/tools/map/making/PlacementPicker.java index 03581b8420..94b5991ee3 100644 --- a/game-app/game-core/src/main/java/tools/map/making/PlacementPicker.java +++ b/game-app/game-core/src/main/java/tools/map/making/PlacementPicker.java @@ -153,7 +153,7 @@ private final class PlacementPickerFrame extends JFrame { private final Image image; private final JLabel locationLabel = new JLabel(); private Map> polygons = new HashMap<>(); - private Map, Boolean>> placements; + private Map, Boolean>> placements = new HashMap<>(); private List currentPlacements; private boolean currentOverflowToLeft = false; private String currentCountry; @@ -569,7 +569,7 @@ private void mouseEvent(final Point point, final boolean ctrlDown, final boolean if (!rightMouse && !ctrlDown) { currentCountry = ToolsUtil.findTerritoryName(point, polygons).orElse("there be dragons"); // If there isn't an existing array, create one - if (placements == null || placements.get(currentCountry) == null) { + if (placements.get(currentCountry) == null) { currentPlacements = new ArrayList<>(); currentOverflowToLeft = false; } else { @@ -583,10 +583,6 @@ private void mouseEvent(final Point point, final boolean ctrlDown, final boolean } } else if (ctrlDown) { if (currentPlacements != null) { - // If there isn't an existing hashmap, create one - if (placements == null) { - placements = new HashMap<>(); - } placements.put(currentCountry, Tuple.of(currentPlacements, currentOverflowToLeft)); currentPlacements = new ArrayList<>(); log.info("done:" + currentCountry);