Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

import java.util.Collections;
import java.util.Comparator;
import java.util.Objects;
import java.util.ServiceConfigurationError;
import java.util.ServiceLoader;
import java.util.Set;
Expand Down Expand Up @@ -76,8 +75,17 @@ private static void discoverFactories() {
* this class will no longer attempt to look it up using service loader.
*
* @param instance a {@link BuildServices} instance that should be used, must not be {@code null}
* @throws IllegalArgumentException if the provided argument is null
* @throws IllegalStateException if the {@link BuildServices} are already set
*/
public static void setBuildServices(BuildServices instance) {
configuredBuildServices = Objects.requireNonNull(instance, "BuildServices instance must not be null");
if (instance == null) {
throw new IllegalArgumentException("BuildServices instance must not be null");
}
if (configuredBuildServices != null) {
configuredBuildServices = instance;
} else {
throw new IllegalStateException("BuildServices cannot be set repeatedly. Existing BuildServices are " + configuredBuildServices);
}
}
}
10 changes: 7 additions & 3 deletions api/src/main/java/jakarta/enterprise/inject/spi/CDI.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public static CDI<Object> current() {
/**
*
* Obtain the {@link CDIProvider} the user set with {@link #setCDIProvider(CDIProvider)} or the last returned
* {@link CDIProvider} if it returns valid CDI container. Otherwise use the serviceloader to retrieve the
* {@link CDIProvider} if it returns valid CDI container. Otherwise, use service loader mechanism to retrieve the
* {@link CDIProvider} with the highest priority.
*
* @return the {@link CDIProvider} set by user or retrieved by serviceloader
Expand Down Expand Up @@ -118,13 +118,17 @@ private static boolean checkProvider(CDIProvider c) {
*
* @param provider the provider to use
* @throws IllegalStateException if the {@link CDIProvider} is already set
* @throws IllegalArgumentException if the provided argument is null
*/
public static void setCDIProvider(CDIProvider provider) {
if (provider != null) {
if (provider == null) {
throw new IllegalArgumentException("CDIProvider must not be null");
}
if (configuredProvider != null) {
providerSetManually = true;
configuredProvider = provider;
} else {
throw new IllegalStateException("CDIProvider must not be null");
throw new IllegalStateException("CDIProvider cannot be set repeatedly. Existing provider is " + configuredProvider);
}
}

Expand Down