This issue was first raised in #3088 <https://github.com/apache/logging-log4j2/issues/3088>. There I already stated
We shouldn't have partially applied configurations. I suggest [...] throwing exceptions in component initialization failures, and catching them in `ConfigurationBuilder::build` methods. Next I brought this issue up on Slack, and there Ralph shared his agreeing sentiment <https://the-asf.slack.com/archives/C4TQW0M5L/p1739878787097369?thread_ts=1739876477.150569&cid=C4TQW0M5L> too. On Mon, Mar 3, 2025 at 12:53 PM Piotr P. Karwasz <pi...@mailing.copernik.eu> wrote: > Hi all, > > Configuration problems in our builders are handled in multiple ways: > > 1. Sometimes we call `LOGGER.error` and return `null`. > > 2. Sometimes we throw an explicit exception. The types of exceptions > vary: NPE, IllegalArgumentException, IllegalStateException, etc. There > is a `o.a.l.l.core.config.ConfigurationException`, but it doesn't seem > to be used often. > > 3. Sometimes exceptions, usually NPEs, are thrown by the constructor of > a plugin. Most of the time I consider these bugs. > > Could we agree on a preferred way to signal configuration errors? I > don't plan to modify the behavior of old code, but we should apply a > consistent strategy on new builders. > > I do like throwing exceptions, which often simplifies flow control, but > when I started working on Log4j, I was told 1. was the way to go. > > On a related matter, Ralph said on Slack that: > > > Failure during configuration should be caught and cause the previous > configuration to remain intact. > > While I agree with this "all-or-nothing" strategy, this is not the way > it currently works. Regardless of the strategy chosen to communicate the > problem, a misconfigured component will simply be omitted. This can > cause problems down the line, like: > > 2025-03-03T11:49:26.081922076Z main ERROR RollingFileAppender 'ROLLING': > When no file name is provided a DirectFileRolloverStrategy must be > configured > 2025-03-03T11:49:26.082046726Z main ERROR Null object returned for > RollingFile in Appenders. > 2025-03-03T11:49:26.083912635Z main ERROR Unable to locate appender > "ROLLING" for logger config "root" > > However, these problems are not fatal and the configuration replaces the > previous one. > > What do you think? > > Piotr > >