Dan,

>Specifically, the EJB Container is not allowed to pass
>non-remote objects
>by reference on inter-EJB invocations when the calling and called
>enterprise beans are collocated in the same JVM. Doing so
>could result in
>the multiple beans sharing the state of a Java object, which
>would break
>the enterprise beans semantics.

Thank for the spec outline Dan.

But, most of the AS do not duplicate the objects passed by reference by
the middleware during a local call, which break the EJB semantic.

That's mean that when you develop an EJB, you must be aware about
problem, and keep in mind that pass-by-value objects may be in fact passed
by references in the case of a local call.

So the following code is dangerous:
        public void doSomeStuff(List list) {
                list.add("hello");
                // do some stuff with "list"
        }
This code should be fixed as:
        public void doSomeStuff(List list) {
                List local = new ArrayList();
                Collections.copy(list, local);
                local.add("hello");
                // do some stuff with "local"   }

This example applied as well to by-values returned objects:
        private List accounts;

        public List getAccounts() {
                return accounts;
        }
        This client may change the account list if the case of a local call
(passed by reference), which break the encapsulation.

This method should be fixed as:
        private List accounts;

        public List getAccounts() {
                List copy = new ArrayList();
                Collections.copy(accounts, copy);
                return copy;
        }
Or (better solution)
        private List accounts;

        public List getAccounts() {
                return Collection.unmodifiableList(accounts);
        }

Tibo.

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to