3

I have the following code in order to set the Entity Expansion limit in Java with JDK8:

    DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
    documentBuilderFactory.setAttribute(Constants.JDK_ENTITY_EXPANSION_LIMIT, "1000");
    DocumentBuilder docBuilder = documentBuilderFactory.newDocumentBuilder();

And these are the corresponding packages I'm importing:

import javax.xml.parsers.DocumentBuilderFactory;
import com.sun.org.apache.xerces.internal.impl.Constants;

I need to migrate from JDK8 to JDK11 and unfortunately the com.sun.org.apache.xerces.internal.impl.Constants package is not supported in JDK11 anymore.

What is the alternative in JDK11? is there another package with this JDK_ENTITY_EXPANSION_LIMIT constant that is supported in JDK11?

Omered
  • 81
  • 5
  • That class still exists in Java 11, but is not exported from the java.xml module. You may want to specify exactly the problem you run into when trying to use this in Java 11 to get a better answer. For example, adding `--add-exports java.xml/com.sun.org.apache.xerces.internal.impl=ALL-UNNAMED` would be a workaround, but I'm not sure if there is any better solution. Alternatively, you could specify the string `"http://www.oracle.com/xml/jaxp/properties/entityExpansionLimit"` – Mark Rotteveel Jun 27 '21 at 11:33
  • Thanks Mark, When I build my project I just get the following error "package com.sun.org.apache.xerces.internal.impl is not visible" – Omered Jun 27 '21 at 12:08
  • Please check [this issue](https://github.com/adoptium/adoptium-support/issues/199) for alternatives – samabcde Jun 27 '21 at 12:37

0 Answers0