Skip to content
This repository has been archived by the owner on Oct 7, 2024. It is now read-only.

PLAT-3546: Validating Config-files #797

Merged
merged 1 commit into from
Sep 26, 2024

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.

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added a test that compares priorities between this module and the config module.

@@ -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.

… 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.
@nolexa nolexa force-pushed the PLAT-3464-validation-of-config-classes branch from f6b0eaa to d0e916d Compare September 23, 2024 07:45
* <p>
* As logging can be part of the configuration file and the configuration file
* could be missing, we have a side effect of setting up and initializing a LoggingFactory
* that doesn't depend on ConfigFactory, if the configuration file is missing.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is not clear if this justification is still vald.

Copy link
Member

Choose a reason for hiding this comment

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

it is no longer valid.

Copy link

sonarcloud bot commented Sep 23, 2024

@jepp3 jepp3 merged commit ef983b0 into master Sep 26, 2024
2 checks passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants