Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8313290

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

    XMLWordPrintable

Details

    • b12
    • generic
    • generic
    • Verified

    Description

      ADDITIONAL SYSTEM INFORMATION :
      Ubuntu 22.04
      openjdk 21-ea 2023-09-19
      OpenJDK Runtime Environment (build 21-ea+32-2482)
      OpenJDK 64-Bit Server VM (build 21-ea+32-2482, mixed mode, sharing)

      A DESCRIPTION OF THE PROBLEM :
      When using a StructuredTaskScope after shutdown, I get a misleading error message when calling Subtask.get(): "IllegalStateException: Owner did not join after forking subtasks".

      See example code below. In the code, join() is called right before Subtask.get(), so the error message is clearly not incorrect (in addition to not being helpful).

      I'd expect an exception that indicates that the StructuredTaskScope is already shutdown.

      Obviously, this is a rather unlikely usage pattern (shutdown() + fork()), but there might be more meaningful cases where this occurs, and then a better exception message might be helpful.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      See example code.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      An exception that indicates that the StructuredTaskScope is shutdown.
      ACTUAL -
      Exception in thread "main" java.lang.IllegalStateException: Owner did not join after forking subtasks
      at java.base/java.util.concurrent.StructuredTaskScope.newIllegalStateExceptionNoJoin(StructuredTaskScope.java:439)
      at java.base/java.util.concurrent.StructuredTaskScope.ensureJoinedIfOwner(StructuredTaskScope.java:477)
      at java.base/java.util.concurrent.StructuredTaskScope$SubtaskImpl.get(StructuredTaskScope.java:927)
      at com.example.Test.main(Test.java:17)

      ---------- BEGIN SOURCE ----------

      import java.util.concurrent.ExecutionException;
      import java.util.concurrent.StructuredTaskScope;

      public class Test {

      public static void main(String[] args) {
      try (var scope = new StructuredTaskScope.ShutdownOnFailure()) {

      scope.shutdown();

      StructuredTaskScope.Subtask<String> subtask = scope.fork(() -> "result");

      scope.join().throwIfFailed();

      subtask.get(); // IllegalStateException: Owner did not join after forking subtasks

      } catch (InterruptedException | ExecutionException e) {
      throw new RuntimeException(e);
      }
      }

      }

      ---------- END SOURCE ----------

      FREQUENCY : always


      Attachments

        Issue Links

          Activity

            People

              alanb Alan Bateman
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: