You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by "elharo (via GitHub)" <gi...@apache.org> on 2026/10/17 11:54:09 UTC

Re: [PR] Timeout Java process during JDK discovery [maven-toolchains-plugin]

elharo commented on code in PR #201:
URL: https://github.com/apache/maven-toolchains-plugin/pull/201#discussion_r4302563859


##########
src/main/java/org/apache/maven/plugins/toolchain/jdk/ToolchainDiscoverer.java:
##########
@@ -276,16 +278,23 @@ ToolchainModel doGetToolchainModel(Path jdk) {
         try {
             Path temp = Files.createTempFile("jdk-opts-", ".out");
             try {
-                new ProcessBuilder()
+                Process process = new ProcessBuilder()
                         .command(java.toString(), "-XshowSettings:properties", "-version")
                         .redirectError(temp.toFile())
-                        .start()
-                        .waitFor();
+                        .start();
+                if (!process.waitFor(JAVA_PROCESS_TIMEOUT_SECONDS, TimeUnit.SECONDS)) {
+                    process.destroyForcibly();
+                    log.debug("JDK toolchain discovered at " + jdk + " will be ignored: java process timed out");
+                    return null;
+                }
                 lines = Files.readAllLines(temp);
             } finally {
                 Files.delete(temp);
             }
         } catch (IOException | InterruptedException e) {
+            if (e instanceof InterruptedException) {
+                Thread.currentThread().interrupt();
+            }
             log.debug("JDK toolchain discovered at " + jdk + " will be ignored: error executing java: " + e);

Review Comment:
   log.warn



##########
src/main/java/org/apache/maven/plugins/toolchain/jdk/ToolchainDiscoverer.java:
##########
@@ -276,16 +278,23 @@ ToolchainModel doGetToolchainModel(Path jdk) {
         try {
             Path temp = Files.createTempFile("jdk-opts-", ".out");
             try {
-                new ProcessBuilder()
+                Process process = new ProcessBuilder()
                         .command(java.toString(), "-XshowSettings:properties", "-version")
                         .redirectError(temp.toFile())
-                        .start()
-                        .waitFor();
+                        .start();
+                if (!process.waitFor(JAVA_PROCESS_TIMEOUT_SECONDS, TimeUnit.SECONDS)) {
+                    process.destroyForcibly();
+                    log.debug("JDK toolchain discovered at " + jdk + " will be ignored: java process timed out");

Review Comment:
   Now this one I do think justifies a warning. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org