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

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

XMLWordPrintable

    • b22
    • Verified

      Create a runtime image consisting only of java.base module:

      jlink --output ./only-java-base --add-modules java.base

      Now, consider this trivial code which calls java.util.random.RandomGeneratorFactory.getDefault():

          import java.util.random.*;

          public class Foo {
              public static void main(final String[] args) throws Exception {
                  final RandomGeneratorFactory<RandomGenerator> rgf = RandomGeneratorFactory.getDefault();
                  System.out.println("Got " + rgf);
              }
          }

      Compile it:

      javac Foo.java

      and then run it using the runtime image that was created above:

      ./only-java-base/bin/java Foo

      This leads to:

          Exception in thread "main" java.lang.IllegalArgumentException: No implementation of the random number generator algorithm "L32X64MixRandom" is available
              at java.base/java.util.random.RandomGeneratorFactory.findProvider(RandomGeneratorFactory.java:229)
              at java.base/java.util.random.RandomGeneratorFactory.factoryOf(RandomGeneratorFactory.java:275)
              at java.base/java.util.random.RandomGeneratorFactory.getDefault(RandomGeneratorFactory.java:374)
              at Foo.main(Foo.java:5)

      The RandomGeneratorFactory.getDefault() in its API documentation notes:

      * Returns a {@link RandomGeneratorFactory} meeting the minimal requirement
      * of having an algorithm whose state bits are greater than or equal 64.

      It appears that there's no implementation within java.base that satisfies this criteria.

      It's suggested that java.base should either include a RandomGeneratorFactory to return as the default or the getDefault method needs to specify behavior when there is no default.

            rgiulietti Raffaello Giulietti
            jpai Jaikiran Pai
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved: