Implement JEP 8376595: Lazy Constants (Third Preview)

XMLWordPrintable

    • Type: CSR
    • Resolution: Unresolved
    • Priority: P4
    • 27
    • Component/s: core-libs
    • None
    • medium
    • Usage of the removed methods `LazyConstant::isInitialized` and `LazyConstant::orElse` would result in a compile-time error. Exception types and handling differ.
    • Java API
    • SE

      Summary

      This API was first previewed in JDK 25 via JEP 502: Stable Values and then in JDK 26 via JEP 526 Lazy Constants. Based on experience and feedback, we propose to remove two methods from LazyConstant and add support for lazy sets.

      Problem

      The methods LazyConstant::isInitialized and LazyConstant::orElse could result in usages that were outside the design goals of the Lazy Constant API.

      There was support for lazy lists and maps, but not for lazy sets. Some corner cases, such as TOC-TOU protection and the use of exotic Set equality schemes, were not specified.

      The concept of an-ever-retrying computing function was abandoned, and now, a true at-most-once invocation is desired instead.

      Solution

      • Remove the LazyConstant::isInitialized and LazyConstant::orElse methods.

      • Add a new factory method Set::ofLazy that allows the creation of lazy sets.

      • Add additional verbiage around Map::ofLazy and Set::ofLazy method requirements on the provided Set specifying key/membership candidates.

      • Make LazyConstant and the lazy collections transition to an error state upon detecting that the computing function throws, and update the docs accordingly.

      Specification

      See attachment.

            Assignee:
            Per-Ake Minborg
            Reporter:
            Per-Ake Minborg
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: