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

ScopedValue throwing StructureViolationException should be clearer

    XMLWordPrintable

Details

    • b06

    Backports

      Description

        Java SE 21 & JDK 21
        DRAFT 21-ea+28-LTS-2377

        Many method's specs in j.l.ScopedValue+Carrier contain the following assertion

        "Once closed, StructureViolationException is thrown."

        e.g. https://download.java.net/java/early_access/jdk21/docs/api/java.base/java/lang/ScopedValue.Carrier.html#call(java.util.concurrent.Callable)

        As experiments show it seems the spec should mention IllegalStateException instead of StructureViolationException

        UPD: this original note above is based on reading of the following block that is repeated 6 times in the specs for j.l.ScopedValue+Carrier methods

        ========
        Scoped values are intended to be used in a structured manner. If op creates a StructuredTaskScope but does not close it, then exiting op causes the underlying construct of each StructuredTaskScope created in the dynamic scope to be closed. This may require blocking until all child threads have completed their sub-tasks. The closing is done in the reverse order that they were created. Once closed, StructureViolationException is thrown.
        ========

        The last sentence could give an impression that it's the scope instance which is throwing StructureViolationException when we are calling, say, StructuredTaskScope::fork after the scope is closed, - while it's throwing IllegalStateException.

        Actually the carrier's methods are expected to throw StructureViolationException if STS was not properly closed by the op.

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                  Created:
                  Updated:
                  Resolved: