Skip to content

Commit

Permalink
NPE when obtaining ConfigValue via getValue
Browse files Browse the repository at this point in the history
Fixes #906
  • Loading branch information
mabartos committed Mar 16, 2023
1 parent ad8b6df commit 4c349b8
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ private ConfigValue getValue(final ConfigSourceInterceptorContext context, final
return configValue;
}

if (configValue == null) {
if (configValue == null || configValue.getValue() == null) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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();
}
}
}

0 comments on commit 4c349b8

Please sign in to comment.