|
From: Vest <no...@gi...> - 2026-07-22 12:25:41
|
Branch: refs/heads/master Home: https://github.com/PCGen/pcgen Commit: 996ec96075b4d9ab99627cd08f3f7b77ec3e08c1 https://github.com/PCGen/pcgen/commit/996ec96075b4d9ab99627cd08f3f7b77ec3e08c1 Author: Vest <Ve...@us...> Date: 2026-07-22 (Wed, 22 Jul 2026) Changed paths: M code/src/java/pcgen/cdom/enumeration/DisplayLocation.java M code/src/java/pcgen/cdom/enumeration/Region.java M code/src/java/pcgen/cdom/enumeration/Type.java Log Message: ----------- Region/Type: add value-equals; DisplayLocation: suppress identity-equals (#7638) * Region/Type: add value-equals; DisplayLocation: suppress identity-equals Fixes 3 EQ_COMPARETO_USE_OBJECT_EQUALS and 1 SI_INSTANCE_BEFORE_FINALS_ASSIGNED finding from SpotBugs. Region: add value-based equals/hashCode matching the case-insensitive compareTo. Region is used as a HashMap<Optional<Region>, ...> key in BioSet (ageMap, userMap) and .equals() is called directly in RegionFacet.matchesRegion. The intern map in getConstant() already made two getConstant(name) calls return the same instance, so the new equals/hashCode strengthens but does not change behaviour for any existing call site. Use String.CASE_INSENSITIVE_ORDER.compare(...) == 0 in equals to satisfy the find-sec-bugs IMPROPER_UNICODE rule (PR #7626 convention); hashCode folds via toLowerCase(Locale.ROOT) for a stable, locale-independent hash consistent with equals. Region: also rearrange the private static int ordinalCount = 0 above the NONE constant declaration to silence SI_INSTANCE_BEFORE_FINALS_ASSIGNED. JLS default-initialises primitive int to 0 before any field initialiser runs, so this is purely a static-layout cleanup. Type: add value-based equals/hashCode matching the case-sensitive compareTo. Type is used as HashSet<Type>/HashMap<Type, ...> across 8 production files. Since the intern map is CaseInsensitiveMap, two distinct Type instances with fieldNames differing only in case cannot exist, so case-sensitive equals matches compareTo and preserves existing behavior. DisplayLocation: identity-equals is already correct (singleton-by-construction via getConstant intern map, no .equals() callers, not used as a collection key). Method-level @SuppressFBWarnings on compareTo documents that explicitly. * Region/Type: document why equals/hashCode are value-based The original commit replaced the stale 'no equals/hashCode needed because TypeSafeConstant has a private constructor' comment with the actual equals/hashCode methods, but didn't leave anything in its place. Replaces the lost archival value with a short class-level Javadoc note explaining the design intent: equals/hashCode match compareTo (Comparable contract) and support use as a HashMap key (BioSet, RegionFacet, DataSet, GameMode, etc.). Captures the *why*, not the *what*, so future readers don't have to rediscover the contract reasoning from git history. To unsubscribe from these emails, change your notification settings at https://github.com/PCGen/pcgen/settings/notifications |