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

AbstractConfiguration#initialize - making two passes generates invalid configuration - no check if initialization has already been performed #3449

Open
JWT007 opened this issue Feb 10, 2025 · 1 comment

Comments

@JWT007
Copy link
Contributor

JWT007 commented Feb 10, 2025

Log4j 2.24.3

Repeated calls to the Configuration#doConfigure method discard appenders (and maybe other inforrmation).

In my example, I have a configuration with two defined appenders ("CONSOLE" and "RollingFile").

Taken from another test case, lets assume I use a BuiltConfiguration with a ConfigurationBuilder and create the and initialized configuration and then initialize it again (the first initialization happens in the build method if I don't call builder.build(false). (Admittedly, this is redundant and strictly incorrect; however, it is possible and I found an instance of this in the Configurator1Test unit-test.)

final Configuration config = builder.build();
config.initialize();

In the first pass, the rootNode tree is processed and through a call to PluginElementVisitor#visit(....) all nested nodes are removed and the top level child node is assigned an built object.

Image

If a second pass is made, the config.initialize() method performs no check to see if it has already been initialized (State.INITIALIZED or later). This results in another runthrough of doConfigure() and now the child nodes are missing because they have been visited and removed,

Here before the 2nd-pass of createConfigurationon the "Appenders" node:

Image

Now however, due to the missing child information, the object list of configured appenders is empty and the two previously defined appenders are gone.

Image

So the second configure cleared the previous run's appenders (and possibly other nested configuration).

I think the easy solution would be to test the state in the initialize method and if not INITIALIZING just log and return; however, I don't know if that would have other side-efffects.

@ppkarwasz
Copy link
Contributor

@JWT007,

Thanks for the report. I would couple it #1653: probably all lifecycle methods are not idempotent.

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