Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Classloader matching for BeanDeploymentArchives #24933

Merged
merged 1 commit into from
Apr 23, 2024

Conversation

lisa-lthorrold
Copy link
Contributor

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:

public <T> CDIInjectionContext<T> createManagedObject(Class<T> managedClass, BundleDescriptor bundle, boolean invokePostConstruct) {

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 a classcastexception if subsequent requests for the same beanclass is coming from a different classloader (i.e. the classloader of the managedClass 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.

Copy link
Contributor

@dmatej dmatej left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, I think you are right! Thank you!

@dmatej dmatej added this to the 7.0.15 milestone Apr 23, 2024
@dmatej dmatej added the bug Something isn't working label Apr 23, 2024
@dmatej dmatej merged commit f9ec5d4 into eclipse-ee4j:master Apr 23, 2024
2 checks passed
@arjantijms
Copy link
Contributor

I was a bit slow to see this PR, but really great work! Thanks from me too!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants