Classloader matching for BeanDeploymentArchives #24933
Merged
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.
The same beanClass may be within several BeanDeploymentArchives. In it's current form, it returns the first matching BDA by checking if the beanClass is can be found within that BDA. If the incorrect BDA is returned, for example in:
glassfish/appserver/web/weld-integration/src/main/java/org/glassfish/weld/services/CDIServiceImpl.java
Line 418 in 5d59bb6
then the classloader of the instantiated object in
createManagedObject
will belong (based on https://github.com/weld/core/blob/aab0ff03a84ea5718a515e9193a64b190e8f8479/impl/src/main/java/org/jboss/weld/manager/BeanManagerImpl.java#L1176) to the initiating class loader which first created the managed bean. This results in aclasscastexception
if subsequent requests for the same beanclass is coming from a different classloader (i.e. the classloader of themanagedClass
is disregarded).The change here tightens the condition for returning the correct BDA, by matching it's module class loader to the incoming beanClass to ensure no
classcastexception
is thrown when the generated objected is cast back to beanClass.