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

Empty values are always treated as non-present #114

Merged
merged 2 commits into from
May 13, 2019
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 @@ -57,6 +57,10 @@ public <T, C extends Collection<T>> C getValues(String name, Class<T> itemClass,
for (ConfigSource configSource : configSources) {
String value = configSource.getValue(name);
if (value != null) {
if (value.isEmpty()) {
// empty collection
break;
}
String[] itemStrings = StringUtil.split(value);
final C collection = collectionFactory.apply(itemStrings.length);
for (String itemString : itemStrings) {
Expand All @@ -65,6 +69,7 @@ public <T, C extends Collection<T>> C getValues(String name, Class<T> itemClass,
return collection;
}
}
// value not found
return collectionFactory.apply(0);
}

Expand All @@ -73,6 +78,10 @@ public <T> T getValue(String name, Class<T> aClass) {
for (ConfigSource configSource : configSources) {
String value = configSource.getValue(name);
if (value != null) {
if (value.isEmpty()) {
// treat empty value as non-present
break;
}
return convert(value, aClass);
}
}
Expand All @@ -93,11 +102,12 @@ public <T> T getValue(String name, Class<T> aClass) {
public <T> Optional<T> getOptionalValue(String name, Class<T> aClass) {
for (ConfigSource configSource : configSources) {
String value = configSource.getValue(name);
// treat empty value as null
if (value != null && value.length() > 0) {
return Optional.of(convert(value, aClass));
if (value != null) {
// treat empty value as non-present
return value.isEmpty() ? Optional.empty() : Optional.of(convert(value, aClass));
}
}
// value not found
return Optional.empty();
}

Expand Down
15 changes: 15 additions & 0 deletions testsuite/tck/tck-suite.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,21 @@
<package name="org.eclipse.microprofile.config.tck.*">
</package>
</packages>

<!-- TCK and spec dispute: https://github.com/eclipse/microprofile-config/pull/407 -->
<classes>
<class name="org.eclipse.microprofile.config.tck.ConfigProviderTest">
<methods>
<exclude name="testEnvironmentConfigSource"/>
</methods>
</class>
<class name="org.eclipse.microprofile.config.tck.EmptyValuesTest">
<methods>
<exclude name="testEmptyStringPropertyFromConfigFile"/>
<exclude name="testEmptyStringProgrammaticLookup"/>
</methods>
</class>
</classes>
</test>

</suite>