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

Add version of org.agrona.SystemUtil#loadPropertiesFile that can preserve existing values #226

Closed
vyazelenko opened this issue Nov 4, 2020 · 1 comment

Comments

@vyazelenko
Copy link
Contributor

Utility methods SystemUtil#loadPropertiesFile and SystemUtil#loadPropertiesFiles work by overwriting system properties with the values from the given file(s). That makes sense especially when multiple files are used since the later files overwrite values of the previous files.

However this behavior is surprising for people come from frameworks such as Spring. In Spring for example explicitly set system property takes precedence over values in the property files. So the following is working with Spring but not with Agrona:

java -cp ... -Dmy.prop=IMPORTANT MyApp default.properties

With Spring value of my.prop will be IMPORTANT but with Agrona it will be DEFAULT (i.e. value from the default.properties file).

Therefore we should probably consider providing a version that can preserve property value if it is already set. One interesting question is how to do SystemUtil#loadPropertiesFilesPreserveExisting. We want to honor already set property when the method was called but if one is not set it should behave the same as the original SystemUtil#loadPropertiesFiles, i.e. next file should overwrite previous file values in the list.

@mjpt777
Copy link
Contributor

mjpt777 commented Nov 4, 2020

We could provide an override of the loadPropertiesFiles method that takes an enum as the first argument. The enum can specify which priority is applied. The existing method can stay with it defaulting to one of the enum values.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants