Details

    • Type: Improvement Improvement
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.2
    • Labels:
      None

      Description

      Currently the rules are interceptor signatures for callbacks are not allowed to return Object or throw Exception. Blogged about it here: http://blog.dblevins.com/2010/09/ejbnext-interceptor-improvements-method.html

      We chose that altered method signature because it effectively matched the method signature of the callback itself, but it has some terrible consequences. The worst is that InvocationContext.proceed() method signature is always the same:

      public Object proceed() throws Exception

      When the Interceptor isn't allowed to have the same method signature it creates awkward and unfortunately unavoidable boiler plate:

         @PostConstruct
         @PreDestroy
         @PrePassivate
         @PostActivate
         @AroundTimeout
         public void callback(InvocationContext context) {
             try {
                 intercept(context);
             } catch (Exception e) {
                 if (e instanceof RuntimeException) {
                     throw (RuntimeException) e;
                 } else{
                     throw new RuntimeException(e);
                 }
             }
         }
      

      Requiring each interceptor to catch and handle the 'throws Exception' from the InvocationContext.proceed() call is unfortunate. The interceptor should be allowed to let any exceptions propagate.

      We should update the spec rules so that interceptor method signatures for callbacks are allowed to be the same and let the container handle the possible undeclared exception issues rather than force that upon the application code in every single callback interceptor they create.

        Activity

        Hide
        marina vatkina added a comment -

        Theoretically speaking @AroundTimeout callback doesn't need 'throws Exception' clause or a return value because the EJB Timeout method is void and can't throw a checked exception.

        I plan to add a note to the Interceptors spec saying that 'throws Exception' in the @AroundTimeout method signature allows to use the same interceptor method to intercept business and timeout methods, but otherwise is not needed.

        Show
        marina vatkina added a comment - Theoretically speaking @AroundTimeout callback doesn't need 'throws Exception' clause or a return value because the EJB Timeout method is void and can't throw a checked exception. I plan to add a note to the Interceptors spec saying that 'throws Exception' in the @AroundTimeout method signature allows to use the same interceptor method to intercept business and timeout methods, but otherwise is not needed.
        Show
        marina vatkina added a comment - In draft3: http://java.net/projects/interceptors-spec/downloads/download/interceptor-1-2-dr3.pdf

          People

          • Assignee:
            marina vatkina
            Reporter:
            dblevins
          • Votes:
            1 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: