You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2021/05/20 04:43:09 UTC
[groovy] branch GROOVY_3_0_X updated: GROOVY-10097: Better
propagation of InterruptedException (additional cases) (port to 3_0_X)
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 72e2868 GROOVY-10097: Better propagation of InterruptedException (additional cases) (port to 3_0_X)
72e2868 is described below
commit 72e28687dea2d78a9a408d8d1924255fa27c022d
Author: Paul King <pa...@asert.com.au>
AuthorDate: Wed May 19 23:49:12 2021 +1000
GROOVY-10097: Better propagation of InterruptedException (additional cases) (port to 3_0_X)
---
.../groovy/runtime/DefaultGroovyStaticMethods.java | 26 +++++++++++++---------
.../groovy/jmx/builder/JmxConnectorHelper.java | 1 +
.../main/groovy/groovy/swing/SwingBuilder.groovy | 1 +
.../groovy/swing/binding/PropertyBinding.java | 1 +
.../org/apache/groovy/stress/util/ThreadUtils.java | 1 +
5 files changed, 20 insertions(+), 10 deletions(-)
diff --git a/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyStaticMethods.java b/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyStaticMethods.java
index 163cca4..5fc0ef2 100644
--- a/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyStaticMethods.java
+++ b/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyStaticMethods.java
@@ -142,19 +142,25 @@ public class DefaultGroovyStaticMethods {
long start = System.currentTimeMillis();
long rest = millis;
long current;
- while (rest > 0) {
- try {
- Thread.sleep(rest);
- rest = 0;
- } catch (InterruptedException e) {
- if (closure != null) {
- if (DefaultTypeTransformation.castToBoolean(closure.call(e))) {
- return;
+ boolean interrupted = false;
+ try {
+ while (rest > 0) {
+ try {
+ Thread.sleep(rest);
+ rest = 0;
+ } catch (InterruptedException e) {
+ interrupted = true;
+ if (closure != null) {
+ if (DefaultTypeTransformation.castToBoolean(closure.call(e))) {
+ return;
+ }
}
+ current = System.currentTimeMillis(); // compensate for closure's time
+ rest = millis + start - current;
}
- current = System.currentTimeMillis(); // compensate for closure's time
- rest = millis + start - current;
}
+ } finally {
+ if (interrupted) Thread.currentThread().interrupt();
}
}
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 4e6f904..8955036 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
@@ -47,6 +47,7 @@ public class JmxConnectorHelper {
try {
Thread.sleep(500);
} catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
throw new RuntimeException(e);
}
}
diff --git a/subprojects/groovy-swing/src/main/groovy/groovy/swing/SwingBuilder.groovy b/subprojects/groovy-swing/src/main/groovy/groovy/swing/SwingBuilder.groovy
index cc17dda..f60ef12 100644
--- a/subprojects/groovy-swing/src/main/groovy/groovy/swing/SwingBuilder.groovy
+++ b/subprojects/groovy-swing/src/main/groovy/groovy/swing/SwingBuilder.groovy
@@ -334,6 +334,7 @@ class SwingBuilder extends FactoryBuilderSupport {
continuationData = getContinuationData()
}
} catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
throw new GroovyRuntimeException("interrupted swing interaction", e)
} catch (InvocationTargetException e) {
throw new GroovyRuntimeException("exception in event dispatch thread", e.getTargetException())
diff --git a/subprojects/groovy-swing/src/main/java/org/apache/groovy/swing/binding/PropertyBinding.java b/subprojects/groovy-swing/src/main/java/org/apache/groovy/swing/binding/PropertyBinding.java
index a485f35..4109fc8 100644
--- a/subprojects/groovy-swing/src/main/java/org/apache/groovy/swing/binding/PropertyBinding.java
+++ b/subprojects/groovy-swing/src/main/java/org/apache/groovy/swing/binding/PropertyBinding.java
@@ -208,6 +208,7 @@ public class PropertyBinding implements SourceBinding, TargetBinding, TriggerBin
SwingUtilities.invokeAndWait(runnable);
} catch (InterruptedException e) {
LOG.log(Level.WARNING, "Error notifying propertyChangeListener", e);
+ Thread.currentThread().interrupt();
throw new GroovyRuntimeException(e);
} catch (InvocationTargetException e) {
LOG.log(Level.WARNING, "Error notifying propertyChangeListener", e.getTargetException());
diff --git a/subprojects/stress/src/test/java/org/apache/groovy/stress/util/ThreadUtils.java b/subprojects/stress/src/test/java/org/apache/groovy/stress/util/ThreadUtils.java
index 83df303..d0c41a5 100644
--- a/subprojects/stress/src/test/java/org/apache/groovy/stress/util/ThreadUtils.java
+++ b/subprojects/stress/src/test/java/org/apache/groovy/stress/util/ThreadUtils.java
@@ -29,6 +29,7 @@ public class ThreadUtils {
try {
latch.await();
} catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
throw new Error(e);
}
}