users@ejb-spec.java.net

[ejb-spec users] Re: [jsr345-experts] Final methods in a bean class?

From: Marina Vatkina <marina.vatkina_at_oracle.com>
Date: Wed, 27 Mar 2013 14:15:46 -0700

On 3/27/13 2:04 PM, Mark Struberg wrote:
>> Right. If they are final, they can't be overridden, so they shouldn't be
>> part of the no-interface view...
> But the developer still can invoke the final method user.setName() and there will be no whatever warning that he will blow up the whole system.
>
>
>
> Just to make sure: what you really get when injecting the User into your own code is a
>
> public class User$$EjbProxy extends User {
> private User getPooledDelegate() { ...ejbmagic()...};
>
> }

No, the proxy will skip setName(), so the caller doing u.setName("foo");
will go directly to the bean instance (like if they do u.wait() - not
that they should ever do it...).

> Thus the setName will just set the name field of User$$EjbProxy and not the delegated pooled instance -> boom

vice versa, but if setName needs transaction or resources, they won't be
started or enlisted...
>
> At least if I understood the NIV correctly - it's just like a @Local but without the need to implement an interface (but you use the pojo instead)...

yes. the question is what does constitute that @Local pseudo-interface...

thanks,
-marina

>
>
> LIeGrue,
> strub
>
>
>
> ----- Original Message -----
>> From: Marina Vatkina <marina.vatkina_at_oracle.com>
>> To: Mark Struberg <struberg_at_yahoo.de>
>> Cc: ejb-users <users_at_ejb-spec.java.net>
>> Sent: Wednesday, March 27, 2013 9:35 PM
>> Subject: Re: [ejb-spec users] Re: [jsr345-experts] Final methods in a bean class?
>>
>> On 3/27/13 1:15 PM, Mark Struberg wrote:
>>> removing (b) completely will create proxying issues, isn't?
>>>
>>>
>>> It's just not possible to override a public final method in the
>> subclass used for the proxies.
>>
>> Right. If they are final, they can't be overridden, so they shouldn't be
>>
>> part of the no-interface view...
>>> Thus those methods will create broken proxies.
>>>
>>> consider the bean
>>> public @Stateless class User {
>>> private String name;
>>>
>>> public String getName() { return name; };
>>> public final setName(String name) {this.name = name;}
>>> }
>>>
>>> and
>>>
>>> @EJB User u;
>>>
>>> calling u.setName("Hans"); would just set the 'name'
>> field of the proxy and not the name of the pooled instance!
>>
>> If a proxy is a subclass, it'd be a direct call, not through the proxy.
>>>
>>>
>>> The rule is a bit too strict though. It should only prohibit final methods
>> until they are static or private. Final private and static methods are perfectly
>> fine as theycannot get proxied anyway...
>>
>> That's true.
>>
>> Best,
>> -marina
>>
>>>
>>> LieGrue,
>>> strub
>>>
>>> PS: thanks for all the hard work on the EJB spec ;)
>>>
>>>
>>>
>>> ----- Original Message -----
>>>> From: Marina Vatkina <marina.vatkina_at_oracle.com>
>>>> To: jsr345-experts_at_ejb-spec.java.net
>>>> Cc:
>>>> Sent: Wednesday, March 27, 2013 7:36 PM
>>>> Subject: [ejb-spec users] [jsr345-experts] Final methods in a bean
>> class?
>>>> Experts,
>>>>
>>>> The EJB spec currently requires that if a bean exposes a no-interface
>> view (see
>>>> 4.9.8 Session Bean’s No-Interface View):
>>>>
>>>> (a) "All public methods of the bean class and of any superclasses
>> except
>>>> the java.lang.Object, are exposed as business methods through the
>> no-interface
>>>> view."
>>>> (b) "All methods of the bean class and any superclasses must not
>> be
>>>> declared final."
>>>>
>>>> For all other views the rules for a *business method* is
>>>> "The method must not be declared as final or static."
>>>>
>>>> Does any of you see a problem with removing the rule (b) and changing
>> the rule
>>>> (a) to:
>>>>
>>>> "All non-final non-static public methods of the bean class and of
>> any
>>>> superclasses except the java.lang.Object, are exposed as business
>> methods
>>>> through the no-interface view."
>>>>
>>>> thanks,
>>>> -marina
>>>>