elharo opened a new pull request, #94:
URL: https://github.com/apache/maven-reporting-api/pull/94
## 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](https://www.apache.org/licenses/LICENSE-2.0)
check one of the following:
- [x] I hereby declare this contribution to be licensed under the [Apache
License Version 2.0, January 2004](https://www.apache.org/licenses/LICENSE-2.0)
- [ ] I hereby declare that I have filed an [Apache Individual Contributor
License Agreement](https://www.apache.org/licenses/icla.pdf).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]