davido opened a new pull request, #4329:
URL: https://github.com/apache/logging-log4j2/pull/4329
# Preserve custom Configuration elements under CompositeConfiguration
Fixes #4328.
## Problem
A `CompositeConfiguration` never runs its child configurations'
`doConfigure()`; it configures
only the merged node tree via its own inherited `doConfigure()`. Any element
a custom
`Configuration` adds programmatically in a `doConfigure()` override is
therefore dropped under a
composite configuration, on both the initial build and every
reconfiguration. See #4328.
## Change
- **`AbstractConfiguration#postConfigure(Configuration target)`** — new
hook, `public` with a
no-op default. (`public` because `CompositeConfiguration` is in a
different package and calls
it on sibling instances; `protected` would not compile there. Happy to
switch to a
`Configuration` interface method or a different name if preferred.)
- **`CompositeConfiguration#doConfigure()`** — override that calls
`super.doConfigure()` (merged
tree) and then `child.postConfigure(this)` for each source configuration.
```java
// AbstractConfiguration
public void postConfigure(final Configuration target) {
// no-op by default; a custom Configuration overrides this to contribute
programmatic elements.
}
// CompositeConfiguration
@Override
protected void doConfigure() {
super.doConfigure();
for (final AbstractConfiguration config : configurations) {
config.postConfigure(this);
}
}
```
Because `reconfigure()` rebuilds a `CompositeConfiguration`, the hook runs
on every
reconfiguration as well.
## Test
`CompositeConfigurationPostConfigureTest` (in `log4j-core-test`) builds a
composite whose first
child is a custom `Configuration` that contributes a programmatic appender
via `postConfigure`,
and asserts the appender is present after the initial build and after
`reconfigure()`.
Verified: the test **fails** without the
`CompositeConfiguration.doConfigure()` wiring
(`postConfigure contribution missing`, 2 failures) and **passes** with it (2
passing).
## Notes for reviewers
- Targets the `2.x` line (`2.27.0-SNAPSHOT`); `@since` is set to `2.27.0`.
Can port to
`main` (3.x) if desired.
- Formatting verified with `spotless:check` (palantir-java-format). No
changelog entry added.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]