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

Entire map of nested sections is reset to default when one section is missing a required key #31

Open
BlueTree242 opened this issue Dec 31, 2021 · 4 comments
Labels
bug Something isn't working
Milestone

Comments

@BlueTree242
Copy link

The config is reset when we put a nested section in a map

@A248
Copy link
Owner

A248 commented Dec 31, 2021

Can you elaborate on and clarify the matter? Also, can you state whether this is a bug or a feature request?

@BlueTree242
Copy link
Author

its a bug, when you make map of string and nested section, and soon add new value to nested section, the config is reset

@A248 A248 changed the title Reset config on new options Entire map of nested sections is reset to default when one section is missing a required key Dec 31, 2021
@A248 A248 added the bug Something isn't working label Jan 2, 2022
@A248
Copy link
Owner

A248 commented Jan 2, 2022

This is a bug, but it is a design bug rather than a functional bug. The fix is more difficult than it seems.

When you load the configuration with fallback-to-default behavior, what really happens is default values are created using ConfigurationFactory#loadDefaults. These defaults are then provided to the #load method as auxiliary values (auxiliary values are fallback values). When a configuration option is processed, we have access only to the auxiliary value of the entire configuration option.

Therefore, in the current design, we have only access to the Map<String, YourConfSection> default value but not the YourConfSection default value. Solving this would require a design rework. Possible options:

  • Use a node system of ConfigEntry and ConfigValue<T> objects, which can provide additional metadata. This will happen at some point, but it would be a breaking change, and so must either wait until 2.0 or be established with backwards compatibility in mind.
  • Creating another #load method on ConfigurationFactory which provides more dynamic handling of auxiliary values, such that they could be requested on-demand from different sources.
  • Various "hacks" are possible, including adding a toggle to ConfigurationOptions to provide special behavior for your situation.

@BlueTree242
Copy link
Author

Oh! Looks really complicated, whatever it is i am waiting (let me know when there is a beta)

@A248 A248 added this to the 2.0.0 milestone Jul 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants