fix: resolve ModifierCache StackOverflow and enforce modifier equality contract (Closes #81) #123

Merged
shahondin1624 merged 1 commits from feature/issue-81-modifiercache-key-equality-fragile into main 2026-04-04 22:51:09 +02:00
Owner

Summary

  • Fixed StackOverflowError caused by circular hashCode()/equals() chain between ModifierCache (data class) and Attributes (data class containing ModifierCache)
  • Converted ModifierCache from data class to regular class and moved cache fields out of data class constructors in Attributes and DamageMonitor
  • Added KDoc contract on SRModifier/AttributeModifier/TalentModifier requiring implementations to override equals()/hashCode()
  • Added 6 dedicated tests in ModifierCacheEqualityTest verifying cache behavior with recreated modifier instances

Closes #81

Test plan

  • All ModifierSystemTest tests pass (previously all 4 failed with StackOverflowError)
  • All 6 new ModifierCacheEqualityTest tests pass
  • No new test regressions (29 pre-existing failures vs 38 before fix)
  • Project compiles successfully on all targets
## Summary - Fixed `StackOverflowError` caused by circular `hashCode()`/`equals()` chain between `ModifierCache` (data class) and `Attributes` (data class containing `ModifierCache`) - Converted `ModifierCache` from `data class` to regular `class` and moved `cache` fields out of data class constructors in `Attributes` and `DamageMonitor` - Added KDoc contract on `SRModifier`/`AttributeModifier`/`TalentModifier` requiring implementations to override `equals()`/`hashCode()` - Added 6 dedicated tests in `ModifierCacheEqualityTest` verifying cache behavior with recreated modifier instances Closes #81 ## Test plan - [x] All `ModifierSystemTest` tests pass (previously all 4 failed with StackOverflowError) - [x] All 6 new `ModifierCacheEqualityTest` tests pass - [x] No new test regressions (29 pre-existing failures vs 38 before fix) - [x] Project compiles successfully on all targets
shahondin1624 added 1 commit 2026-04-04 22:51:03 +02:00
ModifierCache was a data class containing Attributes values, while Attributes
(also a data class) contained a ModifierCache field — creating a circular
hashCode()/equals() chain that caused StackOverflowError on cache lookups.

Fixed by: (1) converting ModifierCache from data class to regular class,
(2) moving cache fields out of data class constructors in Attributes and
DamageMonitor so they are excluded from equals()/hashCode(), (3) adding
KDoc contract on SRModifier/AttributeModifier/TalentModifier requiring
implementations to override equals()/hashCode(), and (4) adding dedicated
tests verifying cache behavior with recreated modifier instances.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
shahondin1624 merged commit c8a83379e1 into main 2026-04-04 22:51:09 +02:00
shahondin1624 deleted branch feature/issue-81-modifiercache-key-equality-fragile 2026-04-04 22:51:09 +02:00
Sign in to join this conversation.