Skip to content

Fix support for JVM shutdown hooks #4474

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 29, 2025

Conversation

marcphilipp
Copy link
Member

@marcphilipp marcphilipp commented Apr 11, 2025

Overview

When the ConsoleLauncher is executed via its main method while
passing arguments via its -cp option, it no longer closes the custom
class loader it creates eagerly after test discovery or execution.
Instead, it relies on the JVM shutdown to free up any resource held by
the class loader which is initiated by calling System.exit directly
afterward.

Fixes #4469.


I hereby agree to the terms of the JUnit Contributor License Agreement.


Definition of Done

When the `ConsoleLauncher` is executed via its `main` method while
passing arguments via its `-cp` option, it no longer closes the custom
class loader it creates eagerly after test discovery or execution.
Instead, it relies on the JVM shutdown to free up any resource held by
the class loader which is initiated by calling `System.exit` directly
afterward.

Fixes #4469.
@marcphilipp marcphilipp self-assigned this Apr 11, 2025
@sormuras
Copy link
Member

Could CustomClassLoaderCloseStrategy.CLOSE_AFTER_CALLING_LAUNCHER be the default? This would keep the amount of changes in existing tests lower. Only the real main path with the terminating System.exit(result) call would use CustomClassLoaderCloseStrategy.KEEP_OPEN.

@marcphilipp
Copy link
Member Author

Could CustomClassLoaderCloseStrategy.CLOSE_AFTER_CALLING_LAUNCHER be the default? This would keep the amount of changes in existing tests lower. Only the real main path with the terminating System.exit(result) call would use CustomClassLoaderCloseStrategy.KEEP_OPEN.

Done in 1ba6fd7

@marcphilipp marcphilipp marked this pull request as ready for review April 29, 2025 10:29
@marcphilipp marcphilipp merged commit 9ea0697 into main Apr 29, 2025
17 of 18 checks passed
@marcphilipp marcphilipp deleted the marc/4469-fix-shutdown-hook-support branch April 29, 2025 10:40
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.

Shutdown hook fails with ClassNotFoundException in junit-platform-console-standalone
2 participants