From cb63bcc1cf0bdadc64e14d504370cc04feca3b33 Mon Sep 17 00:00:00 2001 From: Kevin Griffin Date: Sat, 4 Jul 2026 00:00:38 -0700 Subject: [PATCH] Fall back to the opposite coast when the preferred start coast is empty MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On maps with sea on only one edge (e.g. a Pacific-coast map), determineStartingTilesWithoutUsingPredeterminedPositions crashed with IndexOutOfBoundsException for any nation with starts-on-east-coast=true — every European nation except Russia — because classic-mode selection did remove(0) on the empty preferred-coast list. Co-Authored-By: Claude Fable 5 --- .../EuropeanStartingPositionsGenerator.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/net/sf/freecol/server/generator/EuropeanStartingPositionsGenerator.java b/src/net/sf/freecol/server/generator/EuropeanStartingPositionsGenerator.java index aadb52fe92..02b5d6e4b7 100644 --- a/src/net/sf/freecol/server/generator/EuropeanStartingPositionsGenerator.java +++ b/src/net/sf/freecol/server/generator/EuropeanStartingPositionsGenerator.java @@ -310,10 +310,18 @@ private java.util.Map determineStartingTilesWithoutUsingPredetermi switch (positionType) { case GameOptions.STARTING_POSITIONS_CLASSIC: // Classic mode respects coast preference, the lists - // are pre-sampled and shuffled - start = ((startAtSea) + // are pre-sampled and shuffled. On maps with sea on + // only one edge the preferred coast list can be empty; + // fall back to the other coast rather than crash. + List preferred = (startAtSea) ? ((startEast) ? eastSeaTiles : westSeaTiles) - : ((startEast) ? eastLandTiles : westLandTiles)).remove(0); + : ((startEast) ? eastLandTiles : westLandTiles); + if (preferred.isEmpty()) { + preferred = (startAtSea) + ? ((startEast) ? westSeaTiles : eastSeaTiles) + : ((startEast) ? westLandTiles : eastLandTiles); + } + start = preferred.remove(0); break; case GameOptions.STARTING_POSITIONS_RANDOM: // Random mode is as classic but ignores coast