Skip to content

Fix StackOverflowError from getOutputPath()/getOutputName() recursion - #93

Closed
elharo wants to merge 1 commit into
masterfrom
fix-92-getOutputPath-recursion
Closed

elharo wants to merge 1 commit into
masterfrom
fix-92-getOutputPath-recursion

Conversation

@elharo

@elharo elharo commented Oct 11, 2026

Copy link
Copy Markdown
Contributor

What

MavenReport.getOutputPath() and the deprecated getOutputName() are both default methods that delegate to each other. An implementation that overrides neither recurses forever and fails with StackOverflowError as soon as the report output path is resolved.

Why

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

How

getOutputPath() now fails fast with an UnsupportedOperationException when neither method is overridden. It still delegates to getOutputName() when that method is overridden, so implementations overriding either method keep working:

  • override getOutputPath() only -> getOutputName() delegates to it
  • override getOutputName() only -> getOutputPath() delegates to it
  • override neither -> clear UnsupportedOperationException, no recursion

The override check uses getClass().getMethod("getOutputName").isDefault(), which avoids changing either method's signature or default-ness.

Tests

Added four tests to MavenReportTest covering the full matrix (StubReport was factored out so the output path/name can be left unimplemented). The two "neither implemented" tests fail with StackOverflowError before the fix and pass afterwards; the two delegation tests guard the existing behavior.

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

mvn verify (checkstyle, RAT, tests) passes.

Note: the analogous mutual recursion between the default generate(...) overloads is tracked separately in #91.

Fixes #92


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

Both are default methods that delegate to each other. An implementation
overriding neither recursed forever and failed with StackOverflowError
when the report output path was resolved.

getOutputPath() now fails fast with UnsupportedOperationException when
neither method is overridden, while still delegating to getOutputName()
for implementations that override it. Implementations overriding either
method keep working unchanged.

Fixes #92
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 getOutputPath()/getOutputName() causes StackOverflowError

1 participant