Exception in @PostConstruct not sent to the WebContainer
anton_duca Jul 11, 2008 8:33 AMHi
The problem is simple: if a RuntimeException is thrown on a @PostConstruct method of a JSF managed bean the exception is not sent to the Web tier.
This behaviour does not give the option to handle a 500 error at the web tier level.
The problem is also in JBoss 4.2.2 and I thought 5.0.0 (J2EE 1.5) will solve it.
Glassfish deals better with this situation and gives you the option to handle a 500 HTTP error .
The JSF managed bean:
public class MyBean { String value; @PostConstruct public void load() { throw new RuntimeException(); } public String navigate() { return null; } public String getValue() { return value; } public void setValue(String value) { this.value = value; } }
The stack trace in JBoss console is:
14:08:33,720 ERROR [JBossInjectionProvider] PostConstruct failed on managed bean . java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl. java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces sorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.jboss.web.jsf.integration.injection.JBossInjectionProvider.invoke PostConstruct(JBossInjectionProvider.java:148) at com.sun.faces.mgbean.BeanBuilder.invokePostConstruct(BeanBuilder.java :223) at com.sun.faces.mgbean.BeanBuilder.build(BeanBuilder.java:108) at com.sun.faces.mgbean.BeanManager.createAndPush(BeanManager.java:368) at com.sun.faces.mgbean.BeanManager.create(BeanManager.java:230) at com.sun.faces.el.ManagedBeanELResolver.getValue(ManagedBeanELResolver .java:88) at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:53) at com.sun.faces.el.FacesCompositeELResolver.getValue(FacesCompositeELRe solver.java:72) at org.apache.el.parser.AstIdentifier.getValue(AstIdentifier.java:45) at org.apache.el.parser.AstValue.getTarget(AstValue.java:43) at org.apache.el.parser.AstValue.invoke(AstValue.java:132) at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:2 76) at org.apache.jasper.el.JspMethodExpression.invoke(JspMethodExpression.j ava:68) at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(Met hodBindingMethodExpressionAdapter.java:88) at com.sun.faces.application.ActionListenerImpl.processAction(ActionList enerImpl.java:102) at javax.faces.component.UICommand.broadcast(UICommand.java:387) at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:458) at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:7 63) at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicat ionPhase.java:82) at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100) at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118) at javax.faces.webapp.FacesServlet.service(FacesServlet.java:265) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl icationFilterChain.java:290) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF ilterChain.java:206) at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFi lter.java:96) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl icationFilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF ilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV alve.java:235) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV alve.java:183) at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(Securit yAssociationValve.java:189) at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValv e.java:90) at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invok e(SecurityContextEstablishmentValve.java:96) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j ava:127) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j ava:102) at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedC onnectionValve.java:157) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal ve.java:109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.jav a:325) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java :828) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.proce ss(Http11Protocol.java:601) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:44 7) at java.lang.Thread.run(Thread.java:619) Caused by: java.lang.RuntimeException at mypackage.MyBean.load(MyBean.java:19) ... 45 more