From ba19bfa19e1015cd99ead99d1774c49b8fc9638e Mon Sep 17 00:00:00 2001 From: Ladislav Thon Date: Wed, 30 Aug 2023 14:33:26 +0200 Subject: [PATCH] Fix guards against repeated external sets of SPI implementations We previously [1] added code to guard against repeated calls to these SPIs: - `BuildServicesResolver.setBuildServices()` - `CDI.setCDIProvider()` The guards are unfortunately incorrect. This commit fixes them. [1] https://github.com/jakartaee/cdi/commit/82ec5d71872212364a321cd3700d0ecadf9162d2 --- .../inject/build/compatible/spi/BuildServicesResolver.java | 2 +- api/src/main/java/jakarta/enterprise/inject/spi/CDI.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/api/src/main/java/jakarta/enterprise/inject/build/compatible/spi/BuildServicesResolver.java b/api/src/main/java/jakarta/enterprise/inject/build/compatible/spi/BuildServicesResolver.java index 702bf860..93380024 100644 --- a/api/src/main/java/jakarta/enterprise/inject/build/compatible/spi/BuildServicesResolver.java +++ b/api/src/main/java/jakarta/enterprise/inject/build/compatible/spi/BuildServicesResolver.java @@ -82,7 +82,7 @@ public static void setBuildServices(BuildServices instance) { if (instance == null) { throw new IllegalArgumentException("BuildServices instance must not be null"); } - if (configuredBuildServices != null) { + if (configuredBuildServices == null) { configuredBuildServices = instance; } else { throw new IllegalStateException("BuildServices cannot be set repeatedly. Existing BuildServices are " + configuredBuildServices); 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 7e793500..1182a7ef 100644 --- a/api/src/main/java/jakarta/enterprise/inject/spi/CDI.java +++ b/api/src/main/java/jakarta/enterprise/inject/spi/CDI.java @@ -123,7 +123,7 @@ public static void setCDIProvider(CDIProvider provider) { if (provider == null) { throw new IllegalArgumentException("CDIProvider must not be null"); } - if (configuredProvider != null) { + if (configuredProvider == null) { providerSetManually = true; configuredProvider = provider; } else {