Skip to content

Commit 9184830

Browse files
authored
NPE when obtaining ConfigValue via getValue (smallrye#907)
Fixes smallrye#906
1 parent ad8b6df commit 9184830

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

implementation/src/main/java/io/smallrye/config/ExpressionConfigSourceInterceptor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ private ConfigValue getValue(final ConfigSourceInterceptorContext context, final
4949
return configValue;
5050
}
5151

52-
if (configValue == null) {
52+
if (configValue == null || configValue.getValue() == null) {
5353
return null;
5454
}
5555

implementation/src/test/java/io/smallrye/config/ExpressionConfigSourceInterceptorTest.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
import java.util.Optional;
1313
import java.util.stream.Stream;
1414

15+
import jakarta.annotation.Priority;
16+
1517
import org.junit.jupiter.api.Test;
1618

1719
class ExpressionConfigSourceInterceptorTest {
@@ -203,10 +205,39 @@ void windowPath() {
203205
assertEquals("C:\\Some\\Path", config.getRawValue("window.path"));
204206
}
205207

208+
@Test
209+
void nullValue() {
210+
SmallRyeConfig config = buildConfigWithCustomInterceptor("sth", null);
211+
ConfigValue configValue = config.getConfigValue("sth");
212+
213+
assertNotNull(configValue);
214+
215+
// No exception is thrown, only null is returned
216+
assertNull(configValue.getValue());
217+
}
218+
206219
private static SmallRyeConfig buildConfig(String... keyValues) {
207220
return new SmallRyeConfigBuilder()
208221
.addDefaultInterceptors()
209222
.withSources(KeyValuesConfigSource.config(keyValues))
210223
.build();
211224
}
225+
226+
private static SmallRyeConfig buildConfigWithCustomInterceptor(String... keyValues) {
227+
return new SmallRyeConfigBuilder()
228+
.addDefaultInterceptors()
229+
.withInterceptors(new CustomConfigSourceInterceptor())
230+
.withInterceptors(new ExpressionConfigSourceInterceptor())
231+
.withSources(KeyValuesConfigSource.config(keyValues))
232+
.build();
233+
}
234+
235+
@Priority(Priorities.LIBRARY + 201)
236+
private static class CustomConfigSourceInterceptor implements ConfigSourceInterceptor {
237+
238+
@Override
239+
public ConfigValue getValue(ConfigSourceInterceptorContext context, String name) {
240+
return ConfigValue.builder().withName(name).withValue(null).build();
241+
}
242+
}
212243
}

0 commit comments

Comments
 (0)