From 05b986303cbf5e548c246873a9381d7229ea7061 Mon Sep 17 00:00:00 2001 From: Hans Mackowiak Date: Mon, 19 Jan 2026 10:55:51 +0100 Subject: [PATCH 1/2] CardEdition: cleanup Constructor --- .../src/main/java/forge/card/CardEdition.java | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/forge-core/src/main/java/forge/card/CardEdition.java b/forge-core/src/main/java/forge/card/CardEdition.java index 5046fdfd5d0..872187d0338 100644 --- a/forge-core/src/main/java/forge/card/CardEdition.java +++ b/forge-core/src/main/java/forge/card/CardEdition.java @@ -273,7 +273,7 @@ public String getScriptOverride() { */ public static final String UNKNOWN_CODE = "???"; public static final String UNKNOWN_SET_NAME = "UNKNOWN"; - public static final CardEdition UNKNOWN = new CardEdition("1990-01-01", UNKNOWN_CODE, "??", Type.UNKNOWN, UNKNOWN_SET_NAME, FoilType.NOT_SUPPORTED, new EditionEntry[]{}); + public static final CardEdition UNKNOWN = new CardEdition("1990-01-01", UNKNOWN_CODE, "??", Type.UNKNOWN, UNKNOWN_SET_NAME, FoilType.NOT_SUPPORTED); private Date date; private String code; private String code2; @@ -332,16 +332,6 @@ private CardEdition(ListMultimap cardMap, ListMultimap tokens) { - List cardsList = Arrays.asList(cards); - this.cardMap = ArrayListMultimap.create(); - this.cardMap.replaceValues("cards", cardsList); - this.cardsInSet = new ArrayList<>(cardsList); - Collections.sort(cardsInSet); - this.tokenMap = tokens; - this.customPrintSheetsToParse = new HashMap<>(); - } - /** * Instantiates a new card set. * @@ -355,8 +345,8 @@ private CardEdition(EditionEntry[] cards, ListMultimap tok * @param name the name of the set * @param cards the cards in the set */ - private CardEdition(String date, String code, String code2, Type type, String name, FoilType foil, EditionEntry[] cards) { - this(cards, ArrayListMultimap.create()); + private CardEdition(String date, String code, String code2, Type type, String name, FoilType foil) { + this(ArrayListMultimap.create(), ArrayListMultimap.create(), new HashMap<>()); this.code = code; this.code2 = code2; this.type = type; @@ -916,8 +906,7 @@ public void append(CardEdition.Collection C){ //Append custom editions this.add(E); initAliases(E); //Made a method in case the system changes, so it's consistent. } - CardEdition customBucket = new CardEdition("2990-01-01", "USER", "USER", - Type.CUSTOM_SET, "USER", FoilType.NOT_SUPPORTED, new EditionEntry[]{}); + CardEdition customBucket = new CardEdition("2990-01-01", "USER", "USER", Type.CUSTOM_SET, "USER", FoilType.NOT_SUPPORTED); this.add(customBucket); initAliases(customBucket); this.lock = true; //Consider it initialized and prevent from writing any more data. From f75d8c27189b064b1dd121ce784e84afcb3d89d4 Mon Sep 17 00:00:00 2001 From: fernando Date: Fri, 16 Jan 2026 09:30:01 +0100 Subject: [PATCH 2/2] Fix race condition in CardEdition.getCardInSet() --- .../src/main/java/forge/card/CardEdition.java | 23 ++++++++----------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/forge-core/src/main/java/forge/card/CardEdition.java b/forge-core/src/main/java/forge/card/CardEdition.java index 872187d0338..f9ce44bff7e 100644 --- a/forge-core/src/main/java/forge/card/CardEdition.java +++ b/forge-core/src/main/java/forge/card/CardEdition.java @@ -328,6 +328,13 @@ private CardEdition(ListMultimap cardMap, ListMultimap(cardMap.values()); Collections.sort(cardsInSet); + this.cardsInSetLookupMap = cardsInSet.stream().collect( + Multimaps.toMultimap( + e -> e.name, + e -> e, + MultimapBuilder.treeKeys(String.CASE_INSENSITIVE_ORDER).arrayListValues()::build + ) + ); this.tokenMap = tokens; this.customPrintSheetsToParse = customPrintSheetsToParse; } @@ -343,7 +350,6 @@ private CardEdition(ListMultimap cardMap, ListMultimap()); @@ -409,7 +415,7 @@ public List getAllCardsInSet() { return cardsInSet; } - private ListMultimap cardsInSetLookupMap = null; + private final ListMultimap cardsInSetLookupMap; /** * Get all the CardInSet instances with the input card name. @@ -417,17 +423,8 @@ public List getAllCardsInSet() { * @return A List of all the CardInSet instances for a given name. * If not found, an Empty sequence (view) will be returned instead! */ - public List getCardInSet(String cardName){ - if (cardsInSetLookupMap == null) { - // initialise - cardsInSetLookupMap = Multimaps.newListMultimap(new TreeMap<>(String.CASE_INSENSITIVE_ORDER), Lists::newArrayList); - List cardsInSet = this.getAllCardsInSet(); - for (EditionEntry cis : cardsInSet){ - String key = cis.name; - cardsInSetLookupMap.put(key, cis); - } - } - return this.cardsInSetLookupMap.get(cardName); + public List getCardInSet(String cardName) { + return cardsInSetLookupMap.get(cardName); } public EditionEntry getCardFromCollectorNumber(String collectorNumber) {