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:39:34 UTC
[groovy] branch master updated: GROOVY-10097: Better propagation of
InterruptedException (additional cases)
This is an automated email from the ASF dual-hosted git repository.
paulk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git
The following commit(s) were added to refs/heads/master by this push:
new 908b1c6 GROOVY-10097: Better propagation of InterruptedException (additional cases)
new 0d5b938 Merge pull request #1579 from paulk-asert/groovy10097
908b1c6 is described below
commit 908b1c6fdea4eb5b8b3df53d446af69a6f2f1311
Author: Paul King <pa...@asert.com.au>
AuthorDate: Wed May 19 23:49:12 2021 +1000
GROOVY-10097: Better propagation of InterruptedException (additional cases)
---
.../groovy/runtime/DefaultGroovyStaticMethods.java | 26 +++++++++++++---------
.../collection/runtime/QueryableCollection.java | 4 ++++
.../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 +
6 files changed, 24 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 e4d3797..71f7883 100644
--- a/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyStaticMethods.java
+++ b/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyStaticMethods.java
@@ -138,19 +138,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-ginq/src/main/groovy/org/apache/groovy/ginq/provider/collection/runtime/QueryableCollection.java b/subprojects/groovy-ginq/src/main/groovy/org/apache/groovy/ginq/provider/collection/runtime/QueryableCollection.java
index 2a6ad56..7438166 100644
--- a/subprojects/groovy-ginq/src/main/groovy/org/apache/groovy/ginq/provider/collection/runtime/QueryableCollection.java
+++ b/subprojects/groovy-ginq/src/main/groovy/org/apache/groovy/ginq/provider/collection/runtime/QueryableCollection.java
@@ -299,10 +299,14 @@ class QueryableCollection<T> implements Queryable<T>, Serializable {
if (TRUE_STR.equals(originalParallel)) {
// invoke `collect` to trigger the intermediate operator, which will create `CompletableFuture` instances
stream = stream.collect(Collectors.toList()).parallelStream().map((U u) -> {
+ boolean interrupted = false;
try {
return (U) ((CompletableFuture) u).get();
} catch (InterruptedException | ExecutionException ex) {
+ if (ex instanceof InterruptedException) interrupted = true;
throw new GroovyRuntimeException(ex);
+ } 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 f4f234e..0bcf34f 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
@@ -49,6 +49,7 @@ public class JmxConnectorHelper {
try {
Thread.sleep(100L * counter);
} 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 cb3a023..228b69b 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
@@ -216,6 +216,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/stressTest/java/org/apache/groovy/stress/util/ThreadUtils.java b/subprojects/stress/src/stressTest/java/org/apache/groovy/stress/util/ThreadUtils.java
index 83df303..d0c41a5 100644
--- a/subprojects/stress/src/stressTest/java/org/apache/groovy/stress/util/ThreadUtils.java
+++ b/subprojects/stress/src/stressTest/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);
}
}