rcaller code makes the Thread to wait/sleep at some points (which is fine). The problem is that, if the Thread was interrupted, these methods throw an InterruptedException, which is caught and rethrown by rcaller without restoring the interrupted thread flag.
Example in rcaller 2.8: https://github.com/jbytecode/rcaller/blob/c586cb7c74d2e570d6b3ef242c8f3c1561cac49d/RCaller/src/main/java/com/github/rcaller/rstuff/RCaller.java
The method runRCode uses the method Process.waitFor, which throws an InterruptedException if the Thread was interrupted, and reinit the interrupted flag of the Thread. A good practice is to catch the InterruptedException and to restore the interrupted flag. For instance:
try {
//this Process object is local to this method. Do not use the public one.
process = exec(RscriptExecutable + " " + rSourceFile.toString());
startStreamConsumers(process);
returnCode = process.waitFor();
} catch (Exception e) {
if (e instanceof InterruptedException) {
//restore the interrupt flag so that applications don't loose this information
Thread.currentThread().interrupt();
}
throw new ExecutionException("Can not run " + RscriptExecutable + ". Reason: " + e.toString());
}
rcaller code makes the Thread to wait/sleep at some points (which is fine). The problem is that, if the Thread was interrupted, these methods throw an
InterruptedException, which is caught and rethrown by rcaller without restoring the interrupted thread flag.Example in rcaller 2.8: https://github.com/jbytecode/rcaller/blob/c586cb7c74d2e570d6b3ef242c8f3c1561cac49d/RCaller/src/main/java/com/github/rcaller/rstuff/RCaller.java
The method
runRCodeuses the methodProcess.waitFor, which throws anInterruptedExceptionif the Thread was interrupted, and reinit the interrupted flag of the Thread. A good practice is to catch theInterruptedExceptionand to restore the interrupted flag. For instance: