Skip to content

Commit 6b46b5b

Browse files
committed
Avoid using ThrowableCollector to resolve package cycle
1 parent 765a3ef commit 6b46b5b

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

junit-platform-engine/src/main/java/org/junit/platform/engine/support/store/NamespacedHierarchicalStore.java

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,13 @@
1515
import static org.apiguardian.api.API.Status.DEPRECATED;
1616
import static org.apiguardian.api.API.Status.EXPERIMENTAL;
1717
import static org.apiguardian.api.API.Status.MAINTAINED;
18+
import static org.junit.platform.commons.util.ExceptionUtils.throwAsUncheckedException;
1819
import static org.junit.platform.commons.util.ReflectionUtils.getWrapperType;
1920
import static org.junit.platform.commons.util.ReflectionUtils.isAssignableTo;
2021

22+
import java.util.ArrayList;
2123
import java.util.Comparator;
24+
import java.util.List;
2225
import java.util.Optional;
2326
import java.util.concurrent.ConcurrentHashMap;
2427
import java.util.concurrent.ConcurrentMap;
@@ -28,10 +31,8 @@
2831

2932
import org.apiguardian.api.API;
3033
import org.jspecify.annotations.Nullable;
31-
import org.junit.platform.commons.util.ExceptionUtils;
3234
import org.junit.platform.commons.util.Preconditions;
3335
import org.junit.platform.commons.util.UnrecoverableExceptions;
34-
import org.junit.platform.engine.support.hierarchical.ThrowableCollector;
3536

3637
/**
3738
* {@code NamespacedHierarchicalStore} is a hierarchical, namespaced key-value store.
@@ -131,13 +132,26 @@ public void close() {
131132
if (!this.closed) {
132133
try {
133134
if (this.closeAction != null) {
134-
ThrowableCollector throwableCollector = new ThrowableCollector(__ -> false);
135+
List<Throwable> failures = new ArrayList<>();
135136
this.storedValues.entrySet().stream() //
136137
.map(e -> e.getValue().evaluateSafely(e.getKey())) //
137138
.filter(it -> it != null && it.value != null) //
138139
.sorted(EvaluatedValue.REVERSE_INSERT_ORDER) //
139-
.forEach(it -> throwableCollector.execute(() -> it.close(this.closeAction)));
140-
throwableCollector.assertEmpty();
140+
.forEach(it -> {
141+
try {
142+
it.close(this.closeAction);
143+
}
144+
catch (Throwable t) {
145+
UnrecoverableExceptions.rethrowIfUnrecoverable(t);
146+
failures.add(t);
147+
}
148+
});
149+
if (!failures.isEmpty()) {
150+
var iterator = failures.iterator();
151+
var throwable = iterator.next();
152+
iterator.forEachRemaining(throwable::addSuppressed);
153+
throw throwAsUncheckedException(throwable);
154+
}
141155
}
142156
}
143157
finally {
@@ -474,7 +488,7 @@ private MemoizingSupplier(Supplier<@Nullable Object> delegate) {
474488
computeValue();
475489
}
476490
if (this.value instanceof Failure failure) {
477-
throw ExceptionUtils.throwAsUncheckedException(failure.throwable);
491+
throw throwAsUncheckedException(failure.throwable);
478492
}
479493
return this.value;
480494
}

platform-tooling-support-tests/src/archUnit/java/platform/tooling/support/tests/ArchUnitTests.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,6 @@
6363
import org.junit.platform.commons.util.ReflectionUtils;
6464
import org.junit.platform.engine.TestDescriptor;
6565
import org.junit.platform.engine.reporting.OutputDirectoryProvider;
66-
import org.junit.platform.engine.support.hierarchical.ThrowableCollector;
67-
import org.junit.platform.engine.support.store.NamespacedHierarchicalStore;
6866

6967
@AnalyzeClasses(packages = { "org.junit.platform", "org.junit.jupiter", "org.junit.vintage" })
7068
class ArchUnitTests {
@@ -162,9 +160,6 @@ void freeOfPackageCycles(JavaClasses classes) throws Exception {
162160
// Needs more investigation
163161
.ignoreDependency(OutputDirectoryProvider.class, TestDescriptor.class) //
164162

165-
// Needs more investigation
166-
.ignoreDependency(NamespacedHierarchicalStore.class, ThrowableCollector.class) //
167-
168163
.check(classes);
169164
}
170165

0 commit comments

Comments
 (0)