Note that there are some explanatory texts on larger screens.

plurals
  1. PObehavior for @PostConstruct exception handling in WebSphere
    primarykey
    data
    text
    <p>Short: (Portlet-)Container swallows Exception thrown by @PostConstruct method in backing bean.</p> <p>Is this behavior intentional, a bug or container specific?</p> <p>Long: I am running a portlet on WebSphere Portal 7, where i force managed bean construction in a PhaseListener so it can send the user back to the start page, when the system encounters unrecoverable problems during Bean construction/post-construction.</p> <p>I am using the following code to 'force' construction:</p> <pre><code>@SuppressWarnings("unchecked") public static &lt;T&gt; T getManagedBean(final String beanName) { final FacesContext context = getFacesContext(); return (T)context.getApplication().evaluateExpressionGet(context, "#{" + beanName + "}", Object.class); } </code></pre> <p>I tested throwing a RuntimeException from the @PostConstruct method</p> <pre><code>@PostConstruct public void initialize() { throw new RuntimeException("test"); } </code></pre> <p>The stacktrace ends up on the RAD(Eclipse) log:</p> <pre><code>com.ibm.ws.webcontainer.annotation.WASAnnotationHelper doInvoke unable to invoke method --&gt; [initialize] on class --&gt; [foo.bar.UpdateAddress] java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37) at java.lang.reflect.Method.invoke(Method.java:611) at com.ibm.ws.webcontainer.annotation.WASAnnotationHelper.doInvokeSingle(WASAnnotationHelper.java:432) at com.ibm.ws.webcontainer.annotation.WASAnnotationHelper.doInvokeChain(WASAnnotationHelper.java:400) at com.ibm.ws.webcontainer.annotation.WASAnnotationHelper.doPostConstruct(WASAnnotationHelper.java:220) at com.sun.faces.vendor.WebSphereInjectionProvider.invokePostConstruct(WebSphereInjectionProvider.java:86) at com.sun.faces.mgbean.BeanBuilder.invokePostConstruct(BeanBuilder.java:225) ... Caused by: java.lang.RuntimeException: test at foo.bar.UpdateAddress.initialize(UpdateAddress.java:119) ... 121 more </code></pre> <p>But there is no exception to catch in my PhaseListener and it happily continues without being aware of an Exception during the @PostConstruct.</p> <p>Is this behavior intentional, a bug or container specific?</p> <p>It looks like at least JBoss has a similar way of handling : <a href="http://www.coderanch.com/t/499013/JSF/java/PostConstruct-exception-handling" rel="nofollow">http://www.coderanch.com/t/499013/JSF/java/PostConstruct-exception-handling</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload