This is an automated email from the ASF dual-hosted git repository.
paulk pushed a commit to branch GROOVY_3_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git
The following commit(s) were added to refs/heads/GROOVY_3_0_X by this push:
new ac19c48 GROOVY-9826: Better propagation of InterruptedException
(closes #1434)
ac19c48 is described below
commit ac19c483541c86acb6f81f994fc2d885076b7923
Author: Paul King <[email protected]>
AuthorDate: Thu Nov 26 14:26:49 2020 +1000
GROOVY-9826: Better propagation of InterruptedException (closes #1434)
---
.../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 fc82dc9..9590f23 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();
+ }
}
/**
@@ -438,8 +448,8 @@ public class ProcessGroovyMethods extends
DefaultGroovyMethodsSupport {
private void doProcessWait() {
try {
process.waitFor();
- } catch (InterruptedException e) {
- // Ignore
+ } catch (InterruptedException ignore) {
+ Thread.currentThread().interrupt();
}
}
@@ -455,8 +465,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 9bcc168..195b46c 100644
--- a/src/main/java/org/codehaus/groovy/util/ReferenceManager.java
+++ b/src/main/java/org/codehaus/groovy/util/ReferenceManager.java
@@ -35,6 +35,7 @@ public class ReferenceManager {
try {
r = queue1.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);
}