JDK-8330005 : RandomGeneratorFactory.getDefault() throws exception when the runtime image only has java.base module
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util
  • Affected Version: 17
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • Submitted: 2024-04-10
  • Updated: 2024-07-10
  • Resolved: 2024-05-08
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 23
23 b22Fixed
Related Reports
CSR :  
Relates :  
Relates :  
Sub Tasks
JDK-8331843 :  
Description
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.

Comments
Changeset: 7f299043 Author: Raffaello Giulietti <rgiulietti@openjdk.org> Date: 2024-05-08 08:27:13 +0000 URL: https://git.openjdk.org/jdk/commit/7f299043a99406dbd666d4f7f30445d26f3eae82
08-05-2024

The jdk.random module is removed, there will need to be a release note for that.
07-05-2024

A pull request was submitted for review. URL: https://git.openjdk.org/jdk/pull/18932 Date: 2024-04-24 13:50:56 +0000
24-04-2024