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

RandomGeneratorFactory.getDefault() throws exception when the runtime image only has java.base module

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P4 P4
    • 23
    • core-libs
    • None
    • minimal
    • Hide
      It was never intended, nor is it documented, to make it possible for 3rd party libraries to add a random generator homed outside the platform. Libraries that manage to do so have to make some undocumented and brittle effort.


      The JDK-specific module jdk.random is removed as part of this change. It's possible that there are scripts using jlink that specify this module. These scrips will require update once this module is removed.
      Show
      It was never intended, nor is it documented, to make it possible for 3rd party libraries to add a random generator homed outside the platform. Libraries that manage to do so have to make some undocumented and brittle effort. The JDK-specific module jdk.random is removed as part of this change. It's possible that there are scripts using jlink that specify this module. These scrips will require update once this module is removed.
    • Java API
    • SE

      Summary

      Remove references to service loader and service providers from the documentation of java.util.random and RandomGeneratorFactory.

      Problem

      Currently, package java.util.random specifies that "These algorithms must be found with the current version of Java SE. A particular JDK implementation may recognize additional algorithms".

      The emphasis here is on JDK implementation. There's no mention that other random generators implemented in 3rd party libraries, as opposed to the platform, should ever be accessible or discoverable via the API provided by RandomGeneratorFactory. Indeed, there's no documentation about any mechanism to add generators external to the JDK platform.

      However, the same document also specifies that "RandomGeneratorFactory registers implementations of RandomGenerator interface using the service provider API." This is an implementation detail that might change over time and that should not be part of the specification.

      Likewise, implementation requirements in RandomGeneratorFactory.of() and RandomGeneratorFactory.all() should be removed, as they, too, refer to the service loader API, a private implementation detail.

      Solution

      See summary.

      Specification

      diff --git a/src/java.base/share/classes/java/util/random/package-info.java b/src/java.base/shar
      e/classes/java/util/random/package-info.java
      index b4dfe28f796..2e16b319f44 100644
      --- a/src/java.base/share/classes/java/util/random/package-info.java
      +++ b/src/java.base/share/classes/java/util/random/package-info.java
      @@ -50,9 +50,7 @@
        * <p> The principal supporting class is {@link RandomGeneratorFactory}. This
        * can be used to generate multiple random number generators for a specific
        * algorithm. {@link RandomGeneratorFactory} also provides methods for
      - * selecting random number generator algorithms. RandomGeneratorFactory
      - * registers implementations of {@link RandomGenerator} interface using the
      - * service provider API.
      + * selecting random number generator algorithms.
        *
        * <p> An important subsidiary interface is
        * {@link RandomGenerator.StreamableGenerator}, which provides methods for
      
      
      
      
      diff --git a/src/java.base/share/classes/java/util/random/RandomGeneratorFactory.java b/src/java.base/share/classes/java/util/random/RandomGeneratorFactory.java
      index 7b7339e2772..a7c06371368 100644
      --- a/src/java.base/share/classes/java/util/random/RandomGeneratorFactory.java
      +++ b/src/java.base/share/classes/java/util/random/RandomGeneratorFactory.java
      @@ -341,9 +342,6 @@ private void ensureConstructors() {
            * {@link RandomGenerator} that utilize the {@code name}
            * <a href="package-summary.html#algorithms">algorithm</a>.
            *
      -     * @implSpec Availability is determined by RandomGeneratorFactory using the
      -     * service provider API to locate implementations of the RandomGenerator interface.
      -     *
            * @param name  Name of random number generator
            * <a href="package-summary.html#algorithms">algorithm</a>
            * @param <T> Sub-interface of {@link RandomGenerator} to produce
      
      
      diff --git a/src/java.base/share/classes/java/util/random/RandomGeneratorFactory.java b/src/java.base/share/classes/java/util/random/RandomGeneratorFactory.java
      index 7b7339e2772..a7c06371368 100644
      --- a/src/java.base/share/classes/java/util/random/RandomGeneratorFactory.java
      +++ b/src/java.base/share/classes/java/util/random/RandomGeneratorFactory.java
      @@ -376,12 +374,9 @@ public static RandomGeneratorFactory<RandomGenerator> getDefault() {
      
           /**
            * Returns a non-empty stream of available {@link RandomGeneratorFactory RandomGeneratorFac
      tory(s)}.
      -     *
      +     * <p>
            * RandomGenerators that are marked as deprecated are not included in the result.
            *
      -     * @implSpec Availability is determined by RandomGeneratorFactory using the service provide
      r API
      -     * to locate implementations of the RandomGenerator interface.
      -     *
            * @return a non-empty stream of all available {@link RandomGeneratorFactory RandomGenerato
      rFactory(s)}.
            */
           public static Stream<RandomGeneratorFactory<RandomGenerator>> all() {
      
      
      

            rgiulietti Raffaello Giulietti
            jpai Jaikiran Pai
            Alan Bateman, Jaikiran Pai
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: