Copilot commented on code in PR #201:
URL:
https://github.com/apache/maven-toolchains-plugin/pull/201#discussion_r4302566188
##########
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;
Review Comment:
Returning null on timeout does not currently ignore only that JDK.
`getToolchainModel()` forwards the null to `discoverToolchains()`, which
dereferences it while applying flags or reading the version. The outer catch
then returns an empty toolchain list, discarding healthy JDKs too. Guard
against null immediately after `getToolchainModel(s)` and filter null results
before sorting. Add a regression test with both a healthy and a timed-out
candidate.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]