Refactor XmlFactories into their hardening target factories. - #53
Conversation
e7d4d8f to
e786e7c
Compare
Missing Java 8 methods will be added in a follow up PR.
e786e7c to
16a29b5
Compare
| * @see org.apache.commons.xml | ||
| */ | ||
| final class HardeningDocumentBuilderFactory extends DocumentBuilderFactory { | ||
| public final class HardeningDocumentBuilderFactory extends DocumentBuilderFactory { |
There was a problem hiding this comment.
I have mixed feelings about using the wrapper classes as public entry points:
Pros:
- We save up on the number of classes.
Cons:
- Users can use
instanceofon the implementation class of the wrapper. I am not sure if this is good or bad. Since users could always compare implementation by class name, this is not a blocker. - This makes a Multi-Release JAR harder to produce without duplicating a lot of code. Therefore we are left with calling the Java 9 and Java 13 methods by reflection. Knowing what users do with our JARs (e.g.
log4j-api), maybe it is better, since there are a lot of shaders out there that don't know how to shade an MRJ.
If we choose this model (i.e. wrapper class == public entry point and Java 9/13 methods called by reflection), I would recommend to merge this class with DocumentBuilderHardener in a follow-up PR.
There was a problem hiding this comment.
without duplicating a lot of code.
That shouldn't be the case if we subclass, if that matters that much, for example a HardeningDocumentBuilderFactory13 could extend HardeningDocumentBuilderFactory9 could extend HardeningDocumentBuilderFactory but I'm not sure an MRJ would allow that.
| public static DocumentBuilderFactory newInstance() { | ||
| return DocumentBuilderHardener.harden(DocumentBuilderFactory.newInstance()); | ||
| } |
There was a problem hiding this comment.
This method hides DocumentBuilderFactory, which is not a problem per-se, but is a problem for the methods that we are not hiding, which will return not hardened methods.
There was a problem hiding this comment.
Like what? HardeningDocumentBuilderFactory.newDocumentBuilder() returns a safe DocumentBuilder
|
I compared this design with #54 and I prefer this one: it keeps all (or nearly all) the code for a given JAXP factory type in a single class. I would only change a few things:
I dropped the Multi-Release jar idea: users shade this library without setting |
|
Arg, I meant to open a PR in my fork, not here, apologies. |
Refactor XmlFactories into their hardening target factories.
Missing Java 8 methods will be added in a follow up PR.
Before you push a pull request, review this list:
[ ] I used AI to create any part of, or all of, this pull request. Which AI tool was used to create this pull request, and to what extent did it contribute?mvn; that'smvnon the command line by itself.