Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XmlConfiguration keeps relevant fields private without providing protected accessors making subclassing difficult #3360

Open
JWT007 opened this issue Jan 6, 2025 · 0 comments

Comments

@JWT007
Copy link
Contributor

JWT007 commented Jan 6, 2025

Log4j 2.24

The XmlConfiguration implementation is non-final meaning it is possible to subclass it to provide additional custom functionality; however: the most relevant class field rootElement is private making it near impossible to do anything useful in the subclass.

It would be helpful (and prevent making a complete copy of the implementation) to at the very least provide a protected accessor for this field:

i.e. protected Element getRootElement()

This way, a custom subclass has a chance to perform some custom handling in public void setup() before the hierarchy is constructed.

Most of the AbstractConfiguration configuration-relevant fields are protected (i.e. rootNode) - but it seems someone didn't stick to that approach in the XmlConfiguration implementation.

SIDE NOTE: It seems the complexity of the currrent XmlConfiguration could be greatly reduced by sticking a little more closely to SRP (single-responsibility principle) and offloading the instantiation/configuration of the DocumentBuilderFactory and maybe the validation to separate utility classes .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant