Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Bean discarded after interceptor unwinded

 
Himai Minh
Ranch Hand
Posts: 1361
7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On p. 337 of JSR 318,
A runtime exception thrown by any lifecycle interceptor callback method causes the bean instance and its interceptors to discarded after the interceptor chain unwinded.


But based on my experiment, when a @PostConstruct interceptor method throws a runtime exception, the bean is discarded, but I don't think the interceptor chain is unwinded.





Info: Post construct method in MyInterceptor starts...
Info: My bean initialized ...

Severe: EJB5070: Exception creating stateless session bean : [MyBean]
Warning: A system exception occurred during an invocation on EJB MyBean method public void com.ivan.scbcd6.MyBean.myBusiness()
javax.ejb.EJBException: javax.ejb.EJBException: javax.ejb.CreateException: Could not create stateless EJB
....
Caused by: javax.ejb.EJBException: javax.ejb.CreateException: Could not create stateless EJB

Caused by: javax.ejb.CreateException: Could not create stateless EJB

Caused by: java.lang.RuntimeException ....

Caused by: javax.ejb.EJBException: javax.ejb.CreateException: Could not create stateless EJB ...
Caused by: javax.ejb.CreateException: Could not create stateless EJB
...
Caused by: java.lang.RuntimeException
at com.ivan.scbcd6.MyBean.myBad(MyBean.java:20)
at com.ivan.scbcd6.MyBean.initializeBean(MyBean.java:14)
...
 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Pie
Posts: 2534
113
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think that is a matter of definition. Unwind in this case probably means: the chain is opened up (or broken).

Or in other words: the chain is broken by a RuntimeException and it won't proceed to the next Interceptor in the chain.
 
Himai Minh
Ranch Hand
Posts: 1361
7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Frits. Thanks for your clarification.
In Enthuware and the specification, they point out that the interceptor should do necessary clean up when the interceptor chain is unwinded.
But if the interceptor chain is broken and cannot proceed, any necessary cleanup cannot be performed due to the Runtime exception thrown in the middle of the chain.
 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Pie
Posts: 2534
113
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, you are right. This is the exact text in the specification:
12.5.1 Exceptions
A runtime exception thrown by any lifecycle interceptor callback method causes the bean instance and its interceptors to be discarded after the interceptor chain unwinds.
The PreDestroy callbacks are not invoked when the bean and the interceptors are discarded as a result of such exceptions: the lifecycle callback interceptor methods in the chain should perform any necessary clean-up operations as the interceptor chain unwinds.


I think you should put a try-catch inside the interceptor:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic