Page 1 of 1
About Question enthuware.oce-ejbd.v6.2.395 :
Posted: Tue Dec 27, 2016 11:08 pm
by Gerardo
Hi,
I have the following doubt:
¿Can the result be "1000"? if the @AroundInvoke code were:
@AroundInvoke
public Object iaM1(InvocationContext ic) throws Exception {
return "1000";
}
Thanks in advance
Re: About Question enthuware.oce-ejbd.v6.2.395 :
Posted: Wed Dec 28, 2016 1:17 am
by Gerardo
According to "enthuware.oce-ejbd.v6.2.519" now I understand that the result of my example code will be correctly "1000".
Re: About Question enthuware.oce-ejbd.v6.2.395 :
Posted: Wed Feb 22, 2017 4:48 am
by selvehed
I compare this question with question no. 13 in Test 1. In both questions the actual bean method returns a String. Neither of the interceptors in the questions return Object or call ic.proceed. So the explanation is somewhat confusing: "Further, the return value of the interceptor method must be Object otherwise a ClassCastException will be thrown at Runtime". It rather seems that the return type could be the same as in the bean method without ClassCastException. Could you clarify whats going on for me? Can the explanation be a Little more clear? Maybe the explanation in question 13 test 1 should be the exact same as in this question too?
Re: About Question enthuware.oce-ejbd.v6.2.395 :
Posted: Wed Feb 22, 2017 5:24 am
by admin
The return type as declared in the declaration of interceptor method must be Object. This is required by the specification.
The actual type of the object returned by the interceptor must be compatible with the return type of the bean's method.
In case of 2.395, the return type of the bean method is String, but the interceptor is returning an Integer object. Thus, when the container tries to cast an Integer object to String, a CCE will be thrown. In case of 2.394, the value returned by the interceptor method is String, which is same as that of the type of the return value of the bean's method, so there is no problem.
HTH,
Paul.
Re: About Question enthuware.oce-ejbd.v6.2.395 :
Posted: Wed Feb 22, 2017 6:31 am
by selvehed
I understand. But maybe the explanation in enthuware.oce-ejbd.v6.2.394 (wich I got in test 1 question 13) should explain a Little about it's being OK to return String in the interceptor as it's compatible with the business method return value? I had no problem with enthuware.oce-ejbd.v6.2.394 and thought I knew Everything about that question, but then I took test 2 and got enthuware.oce-ejbd.v6.2.395 and answered wrong =/
Re: About Question enthuware.oce-ejbd.v6.2.395 :
Posted: Wed Feb 22, 2017 6:32 am
by selvehed
I Think a more general explanation that is exactly the same for enthuware.oce-ejbd.v6.2.394 and enthuware.oce-ejbd.v6.2.395 could help us Learning this concept =)
Re: About Question enthuware.oce-ejbd.v6.2.395 :
Posted: Wed Feb 22, 2017 6:57 am
by admin
Good point. Will update.
thank you for your feedback!
Paul.
Re: About Question enthuware.oce-ejbd.v6.2.395 :
Posted: Wed Feb 22, 2017 7:46 am
by selvehed
Now I see that question enthuware.oce-ejbd.v6.2.519 is quite similar. Here the business method return type is "double" but the Interceptor returns "Double" (without Calling proceed). The explanation for 2.394 and 2.395 should cover this example to. How come that the "Integer instead of String" return generates ClassCastException at runtime when the "Double instead of double" does not? I Think I've forgotten some basic Java type conversion here! Anyway keeping a red line in the explanation by giving enthuware.oce-ejbd.v6.2.519 the same explanation as 2.394 and 2.395 might be a good idea!
Re: About Question enthuware.oce-ejbd.v6.2.395 :
Posted: Wed Feb 22, 2017 11:28 am
by admin
Double instead of double (and vice-versa) is ok because of auto-unboxing/boxing.
Will update 2.519 as well.
Paul.