JDK-8323740 : java.lang.ExceptionInInitializerError when trying to load XML classes in wrong order
  • Type: Bug
  • Component: xml
  • Sub-Component: jaxp
  • Affected Version: 22,23
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2024-01-15
  • Updated: 2025-01-20
  • Resolved: 2025-01-14
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 25
25 b06Fixed
Related Reports
Relates :  
Description
After JDK-8306055, when anyone attempts to (reflectively) load an XML class that has a dependency on jdk.xml.internal.JdkXmlUtils, for example XMLDocumentFragmentScannerImpl, then a NPE is being thrown and the class initializer of the class fails.

In other words, a class load order constraint has been introduced with JDK-8306055. If jdk.xml.internal.JdkXmlUtils is loaded first and XMLDocumentFragmentScannerImpl second, class loading passes. If XMLDocumentFragmentScannerImpl is loaded first and JdkXmlUtils second class loading fails.

Simple reproducer:

 echo 'new com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl()' | ./bin/jshell -J-showversion --add-exports java.xml/com.sun.org.apache.xerces.internal.impl=ALL-UNNAMED -
openjdk version "23-internal" 2024-09-17
OpenJDK Runtime Environment (build 23-internal-adhoc.sgehwolf.jdk-jdk)
OpenJDK 64-Bit Server VM (build 23-internal-adhoc.sgehwolf.jdk-jdk, mixed mode, sharing)
Exception java.lang.ExceptionInInitializerError
      at XMLDocumentFragmentScannerImpl.<clinit> (XMLDocumentFragmentScannerImpl.java:193)
      at (#1:1)
Caused by: java.lang.NullPointerException: Cannot invoke "[Ljava.lang.String;.clone()" because "com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.RECOGNIZED_PROPERTIES" is null
      at XMLDocumentFragmentScannerImpl.getRecognizedProperties (XMLDocumentFragmentScannerImpl.java:764)
      at XMLDocumentScannerImpl.getRecognizedProperties (XMLDocumentScannerImpl.java:449)
      at XML11Configuration.addRecognizedParamsAndSetDefaults (XML11Configuration.java:1518)
      at XML11Configuration.addComponent (XML11Configuration.java:1462)
      at XML11Configuration.<init> (XML11Configuration.java:612)
      at XIncludeAwareParserConfiguration.<init> (XIncludeAwareParserConfiguration.java:136)
      at XIncludeAwareParserConfiguration.<init> (XIncludeAwareParserConfiguration.java:93)
      at SAXParser.<init> (SAXParser.java:121)
      at SAXParserImpl$JAXPSAXParser.<init> (SAXParserImpl.java:405)
      at SAXParserImpl.<init> (SAXParserImpl.java:137)
      at SAXParserImpl.<init> (SAXParserImpl.java:124)
      at SAXParserFactoryImpl.newSAXParserImpl (SAXParserFactoryImpl.java:104)
      at SAXParserFactoryImpl.setFeature (SAXParserFactoryImpl.java:144)
      at CatalogImpl.getParser (CatalogImpl.java:312)
      at CatalogImpl.parse (CatalogImpl.java:290)
      at CatalogImpl.load (CatalogImpl.java:171)
      at CatalogManager.catalog (CatalogManager.java:73)
      at JdkCatalog.init (JdkCatalog.java:43)
      at XMLSecurityManager.prepareCatalog (XMLSecurityManager.java:305)
      at XMLSecurityManager.<init> (XMLSecurityManager.java:290)
      at SAXParserFactoryImpl.<init> (SAXParserFactoryImpl.java:72)
      at JdkXmlUtils.getSAXFactory (JdkXmlUtils.java:441)
      at JdkXmlUtils.<clinit> (JdkXmlUtils.java:97)
      ...

Expected behaviour:
Class initializer passes (no NPE being thrown).

Actual behaviour:
java.lang.ExceptionInInitializerError is being thrown, caused by an NPE during a clone() operation.

When JdkXmlUtils is being loaded first this works


Additional info:
This used to work with JDK 21.

echo 'new com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl()' | ./bin/jshell -J-showversion --add-exports java.xml/com.sun.org.apache.xerces.internal.impl=ALL-UNNAMED -
openjdk version "21.0.1" 2023-10-17
OpenJDK Runtime Environment (Red_Hat-21.0.1.0.12-4) (build 21.0.1+12)
OpenJDK 64-Bit Server VM (Red_Hat-21.0.1.0.12-4) (build 21.0.1+12, mixed mode, sharing)
<no exception>
Comments
Changeset: e6902cfc Branch: master Author: Liam Miller-Cushon <cushon@openjdk.org> Date: 2025-01-14 17:27:54 +0000 URL: https://git.openjdk.org/jdk/commit/e6902cfca43c7434be9aa4a0dde4e44eae7ebf29
14-01-2025

A pull request was submitted for review. Branch: master URL: https://git.openjdk.org/jdk/pull/22803 Date: 2024-12-18 02:38:28 +0000
18-12-2024

Internal API or unsupported usage; Workaround available (as described in the report): P3 -> P4
16-01-2024