This is an automated email from the ASF dual-hosted git repository.
paulk pushed a commit to branch GROOVY_2_5_X
in repository https://gitbox.apache.org/repos/asf/groovy.git
The following commit(s) were added to refs/heads/GROOVY_2_5_X by this push:
new 698b70a GROOVY-9826: Better propagation of InterruptedException (port
to 2_5_X)
698b70a is described below
commit 698b70a52f3bccc5e21f3a8132671deaff165437
Author: Paul King <[email protected]>
AuthorDate: Thu Nov 26 14:26:49 2020 +1000
GROOVY-9826: Better propagation of InterruptedException (port to 2_5_X)
---
.../groovy/runtime/ProcessGroovyMethods.java | 34 ++++++++++++++--------
.../org/codehaus/groovy/util/ReferenceManager.java | 1 +
.../groovy/jmx/builder/JmxConnectorHelper.java | 2 +-
3 files changed, 24 insertions(+), 13 deletions(-)
diff --git
a/src/main/java/org/codehaus/groovy/runtime/ProcessGroovyMethods.java
b/src/main/java/org/codehaus/groovy/runtime/ProcessGroovyMethods.java
index 7348d3f..d323947 100644
--- a/src/main/java/org/codehaus/groovy/runtime/ProcessGroovyMethods.java
+++ b/src/main/java/org/codehaus/groovy/runtime/ProcessGroovyMethods.java
@@ -241,10 +241,15 @@ public class ProcessGroovyMethods extends
DefaultGroovyMethodsSupport {
public static void waitForProcessOutput(Process self, Appendable output,
Appendable error) {
Thread tout = consumeProcessOutputStream(self, output);
Thread terr = consumeProcessErrorStream(self, error);
- try { tout.join(); } catch (InterruptedException ignore) {}
- try { terr.join(); } catch (InterruptedException ignore) {}
- try { self.waitFor(); } catch (InterruptedException ignore) {}
- closeStreams(self);
+ boolean interrupted = false;
+ try {
+ try { tout.join(); } catch (InterruptedException ignore) {
interrupted = true; }
+ try { terr.join(); } catch (InterruptedException ignore) {
interrupted = true; }
+ try { self.waitFor(); } catch (InterruptedException ignore) {
interrupted = true; }
+ closeStreams(self);
+ } finally {
+ if (interrupted) Thread.currentThread().interrupt();
+ }
}
/**
@@ -263,10 +268,15 @@ public class ProcessGroovyMethods extends
DefaultGroovyMethodsSupport {
public static void waitForProcessOutput(Process self, OutputStream output,
OutputStream error) {
Thread tout = consumeProcessOutputStream(self, output);
Thread terr = consumeProcessErrorStream(self, error);
- try { tout.join(); } catch (InterruptedException ignore) {}
- try { terr.join(); } catch (InterruptedException ignore) {}
- try { self.waitFor(); } catch (InterruptedException ignore) {}
- closeStreams(self);
+ boolean interrupted = false;
+ try {
+ try { tout.join(); } catch (InterruptedException ignore) {
interrupted = true; }
+ try { terr.join(); } catch (InterruptedException ignore) {
interrupted = true; }
+ try { self.waitFor(); } catch (InterruptedException ignore) {
interrupted = true; }
+ closeStreams(self);
+ } finally {
+ if (interrupted) Thread.currentThread().interrupt();
+ }
}
/**
@@ -444,8 +454,8 @@ public class ProcessGroovyMethods extends
DefaultGroovyMethodsSupport {
private void doProcessWait() {
try {
process.waitFor();
- } catch (InterruptedException e) {
- // Ignore
+ } catch (InterruptedException ignore) {
+ Thread.currentThread().interrupt();
}
}
@@ -461,8 +471,8 @@ public class ProcessGroovyMethods extends
DefaultGroovyMethodsSupport {
if (!finished) {
try {
wait(millis);
- } catch (InterruptedException e) {
- // Ignore
+ } catch (InterruptedException ignore) {
+ Thread.currentThread().interrupt();
}
if (!finished) {
process.destroy();
diff --git a/src/main/java/org/codehaus/groovy/util/ReferenceManager.java
b/src/main/java/org/codehaus/groovy/util/ReferenceManager.java
index 6ab6d56..00ef8b3 100644
--- a/src/main/java/org/codehaus/groovy/util/ReferenceManager.java
+++ b/src/main/java/org/codehaus/groovy/util/ReferenceManager.java
@@ -36,6 +36,7 @@ public class ReferenceManager {
try {
r = queue.remove(1000);
} catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
break;
}
if (r==null) continue;
diff --git
a/subprojects/groovy-jmx/src/test/java/groovy/jmx/builder/JmxConnectorHelper.java
b/subprojects/groovy-jmx/src/test/java/groovy/jmx/builder/JmxConnectorHelper.java
index 2920866..4e6f904 100644
---
a/subprojects/groovy-jmx/src/test/java/groovy/jmx/builder/JmxConnectorHelper.java
+++
b/subprojects/groovy-jmx/src/test/java/groovy/jmx/builder/JmxConnectorHelper.java
@@ -45,7 +45,7 @@ public class JmxConnectorHelper {
port = port + 1;
System.out.println("JmxBuilder - *** FAILED *** to create RMI
Registry - Will Retry on port [" + port + "].");
try {
- Thread.currentThread().sleep(500);
+ Thread.sleep(500);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}