There are 2 updates.
 
 
XWiki Commons / cid:jira-generated-image-avatar-e9069a51-5417-4e0c-a36e-c08c334c4ae2 XCOMMONS-3662 Open

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

 
View issue   ยท   Add comment
 

2 updates

 
cid:jira-generated-image-avatar-66df140b-efe3-4fbd-8f0b-b67581933f1d Changes by Nikita Petrenko on 20/May/26 12:05
 
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
error . Cause: [ Exception java ^full stack trace . 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 txt ] ].


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}
Attachment: full stack trace.txt