That doesn't sound good. We have an integration test that verifies @PostConstruct ordering that passes reliably. However, it's not using @Producers and no multi-project setup. The latter seems less likely to cause problems though.
Can you file a JIRA for this? If you have a testcase (i.e. similar to this: https://github.com/errai/errai/blob/master/errai-cdi/weld-integration/src/test/java/org/jboss/errai/cdi/injection/client/test/PostConstructOrderTest.java) to reproduce the problem or even a potential fix, please feel free to send us a pull request.
thanks for the answer. I created the JIRA: [ERRAI-659] Bean available before post construct called - JBoss Issue Tracker
I also tried to reproduce the issue with a test, but was not successful. If I will be able to reproduce it, I will let you know.
I think I found the source of the problem:
- A proxy is generated for Nesting in BootstrapperImpl.
- During AsyncCreationalContext.resolveAllProxies, the post construct methods of all proxied beans are executed.
- In AsyncCreationalContext.finish, resolveAllresolveAllProxies is executed before fireAllInitCallbacks (the same is true for SimpleCreationalContext.finish).
- Nesting.postConstruct is executed during resolveAllProxies.
- Nested.postConstruct is executed during fireAllInitCallbacks.
--> Nesting.postConstruct is executed before Nested.postConstruct.
I am not sure, whether this is the actual problem. Maybe, there should be no proxy for Nesting in the first place.
Interesting. Thanks for digging this far, Jannis.
Just to make sure. Do you experience this problem with both the async (which you seem to be using) and sync bean manager?
Oh, sorry for the confusion. No, I did not experience this problem with the sync bean manager. I only used the async one. I assumed a similar behavior based on the source code of the mentioned methods, but I did not verify it.
Edit: What I also forgot to mention: I am facing the issues during the initialization of the bean manager (starting with Container.onModuleLoad).