Hello,

Inspired by the StackOverflow question [1], where `log4j-1.2-api`
provided the user with a totally useless error message, I was looking
at the validation of components from the perspective of a Log4j 1.x
bridge `Builder` plugin. From what I found there are 3 ways to
validate parameters:

1. There are nice annotations that are checked if the `PluginBuilder`
is used (Log4j 1.x bridge `Builder`s don't use it),
2. The same constraints are also checked in the `Builder#build()`
methods of each component. This is not very consistent: the
`RollingFileAppender.Builder#build()` checks the `name` and
`filePattern` attribute again, but the `FileAppender.Builder#build()`
method does no such thing.
3. Some Log4j 1.x bridge builders like the
`RollingFileAppenderBuilder` and `FileAppenderBuilder` perform
constraint checks themselves before calling the
`RollingFileAppender.Builder` and `FileAppender.Builder` and return
`null` if the check fails. Without those checks the Log4j 1.x bridge
`BuilderManager` would build an `AppenderWrapper(null)` and would not
fall back to direct instantiation of the
`org.apache.log4j.RollingFileAppender` class.

 I would like to put some order in the attribute validation, but what
would be the best approach? Should each core `Builder#build()` method
call the `PluginBuilder`'s annotation-driven validation code and only
deal directly with complex constraints?

Piotr

[1] https://stackoverflow.com/q/71149004/11748454

Reply via email to