question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Clarification of ConfigSource.getProperties and getPropertyNames

See original GitHub issue

Not so long ago there was an issue opened in the javaee-samples repo because the Liberty config impl did not work as expected with an “EchoConfigSource”.

https://github.com/javaee-samples/microprofile1.2-samples/issues/3 https://github.com/javaee-samples/microprofile1.2-samples/blob/master/config/config-source/src/main/java/org/eclipse/microprofile12/config/configsource/EchoConfigSource.java

The EchoConfigSource has been implemented to simply echo back anything that is requested via ConfigSource.getValue. That means that the returns from getProperties and getPropertyNames are incomplete compared with what getValue will respond to.

If ConfigSource.getPropertyNames is not guaranteed to return a complete set then Config.getPropertyNames can not be guaranteed to be complete either. Without that guarantee then the method isn’t of much use beyond perhaps some non-critical tracing.

Either the javadoc for both ConfigSource and Config should be updated to make if clear what can be relied upon and what can not… or the methods should just be removed?!

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
smillidgecommented, Mar 30, 2018

+1 for updating the docs. Removal could break backwards compatibility however I would also be in favour of removal. Both methods could be very expensive depending on the Config Source for example imagine a config source that looks up a key in a Redis or memcached KV store it would need to retrieve all keys to comply with the api signature.

1reaction
OndroMihcommented, Apr 16, 2018

@Emily-Jiang explained that there’s a usecase to find out whether a value exists in a config source or not and the only way to find out now is to call getPropertyNames(). The usecase is motly valid when checking that a config value is present at deploy time. I think this usecase would be better supported by a new method propertyExists(String).

It can even be a default method like this to avoid breaking existing config sources:

default boolean propertyExists(String propertyName) {
        return getPropertyNames().contains(propertyName);
}

However, I would remove both getProperties() and getPropertyNames() as @smillidge suggested. For most sources, there’s no guarantee that the config values won’t change during runtime. Even standard system property config source can change values during runtime.

To avoid breaking existing code, we can make them deprecated and return empty set/map by default, so that config sources don’t have to implement them.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Configuration for MicroProfile
Manually defining the Ordinal of a built-in ConfigSource; 5.3. ... ConfigSource#getPropertyNames is no longer a default method.
Read more >
Custom ConfigSource for Quarkus - java - Stack Overflow
You can obtain the data source via AgroalDataSource dataSource = Arc.container() .instance(AgroalDataSource.class, new DataSource.
Read more >
Extending Configuration Support - Quarkus
With a Custom ConfigSource it is possible to read additional configuration ... @Override public Set<String> getPropertyNames() { return configuration.
Read more >
Configuration for Microprofile - Red Hat Developer
Custom ConfigSources via ConfigSourceProvider . ... public Set<String> getPropertyNames() { ... Clarified what it means for a value to be present (#216).
Read more >
ConfigSource - Apache TomEE
Return the properties in this config source. default java.util.Set<java.lang.String>, getPropertyNames(). Gets all property names known to this config ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found