8313290: Misleading exception message from STS.Subtask::get when task forked after shutdown

Reviewed-by: psandoz
This commit is contained in:
Alan Bateman 2023-08-19 18:42:43 +00:00
parent febc34dd28
commit ed0f75f266
2 changed files with 8 additions and 23 deletions

View file

@ -576,8 +576,6 @@ public class StructuredTaskScope<T> implements AutoCloseable {
}
SubtaskImpl<U> subtask = new SubtaskImpl<>(this, task, round);
boolean started = false;
if (s < SHUTDOWN) {
// create thread to run task
Thread thread = factory.newThread(subtask);
@ -588,15 +586,14 @@ public class StructuredTaskScope<T> implements AutoCloseable {
// attempt to start the thread
try {
flock.start(thread);
started = true;
} catch (IllegalStateException e) {
// shutdown by another thread, or underlying flock is shutdown due
// to unstructured use
}
}
// force owner to join if thread started
if (started && Thread.currentThread() == flock.owner() && round > forkRound) {
// force owner to join if this is the first fork in the round
if (Thread.currentThread() == flock.owner() && round > forkRound) {
forkRound = round;
}
@ -939,7 +936,8 @@ public class StructuredTaskScope<T> implements AutoCloseable {
T r = (T) result;
return r;
}
throw new IllegalStateException("Subtask not completed or did not complete successfully");
throw new IllegalStateException(
"Result is unavailable or subtask did not complete successfully");
}
@Override
@ -949,7 +947,8 @@ public class StructuredTaskScope<T> implements AutoCloseable {
if (result instanceof AltResult alt && alt.state() == State.FAILED) {
return alt.exception();
}
throw new IllegalStateException("Subtask not completed or did not complete with exception");
throw new IllegalStateException(
"Exception is unavailable or subtask did not complete with exception");
}
@Override