diff --git a/api/src/main/java/jakarta/enterprise/inject/spi/CDI.java b/api/src/main/java/jakarta/enterprise/inject/spi/CDI.java index f06104312..344ec8b3d 100644 --- a/api/src/main/java/jakarta/enterprise/inject/spi/CDI.java +++ b/api/src/main/java/jakarta/enterprise/inject/spi/CDI.java @@ -44,6 +44,7 @@ public abstract class CDI implements Instance { private static final Object lock = new Object(); + private static volatile boolean providerSetManually = false; protected static volatile Set discoveredProviders = null; protected static volatile CDIProvider configuredProvider = null; @@ -77,7 +78,11 @@ private static CDIProvider getCDIProvider() { if (configuredProvider != null && configuredProvider.getCDI() != null) { return configuredProvider; } - } catch (IllegalStateException ignored) { + } catch (IllegalStateException e) { + //if the provider is set manually we do not look for a different provider. + if (providerSetManually) { + throw e; + } } configuredProvider = null; // Discover providers and cache @@ -116,6 +121,7 @@ private static boolean checkProvider(CDIProvider c) { */ public static void setCDIProvider(CDIProvider provider) { if (provider != null) { + providerSetManually = true; configuredProvider = provider; } else { throw new IllegalStateException("CDIProvider must not be null");