Restore interrupt flag in ProcessRunner on InterruptedException

ProcessRunner.waitForProcess and ReaderThread.toString catch
InterruptedException without restoring the thread interrupt flag.
This prevents callers higher up the stack from detecting the
interruption. Every other InterruptedException handler in the
codebase restores the flag; these two were the only omissions.

Add Thread.currentThread().interrupt() before re-throwing or
returning in both catch blocks. Also chain the original exception
as the cause in waitForProcess for debuggability.

See gh-50451

Signed-off-by: Sebastien Tardif <sebtardif@ncf.ca>
This commit is contained in:
Sebastien Tardif
2026-05-29 12:20:51 +02:00
committed by Stéphane Nicoll
parent 3e5ad73f01
commit 8a28cefd08
@@ -122,7 +122,8 @@ class ProcessRunner {
return process.waitFor();
}
catch (InterruptedException ex) {
throw new IllegalStateException("Interrupted waiting for %s".formatted(process));
Thread.currentThread().interrupt();
throw new IllegalStateException("Interrupted waiting for %s".formatted(process), ex);
}
}
@@ -174,6 +175,7 @@ class ProcessRunner {
return this.output.toString();
}
catch (InterruptedException ex) {
Thread.currentThread().interrupt();
return null;
}
}