Discussion:
[argouml-dev] issue with Model.getFacade().getParameters()
(too old to reply)
Thomas N.
2005-08-30 14:10:04 UTC
Permalink
Hi,

some of the failing tests (especially the RE failures) have to do with the
Model.getFacade().getParameters() method. The problem is, when getting the
iterator with

Model.getFacade().getParameters(obj).iterator(),

and then manipulating it, e.g. by removing with

Model.getCoreHelper().removeParameter(obj, i.next()),

then the iterator is not reliable any more. The NSUML version hehaves as if
the the Collection obtained with getParameters() is decoupled from the
iterator. This is different in MDR, maybe because they overwrote the
.iterator() method (yes they did).

So, there are 2 possible solutions, both mean operating on a copy of the
collection for safe iteration:

1. Modify the Model.getFacade().getParameters() method, so that it creates a
new collection and copies all content into it, thus having the original
iterator() method that seems to work.
2. Modify all locations where Model.getFacade().getParameters(obj) is used,
to operate on a copied collection only.

What do you think? I'm in favour of the first solution, but it has the
disadvantage that it allows the current lighthearted use of iterators
("iterate and remove in one loop").

Thomas
--
GMX DSL = Maximale Leistung zum minimalen Preis!
2000 MB nur 2,99, Flatrate ab 4,99 Euro/Monat: http://www.gmx.net/de/go/dsl
Thomas N.
2005-08-30 14:47:06 UTC
Permalink
I tested the first solution, by changing FacadeMDRImpl.getParameters() into

/**
* @see org.argouml.model.Facade#getParameters(java.lang.Object)
*/
public Collection getParameters(Object handle) {
Collection c = null;
if (handle instanceof ObjectFlowState) {
c = ((ObjectFlowState) handle).getParameter();
} else if (handle instanceof BehavioralFeature) {
c = ((BehavioralFeature) handle).getParameter();
} else if (handle instanceof Event) {
c = ((Event) handle).getParameter();
} else if (handle instanceof Classifier) {
c = implementation.getUmlPackage().getCore().
getATypedParameterType().getTypedParameter(
(Classifier) handle);
} else {
return illegalArgumentCollection(handle);
}
ArrayList result = null;
if (c != null) {
result = new ArrayList(c);
}
return result;
}

And it works! I can't commit until weekend, maybe someone else?
Maybe all other methods that return a collection should be examined, if the
collection is some MDR specific Collection implementation, and then changed
in a similar way.

Thomas
--- Ursprüngliche Nachricht ---
Betreff: [argouml-dev] issue with Model.getFacade().getParameters()
Datum: Tue, 30 Aug 2005 16:10:04 +0200 (MEST)
Hi,
some of the failing tests (especially the RE failures) have to do with the
Model.getFacade().getParameters() method. The problem is, when getting the
iterator with
Model.getFacade().getParameters(obj).iterator(),
and then manipulating it, e.g. by removing with
Model.getCoreHelper().removeParameter(obj, i.next()),
then the iterator is not reliable any more. The NSUML version hehaves as if
the the Collection obtained with getParameters() is decoupled from the
iterator. This is different in MDR, maybe because they overwrote the
.iterator() method (yes they did).
So, there are 2 possible solutions, both mean operating on a copy of the
1. Modify the Model.getFacade().getParameters() method, so that it creates a
new collection and copies all content into it, thus having the original
iterator() method that seems to work.
2. Modify all locations where Model.getFacade().getParameters(obj) is used,
to operate on a copied collection only.
What do you think? I'm in favour of the first solution, but it has the
disadvantage that it allows the current lighthearted use of iterators
("iterate and remove in one loop").
Thomas
--
GMX DSL = Maximale Leistung zum minimalen Preis!
http://www.gmx.net/de/go/dsl
---------------------------------------------------------------------
--
5 GB Mailbox, 50 FreeSMS http://www.gmx.net/de/go/promail
+++ GMX - die erste Adresse für Mail, Message, More +++
Bob Tarling
2005-08-30 14:48:30 UTC
Permalink
Solution 1 sounds good to me.
Post by Thomas N.
Hi,
some of the failing tests (especially the RE failures) have to do with the
Model.getFacade().getParameters() method. The problem is, when getting the
iterator with
Model.getFacade().getParameters(obj).iterator(),
and then manipulating it, e.g. by removing with
Model.getCoreHelper().removeParameter(obj, i.next()),
then the iterator is not reliable any more. The NSUML version hehaves as if
the the Collection obtained with getParameters() is decoupled from the
iterator. This is different in MDR, maybe because they overwrote the
.iterator() method (yes they did).
So, there are 2 possible solutions, both mean operating on a copy of the
1. Modify the Model.getFacade().getParameters() method, so that it creates a
new collection and copies all content into it, thus having the original
iterator() method that seems to work.
2. Modify all locations where Model.getFacade().getParameters(obj) is used,
to operate on a copied collection only.
What do you think? I'm in favour of the first solution, but it has the
disadvantage that it allows the current lighthearted use of iterators
("iterate and remove in one loop").
Thomas
--
GMX DSL = Maximale Leistung zum minimalen Preis!
2000 MB nur 2,99, Flatrate ab 4,99 Euro/Monat: http://www.gmx.net/de/go/dsl
---------------------------------------------------------------------
Tom Morris
2005-08-30 16:33:07 UTC
Permalink
Hi Thomas,

Thanks for helping check out MDR with RE. What revision of
FacadeMDRImpl.java do you have? The getParameters method was fixed in 1.76
and similar changes made to getMessages3 and getPredecessors in 1.77.

I chose solution #1 more because I'm restricted to working in the MDR
subproject than because I necessarily think it's the best solution. The
drawback is that all users of any method that returns a collection must pay
the performance penalty for creating a copy of the collection even if they
are using the collection in a read-only fashion. The advantage is that it
concentrates the changes in a single place.

MDR uses live collection semantics and since this is specified by the JMI
spec (see 4.2.3 JMI Collection Semantics), I suspect other JMI-based
repositories will do the same, so it might be a good idea for us to learn to
deal with it.

Actually, another thought just occurred to me. It may be possible to fix
this problem on the remove end of things. Let me look into this more...

Tom
-----Original Message-----
Sent: Tuesday, August 30, 2005 10:10 AM
Subject: [argouml-dev] issue with Model.getFacade().getParameters()
Hi,
some of the failing tests (especially the RE failures) have
to do with the
Model.getFacade().getParameters() method. The problem is,
when getting the iterator with
Model.getFacade().getParameters(obj).iterator(),
and then manipulating it, e.g. by removing with
Model.getCoreHelper().removeParameter(obj, i.next()),
then the iterator is not reliable any more. The NSUML version
hehaves as if the the Collection obtained with
getParameters() is decoupled from the iterator. This is
different in MDR, maybe because they overwrote the
.iterator() method (yes they did).
So, there are 2 possible solutions, both mean operating on a
1. Modify the Model.getFacade().getParameters() method, so
that it creates a new collection and copies all content into
it, thus having the original
iterator() method that seems to work.
2. Modify all locations where
Model.getFacade().getParameters(obj) is used, to operate on a
copied collection only.
What do you think? I'm in favour of the first solution, but
it has the disadvantage that it allows the current
lighthearted use of iterators ("iterate and remove in one loop").
Thomas
--
GMX DSL = Maximale Leistung zum minimalen Preis!
http://www.gmx.net/de/go/dsl
---------------------------------------------------------------------
Thomas N.
2005-08-30 16:54:47 UTC
Permalink
Linus Tolke
2005-08-30 22:40:48 UTC
Permalink
As long as solution 1 is used, it should return, not only a copy of the
collection so that nothing changes it, but an UnmodifyableCollection to
emphasize that this is something that the client does not control.

/Linus
-----Original Message-----
Sent: den 30 augusti 2005 16:10
Subject: [argouml-dev] issue with Model.getFacade().getParameters()
Hi,
some of the failing tests (especially the RE failures) have to do with the
Model.getFacade().getParameters() method. The problem is, when getting the
iterator with
Model.getFacade().getParameters(obj).iterator(),
and then manipulating it, e.g. by removing with
Model.getCoreHelper().removeParameter(obj, i.next()),
then the iterator is not reliable any more. The NSUML version
hehaves as if
the the Collection obtained with getParameters() is decoupled from the
iterator. This is different in MDR, maybe because they overwrote the
.iterator() method (yes they did).
So, there are 2 possible solutions, both mean operating on a copy of the
1. Modify the Model.getFacade().getParameters() method, so that it creates a
new collection and copies all content into it, thus having the original
iterator() method that seems to work.
2. Modify all locations where
Model.getFacade().getParameters(obj) is used,
to operate on a copied collection only.
What do you think? I'm in favour of the first solution, but it has the
disadvantage that it allows the current lighthearted use of iterators
("iterate and remove in one loop").
Thomas
--
GMX DSL = Maximale Leistung zum minimalen Preis!
http://www.gmx.net/de/go/dsl
---------------------------------------------------------------------
Tom Morris
2005-08-31 07:46:47 UTC
Permalink
I've changed the implementation to return an unmodifiable ArrayList to
satisfy both Thomas and Linus.

I'm not really sure what 'unmodifiable' adds since the live collection and
its static copy are completely decoupled. The static copy can't be modified
now, but it doesn't make it any truer a representation of reality. If the
live collection is modified, the static copy will no longer represent the
new reality even though it wasn't modified.

Tom
-----Original Message-----
Sent: Tuesday, August 30, 2005 6:41 PM
Subject: RE: [argouml-dev] issue with
Model.getFacade().getParameters()
As long as solution 1 is used, it should return, not only a
copy of the collection so that nothing changes it, but an
UnmodifyableCollection to emphasize that this is something
that the client does not control.
/Linus
-----Original Message-----
Sent: den 30 augusti 2005 16:10
Subject: [argouml-dev] issue with Model.getFacade().getParameters()
Hi,
some of the failing tests (especially the RE failures) have
to do with
the
Model.getFacade().getParameters() method. The problem is,
when getting the
iterator with
Model.getFacade().getParameters(obj).iterator(),
and then manipulating it, e.g. by removing with
Model.getCoreHelper().removeParameter(obj, i.next()),
then the iterator is not reliable any more. The NSUML
version hehaves
as if the the Collection obtained with getParameters() is decoupled
from the iterator. This is different in MDR, maybe because they
overwrote the
.iterator() method (yes they did).
So, there are 2 possible solutions, both mean operating on
a copy of
1. Modify the Model.getFacade().getParameters() method, so that it
creates a new collection and copies all content into it,
thus having
the original
iterator() method that seems to work.
2. Modify all locations where
Model.getFacade().getParameters(obj) is used,
to operate on a copied collection only.
What do you think? I'm in favour of the first solution, but
it has the
disadvantage that it allows the current lighthearted use of
iterators
("iterate and remove in one loop").
Thomas
--
GMX DSL = Maximale Leistung zum minimalen Preis!
http://www.gmx.net/de/go/dsl
---------------------------------------------------------------------
---------------------------------------------------------------------
Loading...