Skip to content

Commit

Permalink
Throw an exception without setting configuredProvider to null when ge…
Browse files Browse the repository at this point in the history
…tCDI returns null

Signed-off-by: Benjamin Confino <[email protected]>
  • Loading branch information
benjamin-confino committed Dec 18, 2020
1 parent 23986b2 commit 1f8ce88
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions api/src/main/java/jakarta/enterprise/inject/spi/CDI.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
public abstract class CDI<T> implements Instance<T> {

private static final Object lock = new Object();
private static volatile boolean providerSetManually = false;
protected static volatile Set<CDIProvider> discoveredProviders = null;
protected static volatile CDIProvider configuredProvider = null;

Expand Down Expand Up @@ -79,6 +80,11 @@ private static CDIProvider getCDIProvider() {
}
} catch (IllegalStateException ignored) {
}
//configuredProvider cannot be null if providerSetManually is true. If it somehow is an NPE is appropriate
.
if (providerSetManually && configuredProvider.getCDI() == null) {
throw new IllegalStateException("Unable to access CDI");
}
configuredProvider = null;
// Discover providers and cache
if (discoveredProviders == null) {
Expand Down Expand Up @@ -116,6 +122,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");
Expand Down

0 comments on commit 1f8ce88

Please sign in to comment.