Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NPE when obtaining ConfigValue via getValue #907

Merged
merged 1 commit into from
Mar 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,8 @@
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 +205,39 @@ 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();
}
}
}