Scrivio Interview library
LeadershipAdvanced6 min read · updated 12 November 2026

Several services use JDOM2 or dom4j for XML handling. Both are third-party libraries with slower release activity than the JDK. How do you decide whether to keep them or migrate?

I would decide service by service from evidence: the library's maintenance status, open CVEs, compatibility with our Java versions, and how deeply each service uses it. If a library works, is patched and runs on current Java, keeping it is usually cheaper than a migration that delivers no business value. Either way, I would wrap the usage behind an internal interface so a later move is contained, make secure parser configuration mandatory because both libraries had XXE-prone defaults in older versions, and set a policy for dormant dependencies with owners, review dates and exit plans.

Why this question is asked

Every large Java estate carries libraries that were the obvious choice ten or fifteen years ago and are now quiet. JDOM2 and dom4j are typical: both are open-source XML libraries that made DOM-style editing pleasant in Java, both are still used widely, and both release far less often than the JDK. Interviewers ask this to see whether we can make a measured dependency decision rather than react to a scanner report or a fashion. In this answer, we will gather the facts that matter, weigh keeping against migrating, contain the dependency with a wrapper, make secure configuration mandatory, and set a lasting policy for dormant dependencies.

1A Quick Recap of the Two Libraries

JDOM2 and dom4j both read XML into an in-memory tree with an API designed for Java: real collections, generics in JDOM2, convenient navigation and XPath support. Under the hood they use a SAX parser, usually the JDK's, to read the text, so their parsing security depends on how that parser is configured.

Slower release activity is not automatically a problem. XML 1.0 has not changed in decades, so a mature XML library may simply be finished. The question is whether it still gets security fixes when needed and keeps working on the Java versions we run.

2Gathering the Facts

Before deciding, we collect the same facts for each library and each service that uses it.

Assessment per library and service
QuestionHow we find outExample finding
Is it maintained?release history, issue responsessecurity fixes within weeks, features rare
Open CVEs?dependency scanner, advisoriesfixed in current version, old versions affected
Works on our Java?build and tests on Java 21 and 25passes; no internal JDK APIs used
How deep is the usage?code search for importsservice A: 3 classes; service B: 140 classes
How critical and exposed?service catalogueB parses partner files from the internet
Depth and exposure usually decide more than the library's popularity.

Depth of usage is the number that most changes the answer. A service that uses dom4j in three classes to read one config file can move to the JDK's DOM in an afternoon. A service with 140 classes that pass dom4j Element objects through their business logic would need months, and every one of those classes is a chance to change behaviour.

3Keep or Migrate?

If a library is patched, has no open vulnerabilities in the version we use, and runs on current Java, keeping it is usually the right call. A migration has real costs, engineering time, regression risk and review effort, and no visible business value, because the documents are processed the same way afterwards. We record the decision and its reasons rather than leaving it implicit.

Migration becomes the right call when the library stops getting security fixes, blocks a Java upgrade, or when usage is shallow enough that removing it is cheap and reduces our dependency list. The usual targets are the JDK's own DOM with XPath for small documents, StAX for streaming, or Jakarta XML Binding or Jackson XML when the code really just maps XML to objects.

Step throughDeciding for one service
  1. Maintained, patched and runs on our Java?
    YesGo to the next questionNoPlan migration now
  2. Is usage shallow, a few classes?
    YesMigrate opportunistically, it is cheapNoKeep, wrap and harden
  3. Record decision, owner and review daterevisit at the next Java upgrade

3 steps in order. Play them, or step through them one at a time.

4Contain It Behind an Internal Interface

Whatever we decide, we stop the library from spreading further into business code. A thin internal interface, for example an OrderDocumentReader that returns our own domain objects, keeps JDOM2 or dom4j types inside one package. Business logic then depends on our interface, not on org.dom4j.Element.

Java
public interface PartnerFeedReader {
List<PartnerOrder> read(InputStream in) throws FeedException; // domain types only
}
final class Dom4jPartnerFeedReader implements PartnerFeedReader { // the only class importing org.dom4j
@Override
public List<PartnerOrder> read(InputStream in) throws FeedException {
SAXReader reader = SafeXml.dom4jReader(); // secure settings from one place
// ... map dom4j elements to PartnerOrder records ...
}
}
// later: StaxPartnerFeedReader implements PartnerFeedReader, swapped in without touching callers

An architecture test can enforce that only the adapter package imports org.dom4j or org.jdom2. This turns a possible future migration from a 140-class project into a rewrite of one adapter, tested against the same sample files.

5Make Secure Configuration Mandatory

Both libraries had XML external entity (XXE) problems in older versions: dom4j's SAXReader allowed external entities by default before version 2.1.3, and JDOM2 had a related vulnerability fixed in 2.0.6.1. Check the advisories for the exact versions you run. Upgrading to the fixed versions is the first step, but we should not depend on defaults alone.

The shared helper that creates readers, SafeXml in the sketch above, sets disallow-doctype-decl on the underlying parser and disables external entities, and a build rule flags direct construction of SAXReader or SAXBuilder elsewhere. Services that parse input from outside the company, such as partner uploads, get checked first, and each gets a test that sends a document with an external entity and expects it to be rejected.

6A Policy for Dormant Dependencies

JDOM2 and dom4j are one example of a general problem, so the real fix is a policy. Every dependency that releases rarely gets a named owning team, a review date, typically yearly or at each Java upgrade, and a short exit plan stating what we would replace it with and how big the change would be. The review checks the same facts as above and either renews the decision or schedules the exit.

This makes dependency risk visible and boring. When a scanner reports a new CVE, the owner already knows where the library is used, how it is configured and what the alternative is, so the response takes hours instead of a crisis meeting.

7Follow-up questions

Is it a problem to have both JDOM2 and dom4j in the same estate?

It doubles the things to patch and the APIs people must learn, so for new code I would pick neither and use the approved JDK or binding approaches. For existing code it is not urgent on its own; the wrapper and the review policy keep it under control.

What if the scanner flags a CVE that does not affect how we use the library?

We verify it rather than assume: read the advisory, check whether the vulnerable feature is reachable with our configuration, and record the analysis. If it is not exploitable, we still plan the upgrade, but without an emergency, and we suppress the alert with a written justification and an expiry date.

Would you fork an abandoned library?

Only as a last resort, for a deeply embedded library with no migration path. A fork makes us the maintainers of an XML library, which is rarely a good use of a product team. Migrating the wrapped adapter is almost always cheaper.

8Conclusion

In this answer, we decided whether to keep JDOM2 or dom4j by assessing maintenance, CVEs, Java compatibility and depth of usage for each service. Patched, working libraries are usually cheaper to keep than to migrate, but we contain them behind an internal interface so a later move touches one adapter, make secure configuration mandatory because both had XXE-prone defaults in older versions, and set a dormant-dependency policy with owners, review dates and exit plans.

What to say in the interviewAbout 90 seconds aloud

Open with

I would not decide for the whole company at once; I would assess each library per service. The facts I want are: is it still maintained and does it get security fixes, are there open CVEs in the versions we run, does it build and pass tests on our current Java, and how deep is the usage, a few classes or a hundred.

Then, if they want more

Depth matters most. If the library is patched and works, keeping it is usually cheaper than migrating, because a migration has cost and risk and no business value, and XML itself has not changed. If usage is shallow, I would remove it opportunistically, moving to JDK DOM with XPath, StAX, or Jakarta XML Binding.

Either way, I would wrap it behind an internal interface that returns our own domain objects, so only one adapter imports org.dom4j or org.jdom2, and enforce that with an architecture test. That makes any future move small.

Security is non-negotiable: both libraries had XXE-related defaults in older versions, dom4j before 2.1.3 and JDOM2 before 2.0.6.1 if I remember correctly, so I would upgrade, create readers only through a shared helper with doctype declarations disallowed, and add a test that sends an external entity.

Finally, I would set a policy for dormant dependencies: every one has an owner, a review date and a written exit plan.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the official documentation for the version you use. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "Several services use JDOM2 or dom4j for XML handling. Both are third-party libraries...": https://scrivio-interview-library.netlify.app/java/xml-processing/5a4e13d026/