mojohaus / exec-maven-plugin

Exec Maven Plugin
https://www.mojohaus.org/exec-maven-plugin/
Apache License 2.0
163 stars 96 forks source link

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

Closed kriegaex closed 7 months ago

kriegaex commented 7 months ago

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 commented 7 months ago

@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 commented 7 months ago

@kriegaex do you have a plan to fix it?

kriegaex commented 7 months ago

@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.