Skip to content
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

Properly handle UnsupportedOperationException thrown by Thread::stop in JDK 20+ #391

Closed
kriegaex opened this issue Nov 9, 2023 · 3 comments · Fixed by #393
Closed

Properly handle UnsupportedOperationException thrown by Thread::stop in JDK 20+ #391

kriegaex opened this issue Nov 9, 2023 · 3 comments · Fixed by #393

Comments

@kriegaex
Copy link
Contributor

kriegaex commented Nov 9, 2023

Since JDK 20, Thread::stop throws an UnsupportedOperationException, see the corresponding code change in OpenJDK. Actually, the method was deprecated since JDK 1.2 and slated for removal long ago, too. See also JDK-8204243. The rationale behind deprecation and how to better stop a thread are explained in Oracle's "Java Thread Primitive Deprecation".

Not only does ExecJavaMojoTest::testUncooperativeThread use Thread::stop, which is why unit tests are failing since JDK 20, but more severely, mojo exec:java will fail, too, if option stopUnresponsiveDaemonThreads is active. At the very least, an UnsupportedOperationException must be handled and reported in ExecJavaMojo::terminateThreads. Furthermore, option stopUnresponsiveDaemonThreads should be documented accordingly and its use be warned about with special notice of JDK 20+ where it has no effect (other than those exceptions I just mentioned).

@kriegaex kriegaex changed the title Build not running on JDK 21 Properly handle UnsupportedOperationException thrown by Thread::stop in JDK 20+ Nov 10, 2023
@kriegaex
Copy link
Contributor Author

kriegaex commented Nov 10, 2023

@slawekjaranowski, sorry for mentioning you directly, but I guess you are the most active developer in this project. I massively edited this issue, because I realised that this is about more than just failing builds on JDK 20+.

@slawekjaranowski
Copy link
Member

@kriegaex do you have a plan to fix it?

@kriegaex
Copy link
Contributor Author

kriegaex commented Nov 10, 2023

@slawekjaranowski, actually I stumbled upon this one by chance while testing the other PR you just merged. I thought, I should document it, before I forget about it again. I had not thought about fixing it myself.

OTOH, this weekend I might have some time to implement the minimal fix I sketched above and update the docs. If that is good enough for you to merge and you do not envision some kind of grand scheme solution, I can take a shot.

kriegaex added a commit to kriegaex/exec-maven-plugin that referenced this issue Nov 11, 2023
In JDK 20+, the long deprecated Thread.stop() (since JDK 1.2) has been
removed and will throw an UnsupportedOperationException. This will be
handled gracefully when using option 'stopUnresponsiveDaemonThreads',
yielding a log warning "Thread.stop() is unavailable in this JRE
version, cannot force-stop any threads" once and not trying to stop any
further threads during the same execution.

Tests and documentation have been adjusted accordingly.

Closes mojohaus#391.
kriegaex added a commit to kriegaex/exec-maven-plugin that referenced this issue Nov 11, 2023
Because mojohaus#391 introduces special handling of the fact that in JDK 20+
there is no more Thread::stop, we should also run the tests on JDK 21.
slawekjaranowski pushed a commit that referenced this issue Nov 11, 2023
* [#391] Cope with Thread::stop being unavailable in JDK 20+

In JDK 20+, the long deprecated Thread.stop() (since JDK 1.2) has been
removed and will throw an UnsupportedOperationException. This will be
handled gracefully when using option 'stopUnresponsiveDaemonThreads',
yielding a log warning "Thread.stop() is unavailable in this JRE
version, cannot force-stop any threads" once and not trying to stop any
further threads during the same execution.

Tests and documentation have been adjusted accordingly.

Closes #391.

* [#391] Add JDK 21 to CI build

Because #391 introduces special handling of the fact that in JDK 20+
there is no more Thread::stop, we should also run the tests on JDK 21.
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 a pull request may close this issue.

2 participants