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

Reviewed-by: jpai, alanb
This commit is contained in:
Raffaello Giulietti 2024-05-08 08:27:13 +00:00
parent 2baacfc169
commit 7f299043a9
14 changed files with 38 additions and 104 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2022, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -142,8 +142,9 @@ public final class RandomGeneratorFactory<T extends RandomGenerator> {
* @return Map of RandomGeneratorFactory classes.
*/
private static Map<String, Provider<? extends RandomGenerator>> createFactoryMap() {
FactoryMapHolder.class.getModule().addUses(RandomGenerator.class);
return ServiceLoader
.load(RandomGenerator.class)
.load(RandomGenerator.class, ClassLoader.getPlatformClassLoader())
.stream()
.filter(p -> !p.type().isInterface())
.collect(Collectors.toMap(p -> p.type().getSimpleName(), Function.identity()));
@ -341,9 +342,6 @@ public final class RandomGeneratorFactory<T extends RandomGenerator> {
* {@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
@ -376,12 +374,9 @@ public final class RandomGeneratorFactory<T extends RandomGenerator> {
/**
* Returns a non-empty stream of available {@link RandomGeneratorFactory RandomGeneratorFactory(s)}.
*
* <p>
* RandomGenerators that are marked as deprecated are not included in the result.
*
* @implSpec Availability is determined by RandomGeneratorFactory using the service provider API
* to locate implementations of the RandomGenerator interface.
*
* @return a non-empty stream of all available {@link RandomGeneratorFactory RandomGeneratorFactory(s)}.
*/
public static Stream<RandomGeneratorFactory<RandomGenerator>> all() {
@ -615,5 +610,3 @@ public final class RandomGeneratorFactory<T extends RandomGenerator> {
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -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
@ -636,4 +634,3 @@
* @since 17
*/
package java.util.random;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -23,7 +23,7 @@
* questions.
*/
package jdk.random;
package jdk.internal.random;
import java.util.concurrent.atomic.AtomicLong;
import java.util.random.RandomGenerator;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -23,7 +23,7 @@
* questions.
*/
package jdk.random;
package jdk.internal.random;
import java.util.concurrent.atomic.AtomicLong;
import java.util.random.RandomGenerator;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -23,7 +23,7 @@
* questions.
*/
package jdk.random;
package jdk.internal.random;
import java.util.concurrent.atomic.AtomicLong;
import java.util.random.RandomGenerator;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -23,7 +23,7 @@
* questions.
*/
package jdk.random;
package jdk.internal.random;
import java.util.concurrent.atomic.AtomicLong;
import java.util.random.RandomGenerator;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -23,7 +23,7 @@
* questions.
*/
package jdk.random;
package jdk.internal.random;
import java.util.concurrent.atomic.AtomicLong;
import java.util.random.RandomGenerator;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -23,7 +23,7 @@
* questions.
*/
package jdk.random;
package jdk.internal.random;
import java.util.concurrent.atomic.AtomicLong;
import java.util.random.RandomGenerator;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -23,7 +23,7 @@
* questions.
*/
package jdk.random;
package jdk.internal.random;
import java.util.concurrent.atomic.AtomicLong;
import java.util.random.RandomGenerator;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -23,7 +23,7 @@
* questions.
*/
package jdk.random;
package jdk.internal.random;
import java.util.concurrent.atomic.AtomicLong;
import java.util.random.RandomGenerator;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -23,7 +23,7 @@
* questions.
*/
package jdk.random;
package jdk.internal.random;
import java.util.concurrent.atomic.AtomicLong;
import java.util.random.RandomGenerator;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -23,7 +23,7 @@
* questions.
*/
package jdk.random;
package jdk.internal.random;
import java.util.concurrent.atomic.AtomicLong;
import java.util.random.RandomGenerator;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -268,8 +268,6 @@ module java.base {
jdk.jfr;
exports jdk.internal.util.xml.impl to
jdk.jfr;
exports jdk.internal.util.random to
jdk.random;
exports jdk.internal.util to
java.desktop,
java.prefs,
@ -396,7 +394,6 @@ module java.base {
uses java.time.chrono.AbstractChronology;
uses java.time.chrono.Chronology;
uses java.time.zone.ZoneRulesProvider;
uses java.util.random.RandomGenerator;
uses java.util.spi.CalendarDataProvider;
uses java.util.spi.CalendarNameProvider;
uses java.util.spi.CurrencyNameProvider;
@ -425,6 +422,16 @@ module java.base {
provides java.util.random.RandomGenerator with
java.security.SecureRandom,
java.util.Random,
java.util.SplittableRandom;
java.util.SplittableRandom,
jdk.internal.random.L32X64MixRandom,
jdk.internal.random.L64X128MixRandom,
jdk.internal.random.L64X128StarStarRandom,
jdk.internal.random.L64X256MixRandom,
jdk.internal.random.L64X1024MixRandom,
jdk.internal.random.L128X128MixRandom,
jdk.internal.random.L128X256MixRandom,
jdk.internal.random.L128X1024MixRandom,
jdk.internal.random.Xoroshiro128PlusPlus,
jdk.internal.random.Xoshiro256PlusPlus;
}

View File

@ -1,63 +0,0 @@
/*
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
import jdk.internal.util.random.RandomSupport;
/**
* Defines implementations of the
* {@linkplain java.util.random.RandomGenerator RandomGenerator Interface}.
*
* @provides jdk.random.L128X1024MixRandom
* @provides jdk.random.L128X128MixRandom
* @provides jdk.random.L128X256MixRandom
* @provides jdk.random.L32X64MixRandom
* @provides jdk.random.L64X1024MixRandom
* @provides jdk.random.L64X128MixRandom
* @provides jdk.random.L64X128StarStarRandom
* @provides jdk.random.L64X256MixRandom
* @provides jdk.random.Xoroshiro128PlusPlus
* @provides jdk.random.Xoshiro256PlusPlus
*
* @uses java.util.random.RandomGenerator
*
* @moduleGraph
* @since 16
*/
module jdk.random {
exports jdk.random to
java.base;
provides java.util.random.RandomGenerator with
jdk.random.L32X64MixRandom,
jdk.random.L64X128MixRandom,
jdk.random.L64X128StarStarRandom,
jdk.random.L64X256MixRandom,
jdk.random.L64X1024MixRandom,
jdk.random.L128X128MixRandom,
jdk.random.L128X256MixRandom,
jdk.random.L128X1024MixRandom,
jdk.random.Xoroshiro128PlusPlus,
jdk.random.Xoshiro256PlusPlus;
}