Thank you both for your answers, which helped me solve the problems I have with constraint validation. Regarding Ralph's Log4j 1.x bridge validation:
On Sun, Feb 20, 2022 at 9:46 PM Ralph Goers <ralph.go...@dslextreme.com> wrote: > I suspect if we simply extract the values and pass them to the Log4j 2 > component’s > Builder that it won’t be sufficient (I believe the PluginVisitor logic > actually performs > the validation) or the error produced would end up being confusing since it > would > be coming from a Log4j 2 component, not what the configuration specified. I agree, configuring a Log4j 1.x `RollingFileAppender` without a `fileName` and seeing a message about `filePattern` or `DirectFileRolloverStrategy` might be confusing. I submitted PR #768 to solve the main problem I have with the Log4j 1.x bridge validation: I want to be able to return `null` from the `FileAppenderBuilder` without causing an attempt to instantiate `org.apache.log4j.FileAppender` directly. In 2.17.2 this will be possible since Gary added the legacy appender classes, the `FileAppender` will instantiate correctly and will fail on the first message. Regarding Matt's annotation-based validation: On Sun, Feb 20, 2022 at 9:19 PM Matt Sicker <boa...@gmail.com> wrote: > Validation can potentially be done more consistently in the dependency > injection branch I’ve been working on recently, but that’s limited to 3.x. > For 2.x, it might be useful if Builder provided a default method to run all > the constraint validators on its fields. The difficulty here is that there’s > no easy way to add the same for static factory methods, so those are only > enforced when invoked reflectively. In PR #771 I refactored your `PluginBuilder` code, so that it can be called directly from a default `Builder#validate()` method. It's not an ideal solution, since components created through `PluginBuilder` will now validate the same constraints twice, but the alternative was to add those null checks anyway in the `Builder#build` methods anyway. This might save some typing, while waiting for Log4j 3.x. Piotr