This is an automated email from the ASF dual-hosted git repository.
cstamas pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-resolver.git
The following commit(s) were added to refs/heads/master by this push:
new bb91a66bc fix: SmartExecutor may miss to finish the jobs (#2259)
bb91a66bc is described below
commit bb91a66bcf6470c57c1960b1e73f80470266f2c6
Author: Tamas Cservenak <[email protected]>
AuthorDate: Tue Nov 3 22:37:13 2026 +0100
fix: SmartExecutor may miss to finish the jobs (#2259)
As it was catching Exception only, but it may throw other things
as well, leading to lock-ups.
---
.../aether/util/concurrency/SmartExecutor.java | 10 +--
.../aether/util/concurrency/SmartExecutorTest.java | 76 ++++++++++++++++++++++
2 files changed, 81 insertions(+), 5 deletions(-)
diff --git
a/maven-resolver-util/src/main/java/org/eclipse/aether/util/concurrency/SmartExecutor.java
b/maven-resolver-util/src/main/java/org/eclipse/aether/util/concurrency/SmartExecutor.java
index 9755a9fc7..a9f8b18f0 100644
---
a/maven-resolver-util/src/main/java/org/eclipse/aether/util/concurrency/SmartExecutor.java
+++
b/maven-resolver-util/src/main/java/org/eclipse/aether/util/concurrency/SmartExecutor.java
@@ -64,7 +64,7 @@ public interface SmartExecutor extends AutoCloseable {
CompletableFuture<T> future = new CompletableFuture<>();
try {
future.complete(callable.call());
- } catch (Exception e) {
+ } catch (Throwable e) {
future.completeExceptionally(e);
}
return future;
@@ -118,7 +118,7 @@ public interface SmartExecutor extends AutoCloseable {
Thread.currentThread().setContextClassLoader(tccl);
try {
future.complete(callable.call());
- } catch (Exception e) {
+ } catch (Throwable e) {
future.completeExceptionally(e);
} finally {
Thread.currentThread().setContextClassLoader(old);
@@ -127,7 +127,7 @@ public interface SmartExecutor extends AutoCloseable {
} catch (RejectedExecutionException e) {
try {
future.complete(callable.call());
- } catch (Exception ex) {
+ } catch (Throwable ex) {
future.completeExceptionally(ex);
}
}
@@ -191,7 +191,7 @@ public interface SmartExecutor extends AutoCloseable {
executor.submit(() -> {
try {
future.complete(callable.call());
- } catch (Exception e) {
+ } catch (Throwable e) {
future.completeExceptionally(e);
} finally {
semaphore.release();
@@ -200,7 +200,7 @@ public interface SmartExecutor extends AutoCloseable {
} catch (RejectedExecutionException e) {
try {
future.complete(callable.call());
- } catch (Exception ex) {
+ } catch (Throwable ex) {
future.completeExceptionally(ex);
} finally {
semaphore.release();
diff --git
a/maven-resolver-util/src/test/java/org/eclipse/aether/util/concurrency/SmartExecutorTest.java
b/maven-resolver-util/src/test/java/org/eclipse/aether/util/concurrency/SmartExecutorTest.java
new file mode 100644
index 000000000..d82721729
--- /dev/null
+++
b/maven-resolver-util/src/test/java/org/eclipse/aether/util/concurrency/SmartExecutorTest.java
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.eclipse.aether.util.concurrency;
+
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * Tests that {@link Error}s thrown by callables complete the future instead
of leaving it hanging.
+ */
+class SmartExecutorTest {
+ private static final Callable<String> BOOM = () -> {
+ throw new AssertionError("boom");
+ };
+
+ private static void assertErrorPropagated(SmartExecutor executor) {
+ try (SmartExecutor ignored = executor) {
+ Future<String> future = executor.submit(BOOM);
+ ExecutionException e = assertThrows(ExecutionException.class,
future::get);
+ assertInstanceOf(AssertionError.class, e.getCause());
+ assertTrue(future.isDone());
+ }
+ }
+
+ @Test
+ void directPropagatesError() {
+ assertErrorPropagated(new SmartExecutor.Direct());
+ }
+
+ @Test
+ void pooledPropagatesError() {
+ ExecutorService pool = Executors.newFixedThreadPool(1);
+ assertErrorPropagated(new SmartExecutor.Pooled(pool));
+ }
+
+ @Test
+ void limitedPropagatesError() {
+ ExecutorService pool = Executors.newFixedThreadPool(1);
+ assertErrorPropagated(new SmartExecutor.Limited(new
SmartExecutor.Pooled(pool), 1));
+ }
+
+ @Test
+ void limitedReleasesPermitAfterError() throws Exception {
+ ExecutorService pool = Executors.newFixedThreadPool(1);
+ try (SmartExecutor executor = new SmartExecutor.Limited(new
SmartExecutor.Pooled(pool), 1)) {
+ assertThrows(ExecutionException.class, () ->
executor.submit(BOOM).get());
+ // would block forever if the permit leaked
+ executor.submit(() -> "ok").get();
+ }
+ }
+}