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

PLAT-3546: Validating Config-files #797

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

nolexa
Copy link
Contributor

@nolexa nolexa commented Sep 19, 2024

Validation of the config files seems to be broken for a long time. ValidatingConfigFactory did not have effect because its binding was always overridden by the default config factory from the bootstrap binding.

For some reason bootstrap binding was giving the highest priority, thus overriding the bindings of all the auto-bind modules. I could not find any justification for this behaviour. The only class that is bound in the bootstrap module is ConfigFactory, and we want it to be overridden by ValidatingConfigFactory. It looks like it was a bug.

The modules precedence is fixed so that the bootstrap is at the lowest place, overridden by the rest of the modules.

… default config factory because of the bootstrap binding. Validation of the configs did not work. That is fixed by changing the order of the modules binding in relation to the bootstrap binding.
m.preBind();
}

mergedModule = Modules.override(mergedModule)
Copy link
Member

@jepp3 jepp3 Sep 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

checked if the test injector uses this feature to override modules?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TestInjector should indeed override the modules. I made a special case for it.

Copy link
Member

@jepp3 jepp3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

failing build

@Override
public Integer getPrio() {
// We want this module to override the default binding of ConfigFactory
return 110;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any way of creating a test to validate that this actually works, and more importantly continues to work in the future as well?

@@ -28,12 +28,12 @@ void shouldBindImplementationsToTheirInterfaces() {
}

@Test
void shouldUseBootStrapBindingOverDefault() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be a very conscious choice, did you find any hints on why it was this way? It could help prevent reintroducing bugs that this might have resolved.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I don't have any clue why it's done this way. The bootstrap module binds only two things:

                    bind(String[].class).annotatedWith(Names.named("args")).toInstance(args);
                    bind(ConfigFactory.class).toInstance(configFactory);

So it's either the default ConfigFactory class or whatever ConfigFactory compatible class defined in the override modules. I could not find hints why the default factory should always override.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this order of overrides was made just for a single purpose: to promote the TestInjector in DbProxyTest. When this case is fixed, both tests and applications work fine.

… the bootstrap override sequence. The latter is needed for TestInjector take effect. There still are some doubt about the initial justification of having ConfigFactory in the main method. There was an explanation about LoggingFactory. Not clear if it's still valid.
Copy link

sonarcloud bot commented Sep 20, 2024

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

Successfully merging this pull request may close these issues.

3 participants