Improve documentation for JEP 526: Lazy Constants

XMLWordPrintable

    • Type: CSR
    • Resolution: Unresolved
    • Priority: P3
    • 26
    • Component/s: core-libs
    • None
    • source
    • minimal
    • The spec is updated to reflect how lazy constructs actually work.
    • Java API

      Summary

      Minor adjustments to the documentation based on PR feedback.

      Problem

      The LazyConstant::toString was not specified correctly.

      Solution

      Update the specification

      diff --git a/src/java.base/share/classes/java/lang/LazyConstant.java b/src/java.base/share/classes/java/lang/LazyConstant.java
      index 5f5d37b3d1dc3..446ce9f3c3c6e 100644
      --- a/src/java.base/share/classes/java/lang/LazyConstant.java
      +++ b/src/java.base/share/classes/java/lang/LazyConstant.java
      @@ -86,10 +86,6 @@
        * If the computing function recursively invokes itself (directly or indirectly via
        * the lazy constant), an {@linkplain IllegalStateException} is thrown, and the lazy
        * constant is not initialized.
      - * <p>
      - * If the computing function throws any unchecked {@linkplain Exception} or
      - * {@linkplain Error}, that {@linkplain Throwable} is propagated to the caller, and the
      - * lazy constant remains uninitialized.
        *
        * <h2 id="composition">Composing lazy constants</h2>
        * A lazy constant can depend on other lazy constants, forming a dependency graph
      @@ -158,8 +154,8 @@
        * This is only possible if there is a direct reference from a {@code static final} field
        * to a lazy constant or if there is a chain from a {@code static final} field -- via one
        * or more <em>trusted fields</em> (i.e., {@code static final} fields,
      - * {@linkplain Record record} fields, lazy constants, lazy lists, lazy maps,
      - * or final instance fields in hidden classes) -- to a lazy constant.
      + * {@linkplain Record record} fields, or final instance fields in hidden classes) --
      + * to a lazy constant.
        *
        * <h2 id="miscellaneous">Miscellaneous</h2>
        * Except for {@linkplain Object#equals(Object) equals(obj)} and
      @@ -181,7 +177,7 @@
        *          <p>
        *          Use in static initializers may interact with class initialization order;
        *          cyclic initialization may result in initialization errors as described
      - *          in {@jls 12.4} of <cite>The Java Language Specification</cite>.
      + *          in section {@jls 12.4} of <cite>The Java Language Specification</cite>.
        *
        * @implNote
        *           A lazy constant is free to synchronize on itself. Hence, care must be
      @@ -206,7 +202,7 @@ public sealed interface LazyConstant<T>
               permits LazyConstantImpl {
       
           /**
      -     * {@return the contents of this lazy constant if initialized, otherwise,\
      +     * {@return the contents of this lazy constant if initialized, otherwise,
            *          returns {@code other}}
            * <p>
            * This method never triggers initialization of this lazy constant and will observe
      @@ -264,7 +260,8 @@ public sealed interface LazyConstant<T>
            * initialization by other threads atomically (i.e., it observes the
            * contents if and only if the initialization has already completed).
            * <p>
      -     * If this lazy constant is initialized, the {@linkplain Object#toString()} of the
      +     * If this lazy constant is initialized, an implementation-dependent string
      +     * containing the {@linkplain Object#toString()} of the
            * contents will be returned; otherwise, an implementation-dependent string is
            * returned that indicates this lazy constant is not yet initialized.
            */
      @@ -278,14 +275,16 @@ public sealed interface LazyConstant<T>
            *          {@code computingFunction}}
            * <p>
            * The returned lazy constant strongly references the provided
      -     * {@code computingFunction} until initialization completes successfully; after
      -     * which the computing function is no longer strongly referenced and becomes
      -     * eligible for garbage collection.
      +     * {@code computingFunction} at least until initialization completes successfully.
            * <p>
            * If the provided computing function is already an instance of
            * {@code LazyConstant}, the method is free to return the provided computing function
            * directly.
            *
      +     * @implNote  after initialization completes successfully, the computing function is
      +     *            no longer strongly referenced and becomes eligible for
      +     *            garbage collection.
      +     *
            * @param computingFunction in the form of a {@linkplain Supplier} to be used
            *                          to initialize the constant
            * @param <T>               type of the constant
      diff --git a/src/java.base/share/classes/java/util/List.java b/src/java.base/share/classes/java/util/List.java
      index 238dc34965c76..83c2fa20f059f 100644
      --- a/src/java.base/share/classes/java/util/List.java
      +++ b/src/java.base/share/classes/java/util/List.java
      @@ -1197,7 +1197,7 @@ static <E> List<E> copyOf(Collection<? extends E> coll) {
           }
       
           /**
      -     * {@return a new lazily computed list with the provided {@code size}}
      +     * {@return a new lazily computed list of the provided {@code size}}
            * <p>
            * The returned list is an {@linkplain Collection##unmodifiable unmodifiable} list
            * with the provided {@code size}. The list's elements are lazily computed via the
      @@ -1235,12 +1235,15 @@ static <E> List<E> copyOf(Collection<? extends E> coll) {
            * implementation-dependent string is returned for uninitialized elements.
            * <p>
            * The returned lazy list strongly references its computing
      -     * function used to compute elements only so long as there are uncomputed elements
      -     * after which the computing function is not strongly referenced
      -     * anymore and may be collected.
      +     * function used to compute elements at least so long as there are uninitialized
      +     * elements.
            * <p>
            * The returned List is <em>not</em> {@linkplain Serializable}.
            *
      +     * @implNote  after all elements have been initialized successfully, the computing
      +     *            function is no longer strongly referenced and becomes eligible for
      +     *            garbage collection.
      +     *
            * @param size              the size of the returned lazy list
            * @param computingFunction to invoke whenever an element is first accessed
            *                          (may not return {@code null})
      diff --git a/src/java.base/share/classes/java/util/Map.java b/src/java.base/share/classes/java/util/Map.java
      index eead46b9b7082..01ff9bb20b979 100644
      --- a/src/java.base/share/classes/java/util/Map.java
      +++ b/src/java.base/share/classes/java/util/Map.java
      @@ -1788,12 +1788,15 @@ static <K, V> Map<K, V> copyOf(Map<? extends K, ? extends V> map) {
            * implementation-dependent string is returned for uninitialized values.
            * <p>
            * The returned lazy map strongly references its underlying
      -     * computing function used to compute values only so long as there are
      -     * uncomputed values after which the underlying function is not strongly referenced
      -     * anymore and may be collected.
      +     * computing function used to compute values at least so long as there are
      +     * uncomputed values.
            * <p>
            * The returned Map is <em>not</em> {@linkplain Serializable}.
            *
      +     * @implNote  after all values have been initialized successfully, the computing
      +     *            function is no longer strongly referenced and becomes eligible for
      +     *            garbage collection.
      +     *
            * @param keys              the (non-null) keys in the returned computed map
            * @param computingFunction to invoke whenever an associated value is first accessed
            * @param <K>               the type of keys maintained by the returned map
         
      
          
      
      

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

              Created:
              Updated: