On Fri, 12 Sep 2025 18:24:08 GMT, Andy Goryachev <ango...@openjdk.org> wrote:
> Good point. It already has a static state (error log record), and on top of > that try with resources will not work in the bulk use case of `@BeforeEach` > and `@AfterEach` Why wouldn't it work? If you _really_ need to, you can store the `AutoClosable` in `@BeforeEach` and then call the close method in `@AfterEach`. But I would also prefer to not scatter around code in before-each and after-each methods, but to have each test be as stand-alone as possible, especially when it comes to scoping. Whether `ErrorLoggingUtility` has static state is also immaterial (that would only be important if tests were to be run in parallel), what matters is the API. Using an auto-closable scope has the following advantages: 1. Using the tool is easy, as you can only call methods that are applicable for the state of the test. If you want to check the log output, you need to have an active scope instance. 2. It can't be misused, as you can't call methods in the wrong order. 3. The static state will always be well-defined. Yes, it's only a test utility, but the API is really suboptimal no matter how I look at it. ------------- PR Comment: https://git.openjdk.org/jfx/pull/1897#issuecomment-3286467188