RFR: 8336332: Rework tests to avoid unrelated stderr output

Michael Strauß mstrauss at openjdk.org
Fri Sep 12 18:18:26 UTC 2025


On Thu, 11 Sep 2025 22:09:10 GMT, Andy Goryachev <angorya at openjdk.org> wrote:

> This PR removes unrelated `stderr` output in the headful test logs by redirecting it to an in-memory buffer.  Exceptions found in the buffer can be checked against the expected list.
> 
> In the case when any mismatch is detected, whether the type or the number of exceptions of particular type, the accumulated buffer gets dumped to `stderr` (without failing the test).
> 
> ## How To
> 
> To redirect stderr and later check the exceptions, surround your code with
> 
> `ErrorLoggingUtility.suppressStderr()` and either `ErrorLoggingUtility.checkStderr()` or `ErrorLoggingUtility.checkAndRestoreStderr()`.
> 
> To simply undo redirection, without checking, call  `ErrorLoggingUtility.restoreStderr()`.
> 
> To add the check to all the tests in the file, one can call the above mentioned methods inside  `@BeforeEach` and `@AfterEach`.
> 
> ## Miscellaneous
> 
> For reviewers' convenience, the first commit contains the main change, the second fixes the misspelt name of the utility class, the rest are trivial.
> 
> ## Questions
> 
> - should we fail the current test with `Assertions.fail()` in case of a mismatch?

The `ErrorLoggingUtility` class manages static state, and requires users to follow a protocol to avoid messing up its internal state. Have you considered using a try-with-resources scope to make the API easier to use, for example:


try (var util = ErrorLoggingUtility.suppressStdErr()) {
    // test something
    // ...
    //

    util.checkWarning(NullPointerException.class);
} // internal state is restored at the end of the block

-------------

PR Comment: https://git.openjdk.org/jfx/pull/1897#issuecomment-3286382236


More information about the openjfx-dev mailing list