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

Bug: ConfigProperty annotation on Map<String, String> field doesn't filter the configuration values, but populates all configuration entries in Map #4414

Closed
vamshikrishna83 opened this issue Jun 20, 2022 · 5 comments · Fixed by #4653
Assignees
Labels
bug Something isn't working config P3

Comments

@vamshikrishna83
Copy link

vamshikrishna83 commented Jun 20, 2022

For a map configuration field like below, i expect the map to be populated with all configuration entries under configKey section, but the map is populated with all possible configuration entries - without any filtering.

    @Inject
    @ConfigProperty(name = "configKey")
    Map<String, String> configKeyMap;

Is this behaviour expected??? Is there a provision to filter out the configuration entries that just match to the name mentioned in the annotation?

If i understand correctly, filtration happens properly for List and Set field types (at-least as per the code for those branches). Why the behaviour is different for Map alone???

Environment Details

  • Helidon Version: 2.5.1
  • Helidon MP
  • JDK version: JDK 17
  • OS: Windows 11
  • Docker version (if applicable): NA
@tomas-langer
Copy link
Member

MIcroProfile Config does not specify injection of java.util.Map. We do injection into a map, but you will always get the full Map of known key/value pairs.

@tomas-langer tomas-langer added the bug Something isn't working label Jun 20, 2022
@tomas-langer
Copy link
Member

As Helidon, we have these options:

  1. keep the current behavior and mark this "works as designed" - this creates an unusual behavior, where config property key is fully ignored (not according to spec, future spec changes may create backward incompatible behavior)
  2. modify the injection to honor the specified key and filter values (not according to spec, future spec changes may create backward incompatible behavior)
  3. remove support for injection of java.util.Map and wait for what the specification does

Both 1. and 2. suffer from possible performance impact and also from the case that not all sources can provide full set of their properties (so the map may not be complete).

@vamshikrishna83
Copy link
Author

vamshikrishna83 commented Jun 21, 2022

@tomas-langer Thanks for the details.

I see a similar discussion in this MicroProfile issue as well.

Last, but not least, I noticed that the implementation behaviour has changed from filtering a map to the current behaviour in Helidon MP. as part of this PR. I am curious now, wasn't this a breaking / backward incompatible behaviour?

@tomas-langer
Copy link
Member

As this is not tested, we did not catch the difference in behavior. This was quite a big change (we had to switch away from using Helidon SE Config to using a full implementation of MP Config due to differences in handling environment variables), I have missed it when implementing it.
We will get back to this and restore the original behavior

@tomas-langer
Copy link
Member

In the PR:

  • injection of map with a name defined in @ConfigProperty will inject only properties prefixed by that key, with the key removed from keys of the map
  • injection of map with default name will inject all properties available in config
  • I have added a test to verify this behavior

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working config P3
Projects
Archived in project
3 participants