apache / apache/logging-log4j2

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

Open
#3,449 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
3.6k
Forks
1.7k
Avg merge
21h 30m
Merged PRs (30d)
27

Description

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](https://github.com/user-attachments/assets/878f1672-6a42-427e-b55f-4910aa850d12)

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 `createConfiguration`on the "Appenders" node:

![Image](https://github.com/user-attachments/assets/ea4ab566-9925-4cec-a92f-d38af072a2c8)

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](https://github.com/user-attachments/assets/2b9bcfdd-0e04-48cb-8456-3d0091845ac3)

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.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.