Skip to content

[4.4.x] Remove static ThreadLocal caching in XmlUtils to prevent ClassLoader leaks#2532

Merged
jbonofre merged 1 commit into
apache:karaf-4.4.xfrom
jbonofre:backport/2516-xmlutils-classloader-leak-karaf-4.4.x
Apr 15, 2026
Merged

[4.4.x] Remove static ThreadLocal caching in XmlUtils to prevent ClassLoader leaks#2532
jbonofre merged 1 commit into
apache:karaf-4.4.xfrom
jbonofre:backport/2516-xmlutils-classloader-leak-karaf-4.4.x

Conversation

@jbonofre
Copy link
Copy Markdown
Member

Backport of #2516 to karaf-4.4.x.

The static ThreadLocal fields holding DocumentBuilderFactory, TransformerFactory and SAXParserFactory pin the ClassLoader of the XML provider bundle on long-lived Karaf worker threads. When that bundle is updated or refreshed, the old ClassLoader can never be GC'd, causing zombie bundles and Metaspace growth.

This patch removes the ThreadLocal caching and creates fresh factory instances per call. The public API is unchanged.

Fixes #2278

…leaks

The static ThreadLocal fields holding DocumentBuilderFactory, TransformerFactory
and SAXParserFactory pin the ClassLoader of the XML provider bundle on long-lived
Karaf worker threads. When that bundle is updated or refreshed, the old
ClassLoader can never be GC'd, leading to zombie bundles and Metaspace growth.

Create fresh factory instances per call instead of caching them. The public API
is unchanged.

Fixes apache#2278
@jbonofre jbonofre force-pushed the backport/2516-xmlutils-classloader-leak-karaf-4.4.x branch from ae2d8f8 to bb57b63 Compare April 15, 2026 14:01
@jbonofre jbonofre merged commit 2a4911b into apache:karaf-4.4.x Apr 15, 2026
6 checks passed
@jbonofre jbonofre deleted the backport/2516-xmlutils-classloader-leak-karaf-4.4.x branch April 15, 2026 15:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants