Page 1 of 1

About Question enthuware.oce-ejbd.v6.2.551 : Subclasses of exceptions in throws clause of @AroundInvoke method

Posted: Tue Oct 15, 2013 3:11 am
by dstmailinator
Description of one of the wrong answers is:
The signature of @AroundInvoke method must have "throws Exception" part. This is required.
However in question enthuware.oce-ejbd.v6.2.519 there's such a code snippet:

Code: Select all

@AroundInvoke
public Object myAround(InvocationContext ic) throws NoAccountException
EJB 3.1 specification says:
Business method interceptor methods may throw runtime exceptions or application exceptions that are allowed in the throws clause of the business method.
However Java EE 6 API gives the following signature for an interceptor method:

Code: Select all

@AroundInvoke
public Object intercept(InvocationContext ctx) throws Exception { ... }
I tested on Weblogic, that subclasses of Exception in throws clause of an interceptor method are not valid. There's an error during deployment.
weblogic.ejb.container.compliance.ComplianceException: AroundInvoke method myInterceptor in class oce.ejbd.MySLSInterceptor must have the signature: 'Object <METHOD(InvocationContext)> throws Exception'
That's why I think that either Java EE 6 API is inaccurate (should allow Exception subclasses) or you shouldn't use signature with "throws NoAccountException" and say that "throws Exception" is required in another place, if it's not clear what is really compatible with specification.

Re: About Question enthuware.oce-ejbd.v6.2.551 : Subclasses of exceptions in throws clause of @AroundInvoke method

Posted: Thu Oct 17, 2013 7:08 am
by admin
Very sorry for late reply. Required some research.

As you've quoted from EJB 3.1 specification and also given in Interceptor specification, it specifies the signature of AroundInvoke method as having "throws Exception". This makes sense because the interceptor method is permitted to throw any exception that is declared in the business method. So that is possible only if the interceptor method signature has "throws Exception".

The other question needs to be corrected.

HTH,
Paul.

-Paul.

Re: About Question enthuware.oce-ejbd.v6.2.551 : Subclasses

Posted: Sun Jun 14, 2015 6:54 pm
by himaiMinh
The getBalance returns a double while myAround returns an Object.
It should have a ClassCastException during runtime.

Re: About Question enthuware.oce-ejbd.v6.2.551 : Subclasses

Posted: Sun Jun 14, 2015 8:41 pm
by admin
No, it is ok as per Interceptor specification, Page 5: Around-invoke methods have the following signature: Object <METHOD>(InvocationContext) throws Exception

Re: About Question enthuware.oce-ejbd.v6.2.551 : Subclasses

Posted: Sun Jun 14, 2015 8:56 pm
by himaiMinh
Thanks.
But in one of the questions,

Code: Select all


@AroundInvoke
 Object myAround(InvocationContext context) throws Exception{
      return new Integer(100);
 }

 public String getCode(String input){

   return "CountryCode "+ input;
 }
The explanation says it will have ClassCastException during runtime.

But in this case:

Code: Select all

@AroundInvoke
 Object myAround(InvocationContext context) throws Exception{
      return context.proceed();
 }

public double getBalance(){

   return 2.0;
 }
These return type are different, one is object, another is a double, but it works.

Re: About Question enthuware.oce-ejbd.v6.2.551 : Subclasses

Posted: Sun Jun 14, 2015 8:58 pm
by admin
Yes, I updated that also.
As you may have noticed, sometimes the container do not follow the specification exactly.