Error creating Document builder

Which IIQ version are you inquiring about?

Version 8.3

Please share any images or screenshots, if relevant.

Share all details related to your problem, including any error messages you may have received.

Hi sailpoint community could you please help me with the following error:

I am trying to create a DocumentBuilder object but is trowing the error:

Error in method invocation: Cannot access method newDocumentBuilder() in ‘class com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl’ :java.lang.IllegalAccessException: class bsh.Reflect cannot access class com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl (in module java.xml) because module java.xml does not export com.sun.org.apache.xerces.internal.jaxp to unnamed module.

The error is in the line

DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();

I already import the following classes but still not working :

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.OutputKeys;
import javax.xml.tansform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.TransformerFactoryConfigurationError;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;  
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

Does anyone have a suggestion on how to fix the error?

Thanks for your help

@lfagua -

Possible cause 1 - The required 3rd party jars are not available in classpath

Use of Third-party Libraries in Customizations, Not Available OOTB

Before starting, ensure that all third-party libraries used:

  • Are from an authentic/trusted source.
  • Do not incur legal obligations.
  • Are free from known security vulnerabilities.
  • Are compatible with the supported JDK versions of IdentityIQ.

Never add the following libraries explicitly to the classpath of any application, as they can cause class loading or conflict errors (these libraries are infrastructure libraries provided OOTB and are shared across IdentityIQ):

  • Openconnector framework classes or jar: Responsible for providing connector infrastructure like interfaces and functionality control.
  • Any OOTB connector bundle jar.
  • Aspect.jar*: Responsible for providing the aspect infrastructure.
  • Commons-logging.jar, log4j-.jar, slf4j-api.jar*: Responsible for providing logging infrastructure.
  • Bsf.jar* and bsh.jar*: Used to execute Rules.

To enable third-party libraries, complete the following:

  1. Create a subfolder in the WEB-INF/lib-connectors folder. For example, WEB-INF/lib-connectors/XYZcustom
  2. Save a copy of the required third-party libraries for the customization.
  3. In the Application Definition for your application that is using this customization, add a connector-classpath entry to the Attributes map. This entry can point to the jars individually or to the folder, as shown in the example below. This adds the specified jar file, or all jars in the folder, to the classpath for the connector.
<!-- IIQ filePathPrefix = Directory Path including /WEB-INF  -->
      <entry key="connector-classpath"> 
          <value>   
            <List>   
              <String>\lib-connectors\JDBCCustom\commons-codec-1.9.jar</String> <!-- path of single jar -->   
              <String>\lib-connectors\ JDBCCustom\</String> <!-- path of folder, all jars under the folder will be added to classpath -->   
            </List>   
          </value>   
        </entry>

For more details, please check this link.

Possible Cause 2

This error indicates a problem with access permissions when trying to invoke the newDocumentBuilder() method on the DocumentBuilderFactoryImpl class from the com.sun.org.apache.xerces.internal.jaxp package. It is likely caused by the module system introduced in Java 9.

To resolve this issue, you can try the following:

  1. Update Java Version: Ensure that you are using a Java version that is compatible with your code. Newer versions of Java might have resolved certain module-related issues.
  2. Use Official APIs: Avoid using internal classes such as com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl. Instead, use the official APIs provided by Java, such as javax.xml.parsers.DocumentBuilderFactory.
import javax.xml.parsers.DocumentBuilderFactory;

And then, create a DocumentBuilderFactory instance:

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

Add Appropriate Modules: If you are using a modular project, make sure that you have the necessary modules in your module-info.java file. For example:

module your.module.name {
    requires java.xml;
}
  1. Make sure that your module has the required dependencies specified.
  2. Update Dependencies: If you are using external libraries, make sure they are compatible with the Java version you are using. Update your dependencies to the latest versions if needed.
  3. Review Security Policies: Check if there are any security policies or restrictions in place that might be affecting the accessibility of the classes.
  4. Check for Reflective Access Warnings: If you are using reflection in your code, you might encounter issues due to module restrictions. Ensure that your reflective access is legitimate and consider adding appropriate --add-opens or --add-exports flags to your JVM arguments if necessary.For example:
--add-opens java.xml/com.sun.org.apache.xerces.internal.jaxp=ALL-UNNAMED

This link might be helpful.

Mark it as solution, if it helps.

2 Likes

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.