Remove thread-context-classloader hack in Weld BDA; rely on per-BDA ResourceLoader SPI#26090
Open
renatsaf wants to merge 1 commit into
Open
Conversation
…esourceLoader SPI BeanDeploymentArchiveImpl.getBeanClasses() set the thread context classloader to the BDA's module classloader as a side effect, a workaround for WELD-781 from before Weld offered an SPI to control the classloader per bean deployment archive. The side effect leaked into any caller of this getter (e.g. toString()) and, when the BDA classloader is a custom one, remained set for the rest of the Weld deployment because GlassFish only reset it at the end of WeldDeployer.enable(). Weld now resolves classes and resources of each archive through the per-BDA ResourceLoader SPI, which GlassFish already registers in WeldDeployer.enable() using getModuleClassLoaderForBDA(); proxy generation goes through ProxyServices. The TCL manipulation is therefore redundant. Make getBeanClasses() a pure getter and drop the dependent machinery: the deploymentComplete flag with its accessors, the originalClassLoader save/restore and deploymentComplete() call in WeldDeployer.enable(), and the now-orphaned AS-CDI-00001 "Setting Context Class Loader" log message. Fixes eclipse-ee4j#25593 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #25593.
BeanDeploymentArchiveImpl.getBeanClasses()set the thread context classloader (TCL) to the BDA's module classloader as a side effect — a long-standing workaround for WELD-781, introduced back in #18152, from before Weld offered an SPI to control the classloader per bean deployment archive.That side effect is fragile: a getter mutates global thread state, so it leaks into any caller (e.g.
toString()), and when a BDA uses a custom classloader the TCL stays set for the rest of the Weld deployment because GlassFish only restores it at the end ofWeldDeployer.enable().The SPI has long since landed and GlassFish already uses it:
ResourceLoader— registered inWeldDeployer.enable()withgetModuleClassLoaderForBDA(), so Weld loads each archive's classes/resources with the correct classloader;ProxyServices— resolves the bean's own classloader for proxy generation.The TCL manipulation is therefore redundant.
Changes
BeanDeploymentArchiveImpl.getBeanClasses()is now a pure getter (no TCL side effect).deploymentCompleteflag and itsis/setaccessors, theoriginalClassLoadersave/restore anddeploymentComplete()call inWeldDeployer.enable(), and the now-orphanedAS-CDI-00001"Setting Context Class Loader" log message.Notes / risk
Behavioral change: during Weld bootstrap the TCL is no longer mutated to each BDA's module classloader; it stays as the deployment-time classloader.
ProxyServicesImplstill falls back to the TCL only for non-application beans (e.g.UserTransactionproxies), which now resolve against the application classloader — a reasonable choice. As the issue notes there is no functional reproducer today, so correctness rests on the CDI/Weld TCKs (multi-module EARs, RARs, WEB-INF/lib bean archives, built-in-bean proxies).🤖 Generated with Claude Code