file [UPDATE, FIXED]UnsupportedOpertationException

3 years 10 months ago - 3 years 10 months ago #4183 by deankramer99
Dear forum,
I have a module which was originally developed for 3.3. I have since migrated to 3.5 with the relevant changes to get it to compile and import, however there are now broken parts of my module.

For a start (and for this discussion) is my associations. In my models I have 3 different type of elements (ContextSource, ContextRule, and ContextState). All three extend Class type in terms of a model. The diagram extends StaticDiagram.

When we want to association (draw a line) between the different elements, I use a UMLAssociation, which is created in a DefaultLinkTool class (attached to the palette). This should link the different elements together. While everything seemed to be working before, I now seem to be finding the following exception being thrown:
ERROR o.m.api.impl     - 'Every: 
For: '{d3bd900a-20ce-4962-aa11-95a3a10744c7} Association: Can only add newly added objects.
java.lang.UnsupportedOperationException: 'Every: 
For: '{d3bd900a-20ce-4962-aa11-95a3a10744c7} Association: Can only add newly added objects.
	at org.modelio.vcore.session.impl.CoreSession$ScratchRepository.attach(CoreSession.java:804)


Without putting the whole code (which has a few things that I do not think are relevant or helpful in people being able to understand my code),

I firstly get the source and destination elements with:
Classifier c_source = (Classifier) source.getElement();
Classifier c_destination = (Classifier) destination.getElement();

I then create the association and give it a stereotype and name the different parts:
Association association = model.createAssociation();

String name = "";
String endMulMin = "";

if (assocType == 1) {
    association.addStereotype(Utils.CONTEXT_MODELLER,
				Utils.CONTEXT_SR_ASSOCIATION);
    name = "Every: \nFor: ";
}

and next I setup the Association ends:
association.setName(name);
AssociationEnd endSource = model.createAssociationEnd();
endSource.setMultiplicityMin("");
endSource.setMultiplicityMax("");
endSource.setSource(c_source);
endSource.setTarget(c_destination);

AssociationEnd endTarget = model.createAssociationEnd();
endTarget.setMultiplicityMin(endMulMin);
endTarget.setMultiplicityMax("");

Now I find that when I try to add both AssociationEnds, the exception throws (specifically it seems to throw when "endTarget" is added):
association.getEnd().add(endSource);
association.getEnd().add(endTarget);

Can someone help?
*******************************************************

Sorry, have found the cause the issue. Seems the issue was that the source and destination of the second AssociationEnd had not been set.
I am still interested to know why this worked in Modelio 3.3, as the code is the same.

Please Log in or Create an account to join the conversation.

3 years 10 months ago #4191 by pan
Hi deankramer99,

Maybe it was an issue on Modelio 3.3 to have the possibility to do it because it could lead to an inconsistent model.

BR

Please Log in or Create an account to join the conversation.

Moderators: tmachmaab
Time to create page: 0.031 seconds
^ Back to Top