Skip to content

Fix @PreDestroy ClassNotFoundException from premature ClassRealm disposal#11825

Open
gnodet wants to merge 1 commit intomasterfrom
fix/realm-cache-dispose-ordering
Open

Fix @PreDestroy ClassNotFoundException from premature ClassRealm disposal#11825
gnodet wants to merge 1 commit intomasterfrom
fix/realm-cache-dispose-ordering

Conversation

@gnodet
Copy link
Copy Markdown
Contributor

@gnodet gnodet commented Mar 23, 2026

Summary

  • DefaultExtensionRealmCache, DefaultPluginRealmCache, and DefaultProjectRealmCache implement Plexus Disposable
  • Their dispose() method called flush(), which disposed ClassRealms via realm.getWorld().disposeRealm()
  • Plexus Disposable.dispose() runs before Sisu's @PreDestroy callbacks, so beans loaded from extension/plugin ClassRealms would get ClassNotFoundException when their @PreDestroy methods executed
  • Fix: dispose() now only clears the cache map without disposing realms. The flush() method (for explicit cache clearing between builds) remains unchanged.

Fixes #10571

Test plan

  • Verify plugins with @PreDestroy lifecycle methods no longer throw ClassNotFoundException at shutdown
  • Verify flush() still works correctly for cache clearing between builds (e.g., resident Maven)

🤖 Generated with Claude Code

… 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>
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.

[MNG-8217] ClassNotFoundException in @PreDestroy method when Maven extension declared in pom.xml

1 participant