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

Inheritance example in ScopedValue class-level spec needs an improvement

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Unresolved
    • Icon: P3 P3
    • None
    • None
    • core-libs

      The "Inheritance" section of j.l.ScopedValue contains the following sample
      (DRAFT 21-ea+27-LTS-2343)
      https://download.java.net/java/early_access/jdk21/docs/api/java.base/java/lang/ScopedValue.html#inheritance

      ====
          private static final ScopedValue<String> NAME = ScopedValue.newInstance();

          ScopedValue.runWhere(NAME, "duke", () -> {
              try (var scope = new StructuredTaskScope<String>()) {

                  scope.fork(() -> childTask1());
                  scope.fork(() -> childTask2());
                  scope.fork(() -> childTask3());

                  ...
               }
          });
      ====


      The example basically does not work out-of-the-box - it is missing scope.join(); after forking, otherwise the result would be

          java.lang.IllegalStateException: Owner did not join after forking subtasks


      UPDATE: and the thrown java.lang.IllegalStateException is not mentioned anywhere in the specs for j.l.ScopedValue+Carrier classes


            alanb Alan Bateman
            dbessono Dmitry Bessonov
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: