'Error: unnamed module of loader org.eclipse.osgi.internal.loader.EquinoxClassLoader

I am new to the OSGi concept, and any help is appreciated on the below error.

When running the standalone application there are no issues but when the same application is put inside the OSGI bundle we are getting the below error.

Cause exception java.lang.RuntimeException: Could not instantiate parser org.apache.xerces.parsers.SAXParser: java.lang.ClassCastException: class org.apache.xerces.parsers.SAXParser cannot be cast to class org.xml.sax.Parser (org.apache.xerces.parsers.SAXParser is in unnamed module of loader org.eclipse.osgi.internal.loader.EquinoxClassLoader @14b4fcf0; org.xml.sax.Parser is in unnamed module of loader org.eclipse.osgi.internal.loader.EquinoxClassLoader @555c2470)

Please note, the code snippet works with JRE8 + Eclipse 4.4 but failed with the above error with JRE 11 + Eclipse 4.19. In my application, I am invoking the third-party API, which internally tries to do the above casting, and throws an error.

I understood that this is something related to the OSGi class loader, but need steps to find the cause of this issue. We tried to get more information through the OSGi console as it's a huge application, I can see more than 1000 bundles listed if we execute the SS command on the console.

Thanks in advance.

Regards, Hrushi



Solution 1:[1]

This is due to the changes within Java 9 (Jigsaw). See https://www.logicbig.com/tutorials/core-java-tutorial/modules/unnamed-modules.html.

We had similar issues in our product when upgrading to java 11. This has probably something to do with old libraries which export org.xml.sax somehow. We've upgraded or replaced those libraries to get it fixed

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 R.Groote