This issue has been created
There is 1 update.
 
 
XWiki Commons / cid:jira-generated-image-avatar-e20bb7d0-3ef2-4102-b29e-a7b275a81ed6 XCOMMONS-3662 Open

Static service cache retains old extension class instances after classloader reload, causing ClassCastException

 
View issue   ยท   Add comment
 

Issue created

 
cid:jira-generated-image-avatar-859f0b12-b21a-4002-8d58-c0efda2c6f3e Nikita Petrenko created this issue on 20/May/26 10:34
 
Summary: Static service cache retains old extension class instances after classloader reload, causing ClassCastException
Issue Type: cid:jira-generated-image-avatar-e20bb7d0-3ef2-4102-b29e-a7b275a81ed6 Bug
Affects Versions: 17.10.0
Assignee: Unassigned
Components: Classloader
Created: 20/May/26 10:34
Priority: cid:jira-generated-image-static-major-61f20124-1774-4f25-bf59-4de881e024ff Major
Reporter: Nikita Petrenko
 
 

1 update

 
cid:jira-generated-image-avatar-859f0b12-b21a-4002-8d58-c0efda2c6f3e Changes by Nikita Petrenko on 20/May/26 10:39
 
Description: I don't have reproduction steps, I've just encountered it randomly after downgrading/upgrading [Formula macro|https://extensions.xwiki.org/xwiki/bin/view/Extension/Formula%20Macro/] on demo XWiki Jetty/HSQLDB.

Where instead of rendered macro, I have stacktrace
{noformat}
Failed to execute the [formula] macro. Cause: [Exception java.lang.ClassCastException: class net.sourceforge.jeuclid.converter.ImageIODetector cannot be cast to class net.sourceforge.jeuclid.converter.ConverterDetector (net.sourceforge.jeuclid.converter.ImageIODetector is in unnamed module of loader 'wiki:xwiki'; net.sourceforge.jeuclid.converter.ConverterDetector is in unnamed module of loader 'wiki:xwiki') [in thread http://localhost:8080/xwiki/bin/view/Sandbox/TestPage1]].

java.lang.NoClassDefFoundError: Could not initialize class net.sourceforge.jeuclid.converter.ConverterRegistry$SingletonHolder
.....
Caused by: java.lang.ExceptionInInitializerError: Exception java.lang.ClassCastException: class net.sourceforge.jeuclid.converter.ImageIODetector cannot be cast to class net.sourceforge.jeuclid.converter.ConverterDetector (net.sourceforge.jeuclid.converter.ImageIODetector is in unnamed module of loader 'wiki:xwiki'; net.sourceforge.jeuclid.converter.ConverterDetector is in unnamed module of loader 'wiki:xwiki') [in thread http://localhost:8080/xwiki/bin/view/Sandbox/TestPage1]
....
{noformat}

Restarting XWiki resolves the issue.

Thanks [~MichaelHamann] for findings and  below details

A classloader conflict can occur after installing, upgrading, or removing JAR-based extensions without a full XWiki restart.

Root cause appears to be {{org.apache.xmlgraphics.util.Service}} (loaded from the XWiki WAR via xwiki-platform-oldcore), which maintains an internal static cache of discovered service implementations. Since this class comes from the WAR, it is not reloaded when extension classloaders are refreshed.

If a service implementation originating from an extension JAR (e.g. {{net.sourceforge.jeuclid.converter.ImageIODetector}}) is cached there, the cache may retain an instance tied to the old extension classloader after extension reload.

Subsequent code execution then attempts to use the cached old instance together with classes loaded from the new extension classloader, causing class identity mismatch errors such as:

{noformat}
java.lang.ClassCastException: net.sourceforge.jeuclid.converter.ImageIODetector
cannot be cast to net.sourceforge.jeuclid.converter.ConverterDetector
{noformat}

In my case, this breaks JEuclid ConverterRegistry initialization and causes Formula Macro rendering failure:
{noformat}
java.lang.NoClassDefFoundError: Could not initialize class net.sourceforge.jeuclid.converter.ConverterRegistry
{noformat}