Skip to content

[4.0.x] Fix @PreDestroy ClassNotFoundException from premature ClassRealm disposal#12232

Merged
gnodet merged 1 commit into
apache:maven-4.0.xfrom
gnodet:cherry-pick-11825-to-4.0.x
Jun 4, 2026
Merged

[4.0.x] Fix @PreDestroy ClassNotFoundException from premature ClassRealm disposal#12232
gnodet merged 1 commit into
apache:maven-4.0.xfrom
gnodet:cherry-pick-11825-to-4.0.x

Conversation

@gnodet
Copy link
Copy Markdown
Contributor

@gnodet gnodet commented Jun 4, 2026

Cherry-pick of #11825

…osal (apache#11825)

* [MNG-8572] Fix @PreDestroy ClassNotFoundException caused by premature ClassRealm disposal

The Plexus Disposable.dispose() lifecycle runs before Sisu's @PreDestroy
callbacks. When dispose() called flush(), it disposed ClassRealms before
@PreDestroy methods on beans loaded from those realms could execute,
causing ClassNotFoundException.

Change dispose() to only clear the cache map without disposing realms.
The flush() method (used for explicit cache clearing between builds)
remains unchanged. ClassRealms are disposed when the PlexusContainer
shuts down after all lifecycle callbacks complete.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Add test for dispose() vs flush() ClassRealm behavior

Verifies that dispose() clears the cache without disposing ClassRealms
(so @PreDestroy callbacks can still execute), while flush() disposes
both the cache and the realms.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
@gnodet gnodet merged commit 1bffa60 into apache:maven-4.0.x Jun 4, 2026
1 check passed
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 4, 2026

@gnodet Please assign appropriate label to PR according to the type of change.

@github-actions github-actions Bot added this to the 4.0.0-rc-6 milestone Jun 4, 2026
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.

1 participant