Restore Thread interrupt flag after wait
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());
}
And also it would be good to formally provide the cause of the exception, not only in the message:
throw new ExecutionException("Can not run " + RscriptExecutable + ". Reason: " + e.toString(), e)
You could implement it and then make a pull request.
@fbastian any help or improvements for this issue?