JDK-8331223 : RandomGeneratorFactory.all() throws ServiceConfigurationError if a java.util.random.RandomGenerator service is missing in the classpath
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util
  • Affected Version: 17
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • Submitted: 2024-04-27
  • Updated: 2024-05-10
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.
Other
tbdUnresolved
Related Reports
Relates :  
Description
Create a trivial jar (let's say foo.jar) which just contains a single META-INF/services/java.util.random.RandomGenerator file whose contents are:

foo.DummyRandomGenerator

Now run the following Main application with that jar in the classpath. The main() method just calls RandomGeneratorFactory.all() method:

import java.util.random.RandomGeneratorFactory;

public class Main {
    public static void main(String[] args) {
        System.out.println("available RandomGenerator(s):");
        RandomGeneratorFactory.all().map(RandomGeneratorFactory::name).forEach(System.out::println);
    }
}

javac Main.java
java -cp .:foo.jar Main

This leads to the following exception:

Exception in thread "main" java.util.ServiceConfigurationError: java.util.random.RandomGenerator: Provider foo.DummyRandomGenerator not found
    at java.base/java.util.ServiceLoader.fail(ServiceLoader.java:589)
    at java.base/java.util.ServiceLoader$LazyClassPathLookupIterator.nextProviderClass(ServiceLoader.java:1215)
    at java.base/java.util.ServiceLoader$LazyClassPathLookupIterator.hasNextService(ServiceLoader.java:1224)
    at java.base/java.util.ServiceLoader$LazyClassPathLookupIterator.hasNext(ServiceLoader.java:1269)
    at java.base/java.util.ServiceLoader$2.hasNext(ServiceLoader.java:1305)
    at java.base/java.util.ServiceLoader$ProviderSpliterator.tryAdvance(ServiceLoader.java:1485)
    at java.base/java.util.Spliterator.forEachRemaining(Spliterator.java:332)
    at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:556)
    at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:546)
    at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921)
    at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265)
    at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:702)
    at java.base/java.util.random.RandomGeneratorFactory$FactoryMapHolder.createFactoryMap(RandomGeneratorFactory.java:149)
    at java.base/java.util.random.RandomGeneratorFactory$FactoryMapHolder.<clinit>(RandomGeneratorFactory.java:137)
    at java.base/java.util.random.RandomGeneratorFactory.getFactoryMap(RandomGeneratorFactory.java:168)
    at java.base/java.util.random.RandomGeneratorFactory.all(RandomGeneratorFactory.java:388)
    at Main.main(Main.java:6)



Comments
See also the discussion in the PR for JDK-8330005. I think the main thing that has to be established is whether there was an intention to expose a service provider interface or not.
27-04-2024

I've attached a new jtreg test (test/jdk/java/util/Random/MissingProviderTest.java) which reproduces this issue.
27-04-2024