-
Notifications
You must be signed in to change notification settings - Fork 287
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
WELD-2776 manually registered extensions in Weld SE should reside in synthetic bean archive #2909
Conversation
Hm, the two different BMs in
Whereas the BM instance delivered to the extension method looks like this:
This seems very deliberate as noted here in the codebase. I cannot say I know why is that from the top of my head though; I'll give it another look tomorrow.
Note that the specification doesn't place any requirements on which archive does a bean belong to if defined by an extension. To expand some more, each bean archive has its own bean manager attached and there is certain visibility established between then. This is why swapping out the BMs in your FTR, the specification part you quoted is correct and so id your understanding of it but the typical use case is in something like a WAR application with additional libraries where you might want to limit visibility of your alternatives. Even then, in most cases you're fine using |
After some more digging I am pretty convinced this is behaving as expected. If you move outside of SE and into servlet/EE territory, you'd see that this split makes a lot more sense as there are all the discovered bean archives and then there's |
Thanks a lot for your reply. After having read the specs over and over again, I agree that my |
Well, CDI is build around bean archives and all components come from some such archive or need to reside in one.
The test you are using ( |
I have an impression that
means to add the extension to the synthetic bean archive but lateron Put differently, all of these
should preferably all go into the synthetic bean archive, including the extension, shouldn't they? A simple quick fix (prototype 429622b) makes all tests pass including Obviously that fix is nowhere near ready but shows it could actually work. |
Fair enough. I cannot say what the original intention was but adding them in synthetic archive makes sense. I've created https://issues.redhat.com/browse/WELD-2776 to track this and I hope you won't mind that I'm going to alter this PR a bit before we use it as a fix (squashing, editing commit msg and adding a commit of my own). Last but not least, what version of Weld are you using? Do you need this fixed for 5.1.x or should we just add it to 6.x? |
Added reproducer. Added fix proposal.
d1e6fc0
to
f5d7b1b
Compare
@dev-qnz I have force-pushed into this PR with following changes:
Please take a look if you're OK with it in this state. |
i'm relieved we eventually found an agreement on a bug after all that fuzz. thanks for your patience. i originally found it in 5.1.2. for me is fine to fix it in the master branch. i'll have a look at your changes in a convenient moment. |
Even though it seems to work I'm not yet convinced I could imagine that there is more code operating with prefixes that might somehow benefit in the same way. Or we might want to check that adding bean defining annotations, stereotypes, interceptors and decorators also work with extensions just as without.
|
If we have plenty time and you agree, I might try try to fix it again in a different way (or convince myself of the current solution). In that case I'd appreciate any kind of hint or advice from anyone familiar with Weld, probably you, how to deal with the synthetic archive and |
The extension location prefix is only ever used for extensions added in Weld SE manually, so that's a solid way to detect it.
I don't see what you mean here, adding the stereotypes, interceptor etc. isn't affected by this. All this PR does is change where the manually registered extension resides.
It doesn't affect the test; not this Arq. setup - I used one where it just puts together an artificial classpath for Weld but you are still in control of the CDI container bootstrap.
I understand but I kept it in intentionally - it's a good assertion of the initial setup and clearly shows the intention and the way it should work later with the extension.
I asked my colleague for a review but once we get that, I'd rather vote for getting this in as it doesn't seem to break anything.
The tricky part is that the whole bootstrap process and bean deployment creation is not necessarily aware of any synthetic archive - the same logic is used in SE, servlet and full EE. Which is why I chose the String comparison. |
After reconsideration is all fine now for me as far as discussed so far. Still, the following code bothers me:
and so I tried to refactor Considering this refactoring we might just as well continue with the current version here (f5d7b1b). |
impl/src/main/java/org/jboss/weld/util/DeploymentStructures.java
Outdated
Show resolved
Hide resolved
impl/src/main/java/org/jboss/weld/bootstrap/events/AbstractBeanDiscoveryEvent.java
Outdated
Show resolved
Hide resolved
Move the test to environments/se/tests and refactor so that it uses Arq. like other tests.
719d095
to
340dcb1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good.
Thank you @dev-qnz for bringing this up and for the PR drafts you sent 👍 |
I don't fully understand what exactly happens in the two new tests, so this may just as well be a question only but nevertheless it looks suspicious enough to ask.
In
org.jboss.weld.util.Beans.removeDisabledBeans
I figure a breakpoint on line 221 reveals that alternative beans are removed from the set of beans because the wrongbeanManager
'senabled
is checked for enabled alternatives.(While AfterBeanDiscoveryAddBeanTest looks more or less ok in my opinion and limited understanding as a valid test, AlternativeInBeanDeploymentArchiveTest just about reproduces the same or a similar behavior but may have any kind of shortcomings.)
Adding
@Priority
to@Alternative
seems to work around the problem. According to my understanding of https://jakarta.ee/specifications/cdi/4.0/jakarta-cdi-spec-4.0#bean_archive that should not be necessary.