Skip to content

Prevent RecursionMax stack exhaustion - #97

Closed
krotname wants to merge 1 commit into
mainfrom
codex/fix-recursionmax-crash-on-list-inputs
Closed

Prevent RecursionMax stack exhaustion#97
krotname wants to merge 1 commit into
mainfrom
codex/fix-recursionmax-crash-on-list-inputs

Conversation

@krotname

@krotname krotname commented Aug 1, 2026

Copy link
Copy Markdown
Owner

Motivation

  • recursionMax(List<Integer>) previously used unbounded recursion and attempted to remove elements from the input List, which can throw UnsupportedOperationException for fixed-size/immutable lists and can cause StackOverflowError on very large lists.
  • Apply a minimal, low-risk fix that preserves the method behavior and existing test expectations while eliminating the availability/crash risk.

Description

  • Route recursionMax(List<Integer>) through the existing iterative max(List<Integer>) implementation so the method no longer mutates the caller's list or performs unbounded recursion.
  • The private recursive helper is no longer used and recursionMax returns the same values as max for null, empty, single-element, and multi-element lists.
  • Add a regression test shouldHandleLargeListsWithoutExhaustingTheStack that uses Collections.nCopies(100_000, 42) to verify large caller-controlled lists are handled without stack exhaustion and without mutating the input.

Testing

  • Ran mvn -Dtest=other.RecursionMaxTest test and the modified RecursionMax tests passed.
  • Ran full mvn verify and the build completed successfully with 598 tests passing and Checkstyle, PMD, JaCoCo, and SpotBugs gates all passing.
  • No automated test failures were observed after the change.

Codex Task

@krotname

krotname commented Aug 1, 2026

Copy link
Copy Markdown
Owner Author

Superseded by the validated combined merge in #115: #115

@krotname krotname closed this Aug 1, 2026
@krotname
krotname deleted the codex/fix-recursionmax-crash-on-list-inputs branch August 1, 2026 02:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant