diff --git a/implementation/src/main/java/io/smallrye/config/ExpressionConfigSourceInterceptor.java b/implementation/src/main/java/io/smallrye/config/ExpressionConfigSourceInterceptor.java index 740799f9f..09b73ecef 100644 --- a/implementation/src/main/java/io/smallrye/config/ExpressionConfigSourceInterceptor.java +++ b/implementation/src/main/java/io/smallrye/config/ExpressionConfigSourceInterceptor.java @@ -49,7 +49,7 @@ private ConfigValue getValue(final ConfigSourceInterceptorContext context, final return configValue; } - if (configValue == null) { + if (configValue == null || configValue.getValue() == null) { return null; } diff --git a/implementation/src/test/java/io/smallrye/config/ExpressionConfigSourceInterceptorTest.java b/implementation/src/test/java/io/smallrye/config/ExpressionConfigSourceInterceptorTest.java index 7abe50a76..83b17c017 100644 --- a/implementation/src/test/java/io/smallrye/config/ExpressionConfigSourceInterceptorTest.java +++ b/implementation/src/test/java/io/smallrye/config/ExpressionConfigSourceInterceptorTest.java @@ -12,6 +12,7 @@ import java.util.Optional; import java.util.stream.Stream; +import jakarta.annotation.Priority; import org.junit.jupiter.api.Test; class ExpressionConfigSourceInterceptorTest { @@ -203,10 +204,40 @@ void windowPath() { assertEquals("C:\\Some\\Path", config.getRawValue("window.path")); } + @Test + void nullValue() { + SmallRyeConfig config = buildConfigWithCustomInterceptor("sth", null); + ConfigValue configValue = config.getConfigValue("sth"); + + assertNotNull(configValue); + + // No exception is thrown, only null is returned + assertNull(configValue.getValue()); + } + private static SmallRyeConfig buildConfig(String... keyValues) { return new SmallRyeConfigBuilder() .addDefaultInterceptors() .withSources(KeyValuesConfigSource.config(keyValues)) .build(); } + + private static SmallRyeConfig buildConfigWithCustomInterceptor(String... keyValues) { + return new SmallRyeConfigBuilder() + .addDefaultInterceptors() + .withInterceptors(new CustomConfigSourceInterceptor()) + .withInterceptors(new ExpressionConfigSourceInterceptor()) + .withSources(KeyValuesConfigSource.config(keyValues)) + .build(); + } + + + @Priority(Priorities.LIBRARY + 201) + private static class CustomConfigSourceInterceptor implements ConfigSourceInterceptor { + + @Override + public ConfigValue getValue(ConfigSourceInterceptorContext context, String name) { + return ConfigValue.builder().withName(name).withValue(null).build(); + } + } }