Skip to content

Fix StackOverflowError from default generate() overload recursion - #94

Closed
elharo wants to merge 1 commit into
masterfrom
fix-91-generate-recursion
Closed

elharo wants to merge 1 commit into
masterfrom
fix-91-generate-recursion

Conversation

@elharo

@elharo elharo commented Oct 11, 2026

Copy link
Copy Markdown
Contributor

What

MavenReport.generate(Sink, Locale) and generate(Sink, SinkFactory, Locale) are both default methods that delegate to each other. An implementation that overrides neither recurses forever and fails with StackOverflowError when a report is generated.

Why

Because both overloads are default, a MavenReport implementation may override neither (the interface still requires the other abstract methods), so the recursion is reachable from ordinary report generation and crashes instead of reporting a clear error. See #91.

How

The multi-page generate(Sink, SinkFactory, Locale) now fails fast with a MavenReportException when neither overload is overridden. It still delegates to the deprecated generate(Sink, Locale) when that is overridden, so implementations overriding either overload keep working:

  • override generate(Sink, Locale) only -> multi-page call delegates to it with a null factory
  • override generate(Sink, SinkFactory, Locale) only -> single-page call delegates to it
  • override neither -> clear MavenReportException, no recursion

The override check uses getClass().getMethod("generate", Sink.class, Locale.class).isDefault(), which avoids changing either method's signature or default-ness. MavenReportException is used (rather than an unchecked exception) so the failure flows through the existing generate(...) error handling.

Tests

Added two tests to MavenReportTest using a report that overrides neither overload. Both fail with StackOverflowError before the fix and pass afterwards; the two pre-existing delegation tests guard the unchanged behavior.

Tests run: 4, Failures: 0, Errors: 0, Skipped: 0

mvn verify (checkstyle, RAT, tests) passes.

Fixes #91


To make clear that you license your contribution under
the Apache License Version 2.0, January 2004
check one of the following:

Both generate(Sink, Locale) and generate(Sink, SinkFactory, Locale) are
default methods that delegate to each other. An implementation
overriding neither recursed forever and failed with StackOverflowError
during report generation.

The multi-page generate(Sink, SinkFactory, Locale) now fails fast with a
MavenReportException when neither overload is overridden, while still
delegating to generate(Sink, Locale) for implementations that override
it. Implementations overriding either overload keep working unchanged.

Fixes #91
@elharo
elharo marked this pull request as draft October 11, 2026 18:24
@slawekjaranowski

This comment was marked as off-topic.

@elharo elharo closed this Oct 20, 2026
@elharo
elharo deleted the fix-91-generate-recursion branch October 20, 2026 10:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

High: mutual recursion between default generate() overloads causes StackOverflowError

2 participants