diff --git a/extensions/arc/deployment/src/test/java/io/quarkus/arc/test/config/staticinit/StaticInitConfigInjectionMissingValueFailureTest.java b/extensions/arc/deployment/src/test/java/io/quarkus/arc/test/config/staticinit/StaticInitConfigInjectionMissingValueFailureTest.java new file mode 100644 index 00000000000000..fd1d1fee3fd230 --- /dev/null +++ b/extensions/arc/deployment/src/test/java/io/quarkus/arc/test/config/staticinit/StaticInitConfigInjectionMissingValueFailureTest.java @@ -0,0 +1,54 @@ +package io.quarkus.arc.test.config.staticinit; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.fail; + +import java.util.Optional; + +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.enterprise.context.Initialized; +import jakarta.enterprise.event.Observes; +import jakarta.inject.Singleton; + +import org.eclipse.microprofile.config.inject.ConfigProperty; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.quarkus.runtime.ShutdownEvent; +import io.quarkus.test.QuarkusUnitTest; + +public class StaticInitConfigInjectionMissingValueFailureTest { + + @RegisterExtension + static final QuarkusUnitTest config = new QuarkusUnitTest() + .withApplicationRoot(root -> root + .addClasses(StaticInitBean.class)) + .assertException(t -> { + assertThat(t).isInstanceOf(IllegalStateException.class) + .hasMessageContainingAll( + "A runtime config property value differs from the value that was injected during the static intialization phase", + "the runtime value of 'apfelstrudel' is [gizmo] but the value [null] was injected into io.quarkus.arc.test.config.staticinit.StaticInitConfigInjectionMissingValueFailureTest$StaticInitBean#value"); + }); + + @Test + public void test() { + fail(); + } + + @Singleton + public static class StaticInitBean { + + @ConfigProperty(name = "apfelstrudel") + Optional value; + + // bean is instantiated during STATIC_INIT + void onInit(@Observes @Initialized(ApplicationScoped.class) Object event) { + System.setProperty("apfelstrudel", "gizmo"); + } + + void onDestroy(@Observes ShutdownEvent event) { + System.clearProperty("apfelstrudel"); + } + + } +} diff --git a/extensions/arc/runtime/src/main/java/io/quarkus/arc/runtime/ConfigStaticInitCheckInterceptor.java b/extensions/arc/runtime/src/main/java/io/quarkus/arc/runtime/ConfigStaticInitCheckInterceptor.java index e02621937e7b86..dc06f683503a5b 100644 --- a/extensions/arc/runtime/src/main/java/io/quarkus/arc/runtime/ConfigStaticInitCheckInterceptor.java +++ b/extensions/arc/runtime/src/main/java/io/quarkus/arc/runtime/ConfigStaticInitCheckInterceptor.java @@ -69,8 +69,7 @@ static void recordConfigValue(InjectionPoint injectionPoint, ConfigStaticInitVal value = getDefaultValue(injectionPoint, configProperty); } if (value == null) { - LOG.debugf("No config value found for %s", propertyName); - return; + LOG.debugf("No config value found for %s - recording value", propertyName); } if (configValues == null) { configValues = Arc.container().instance(ConfigStaticInitValues.class).get(); diff --git a/extensions/arc/runtime/src/main/java/io/quarkus/arc/runtime/ConfigStaticInitValues.java b/extensions/arc/runtime/src/main/java/io/quarkus/arc/runtime/ConfigStaticInitValues.java index f464416e7603f1..bb525564633295 100644 --- a/extensions/arc/runtime/src/main/java/io/quarkus/arc/runtime/ConfigStaticInitValues.java +++ b/extensions/arc/runtime/src/main/java/io/quarkus/arc/runtime/ConfigStaticInitValues.java @@ -3,6 +3,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.Objects; import jakarta.annotation.Priority; import jakarta.enterprise.event.Observes; @@ -43,7 +44,7 @@ void onStart(@Observes @Priority(Integer.MIN_VALUE) StartupEvent event) { List mismatches = new ArrayList<>(); for (InjectedValue injectedValue : injectedValues) { ConfigValue currentValue = config.getConfigValue(injectedValue.name); - if (currentValue.getValue() != null && !injectedValue.value.equals(currentValue.getValue())) { + if (!Objects.equals(currentValue.getValue(), injectedValue.value)) { mismatches.add( " - the runtime value of '" + injectedValue.name + "' is [" + currentValue.getValue() + "] but the value [" + injectedValue.value