could you describe your use-case in more detail? Weld usually wraps and rethrows the exception. Whether the problem is reported or not depends on the context, i.e. the situation in which the contextual instance is created.
Sorry for the delay, email problems and I didn't get notification that you had responded.
Not too much more detail than:
- Running in an SE environment, we have multiple containers.
- A typical @ApplicationScope bean that has a method annotated with @PostConstruct
- When the container instantiated it (to satisfy an injection point in another App scoped bean) and invoked the post construct method, an NPE was thrown in some subordinate code.
- The container apparently caught and did not report the exception, and it wasn't added to the App context. I debugged this at the time down into the Weld code, but don't have exact details for you. I did inspect the App context after the attempt to construct the bean, and confirmed that the instance was not present.
- Later, a method in that class that @Observes an event was triggered, and it tried to construct another instance (since the first failure resulted in it not being in the context), which led to application failures since the initial post construct logic had not completed.
If need be, I can try to recreate the failure mode (we've since corrected our code to avoid the problem). Just let me know what additional information you need. Thanks for your help.
Yep, a simple reproducer/test application would be really helpful. If it was too complicated to extract the beans then the way "a typical @ApplicationScopes bean" is created/accessed might be interesting info.
Ok, a little more info and an example to reproduce it.
One key was that the invocation of a method on the App scoped bean was happening in a SwingWorker, which has an evil habit of eating exceptions and not reporting them. So, in the example (which is a maven project that I've attached, just run the command in "runme" to execute it), I wrap the invocations in a try/catch to mimic that behavior. So, it appears that the Weld core doesn't report the failure, but it does wrap it in a WeldException and throws that, which I'm assuming is the desired/correct behavior for Weld?
So, this is something that I'll probably need to handle in our application infrastructure if this is expected behavior from Weld.
CdiFailure.tar.gz 8.4 KB
Yes, this is expected. Weld wraps checked exceptions - in this case
java.lang.reflect.InvocationTargetExceptionwhich holds the NPE in its