Bug 135606

Summary: Umbrello saves too much copies at xmi
Product: [Applications] umbrello Reporter: ediaz666 <ediaz666>
Component: generalAssignee: Umbrello Development Group <umbrello-devel>
Status: RESOLVED FIXED    
Severity: normal    
Priority: NOR    
Version: unspecified   
Target Milestone: ---   
Platform: unspecified   
OS: Linux   
Latest Commit: Version Fixed In:
Sentry Crash Report:
Attachments: Test Project
Patch which resolves problem for my test cases
extracts from testcase
proof of concept patch
test case after Olivers fix

Description ediaz666@gmail.com 2006-10-13 22:50:44 UTC
Version:           1.5.5 (using KDE 3.5.5 "release 19.1" , openSUSE )
Compiler:          Target: x86_64-suse-linux
OS:                Linux (x86_64) release 2.6.16.13-4-default

I was working on a class diagram with 36 classes, i was modifying them because i am in the analice phase. I got surprise when i realize that the xmi file grows until 3.4 MB, so i decide to check the xmi with a plain text editor. What i found was that almost 60% of the information is duplicated!!! i guess the problem is that xmi saves as many changes as you make to your diagram, no matter they are not in the diagram anymore.

Greetings
ediaz
Comment 1 Oliver Kellogg 2006-10-14 10:08:45 UTC
Could you attach your XMI file?
That would be very helpful, thanks.
Comment 2 Achim Spangler 2006-10-24 11:48:26 UTC
Hi,
I have written already some emails - but as I was not able to attach an example file, I deiced to enter a bug report with test file and my findings so far.

I have the impression, that the problem starts somewhere around the code for UMLObject::load(XX) where the following error message is triggered even for a small test project (see attachement):
umbrello: ERROR: UMLObject::load(Logische Ansicht): m_pUMLPackage is not set
umbrello: ERROR: UMLObject::load(Datentypen): m_pUMLPackage is not set
umbrello: ERROR: UMLObject::load(Anwendungsfallansicht): m_pUMLPackage is not 
set
umbrello: ERROR: UMLObject::load(Komponentenansicht): m_pUMLPackage is not set
umbrello: ERROR: UMLObject::load(Verteilungsansicht): m_pUMLPackage is not set
umbrello: ERROR: UMLObject::load(Entity-Relationship-Modell): m_pUMLPackage is 
not set


This seems to confuse the total XMI lookup algorithms, so that references can not be resolved and also duplicates aren't detected. This leads to:
+ bunch of error messages like this on load:
   umbrello: UMLListView::slotObjectCreated(Datentypen, id= 614302): item already 
exists.

+ failing load of Generalizations, as the corresponding widget is not found:
   umbrello: ERROR: AssociationWidget::loadFromXMI: cannot find UMLObject 612293
umbrello: ERROR: couldn't loadFromXMI association widget:0x90a5c30, bad XMI 
file? Deleting from umlview.

The strange thing:
The Generalization is defined for a class as follows:
        <UML:GeneralizableElement.generalization>
                <UML:Generalization xmi.idref="612293" />
        </UML:GeneralizableElement.generalization>

The referenced item exists as follows:
<assocwidget totalcounta="3" indexa="1" totalcountb="7" indexb="1" 
linewidth="none" widgetbid="583487" widgetaid="584616" xmi.id="612293" 
linecolor="none" >
          <linepath>
           <startpoint startx="212" starty="651" />
           <endpoint endx="570" endy="603" />
          </linepath>
         </assocwidget>

+ at least the data type XML-Tags are massively duplicated:
    <UML:Stereotype isSpecification="false" isLeaf="false" visibility="public" 
namespace="m1" xmi.id="2" isRoot="false" isAbstract="f
alse" name="folder" />
    <UML:Stereotype isSpecification="false" isLeaf="false" visibility="public" 
namespace="m1" xmi.id="2" isRoot="false" isAbstract="f
alse" name="folder" />
    <UML:Stereotype isSpecification="false" isLeaf="false" visibility="public" 
namespace="m1" xmi.id="2" isRoot="false" isAbstract="f
alse" name="folder" />
    <UML:Stereotype isSpecification="false" isLeaf="false" visibility="public" 
namespace="m1" xmi.id="2" isRoot="false" isAbstract="f
alse" name="folder" />
    <UML:Stereotype isSpecification="false" isLeaf="false" visibility="public" 
namespace="m1" xmi.id="2" isRoot="false" isAbstract="f
alse" name="folder" />
    <UML:Stereotype isSpecification="false" isLeaf="false" visibility="public" 
namespace="m1" xmi.id="11" isRoot="false" isAbstract="
false" name="datatype" />
    <UML:Stereotype isSpecification="false" isLeaf="false" visibility="public" 
namespace="m1" xmi.id="2" isRoot="false" isAbstract="f
alse" name="folder" />
    <UML:Stereotype isSpecification="false" isLeaf="false" visibility="public" 
namespace="m1" xmi.id="2" isRoot="false" isAbstract="f
alse" name="folder" />
    <UML:Stereotype isSpecification="false" isLeaf="false" visibility="public" 
namespace="m1" xmi.id="2" isRoot="false" isAbstract="f
alse" name="folder" />
    <UML:Stereotype isSpecification="false" isLeaf="false" visibility="public" 
namespace="m1" xmi.id="2" isRoot="false" isAbstract="f
alse" name="folder" />
    <UML:Stereotype isSpecification="false" isLeaf="false" visibility="public" 
namespace="m1" xmi.id="2" isRoot="false" isAbstract="f
alse" name="folder" />
    <UML:Stereotype isSpecification="false" isLeaf="false" visibility="public" 
namespace="m1" xmi.id="2" isRoot="false" isAbstract="f
alse" name="folder" />
    <UML:Stereotype isSpecification="false" isLeaf="false" visibility="public" 
namespace="m1" xmi.id="2" isRoot="false" isAbstract="f
alse" name="folder" />
    <UML:Stereotype isSpecification="false" isLeaf="false" visibility="public" 
namespace="m1" xmi.id="2" isRoot="false" isAbstract="f
alse" name="folder" />
    <UML:Stereotype isSpecification="false" isLeaf="false" visibility="public" 
namespace="m1" xmi.id="2" isRoot="false" isAbstract="f
alse" name="folder" />


This seems to be also the reason for an endless loop in the SVN version of 24.10.2006, where lots of error messages as follows are produced:
umbrello: ERROR: UMLListView::loadChildrenFromXMI: umlParent((nil)) is not a 
UMLPackage


This error is very easy to reproduce:
Just create a new project and add:
+ two classes where one class derives from the other
+ add an enum and create an attribute with this type as class member
+ add an attribute to a class with a free datatype like "int32_t"

Save&Load, Save&Load this sometimes - and you will get those strange results.
I'll attach nevertheless a test file.

Thanks,
Achim
Comment 3 Achim Spangler 2006-10-24 11:49:30 UTC
Created attachment 18244 [details]
Test Project
Comment 4 Achim Spangler 2006-10-24 15:02:03 UTC
Hi,
I might have found the reason.

Somebody in the past commented the following block out:
if (type == Uml::lvt_Datatype) {
        parentItem = m_datatypeFolder;
    }

Well - this shouldn't have been done....

This block is VERY IMPORTANT for a correct resolve of data types, generalizations, ........ .

The attached patch solves:
+ endless loop in error case with parent package pointer being NULL
+ activate back the cited code

I was able to create a small test project without any redundant datatype lines.
The class hierarchy (generalization) is reloaded correctly again.
And the diagrams are also reloaded.

Bye,
Achim
Comment 5 Achim Spangler 2006-10-24 15:05:33 UTC
Created attachment 18247 [details]
Patch which resolves problem for my test cases

+ activate back the special check for datatype folder in
UMLListView::addNewItem(UMLListViewItem *parentItem, Uml::ListView_Type type)

+ avoid endless loop in UMLListView::loadChildrenFromXMI( UMLListViewItem *
parent, QDomElement & element )
Comment 6 Achim Spangler 2006-10-24 16:08:46 UTC
Hi again,
well - I was too early happy. The change avoids several ERROR messages during XMI loading.

BUT the massive redundant save of <UML:Stereotype ....> tags is STILL active.
I hope, that someone else finds this last item.

Bye,
Achim
Comment 7 Oliver Kellogg 2006-10-24 19:06:56 UTC
SVN commit 598796 by okellogg:

Attachment 18247 [details] from Achim Spangler restores a check for datatype folder in
 addNewItem() and avoids an endless loop in loadChildrenFromXMI(). Thanks!
CCBUG:135606


 M  +4 -3      umllistview.cpp  


--- branches/KDE/3.5/kdesdk/umbrello/umbrello/umllistview.cpp #598795:598796
@@ -1805,9 +1805,9 @@
     QString name;
 
     //// CHECK: Why?
-    // if (type == Uml::lvt_Datatype) {
-    //     parentItem = m_datatypeFolder;
-    // }
+     if (type == Uml::lvt_Datatype) {
+         parentItem = m_datatypeFolder;
+     }
 
     UMLPackage *parentPkg = dynamic_cast<UMLPackage*>(parentItem->getUMLObject());
     if (parentPkg == NULL)
@@ -2346,6 +2346,7 @@
                 if (parentPkg == NULL) {
                     kdError() << pfx << "umlParent(" << umlParent << ") is not a UMLPackage"
                         << endl;
+                    domElement = node.toElement();
                     continue;
                 }
                 UMLFolder *f = new UMLFolder(label, nID);
Comment 8 Oliver Kellogg 2006-10-24 21:41:09 UTC
SVN commit 598837 by okellogg:

loadUMLObjectsFromXMI(): Don't addStereotype() if it's already there.
CCBUG:135606


 M  +4 -1      umldoc.cpp  


--- branches/KDE/3.5/kdesdk/umbrello/umbrello/umldoc.cpp #598836:598837
@@ -1805,7 +1805,10 @@
         }
         if (ot == ot_Stereotype) {
             UMLStereotype *s = static_cast<UMLStereotype*>(pObject);
-            addStereotype(s);
+            if (findStereotype(s->getName()) != NULL)
+                delete s;
+            else
+                addStereotype(s);
             continue;
         }
         pkg->addObject(pObject);
Comment 9 Oliver Kellogg 2006-11-03 11:08:30 UTC
SVN commit 601431 by okellogg:

CCBUG:135606 - Print a debug message and backtrace on constructing a duplicate stereotype.

 M  +5 -0      stereotype.cpp  


--- branches/KDE/3.5/kdesdk/umbrello/umbrello/stereotype.cpp #601430:601431
@@ -21,6 +21,11 @@
 UMLStereotype::UMLStereotype(const QString &name, Uml::IDType id /* = Uml::id_None */)
         : UMLObject( name, id ) {
     m_BaseType = Uml::ot_Stereotype;
+    UMLStereotype * existing = UMLApp::app()->getDocument()->findStereotype(name);
+    if (existing) {
+        kdError() << "UMLStereotype constructor: " << name << " already exists" << endl;
+        kdBacktrace(25);
+    }
     m_refCount = 0;
 }
 
Comment 10 Oliver Kellogg 2006-11-20 21:02:39 UTC
Has anybody tried this again using 1.5.52 or SVN branches/KDE/3.5/kdesdk?
I am tempted to close this PR unless I hear back.
Comment 11 Achim Spangler 2006-12-06 17:44:56 UTC
Hi Oliver,
I've still those problems in the saved XMI.
The following is just a very small part of all my redundant Stereotypes.
Your DEBUG statements are printed very very often on load of my XMI file.
BUT - when I open the stereotype drop down list, all those redundant copies are inserted there.
==>>
There seems to be some other construction paths for Stereotypes, or whatever is going wrong.

Bye,
Achim



  <UML:Model isSpecification="false" isLeaf="false" isRoot="false" xmi.id="m1" isAbstract="false" name="UML-Modell" >
   <UML:Namespace.ownedElement>
    <UML:Stereotype isSpecification="false" isLeaf="false" visibility="public" namespace="m1" xmi.id="7l6nva8uOJIY" isRoot="false" isAbstract="false" name="folder" />
    <UML:Stereotype isSpecification="false" isLeaf="false" visibility="public" namespace="m1" xmi.id="DgnSE7nQyiVO" isRoot="false" isAbstract="false" name="datatype" />
    <UML:Stereotype isSpecification="false" isLeaf="false" visibility="public" namespace="m1" xmi.id="8nKI1BGZADae" isRoot="false" isAbstract="false" name="folder" />
    <UML:Stereotype isSpecification="false" isLeaf="false" visibility="public" namespace="m1" xmi.id="nLZw3mv5Qsjd" isRoot="false" isAbstract="false" name="datatype" />
    <UML:Stereotype isSpecification="false" isLeaf="false" visibility="public" namespace="m1" xmi.id="SaaStua0kHtU" isRoot="false" isAbstract="false" name="folder" />
    <UML:Stereotype isSpecification="false" isLeaf="false" visibility="public" namespace="m1" xmi.id="m8m8rc9CDkI4" isRoot="false" isAbstract="false" name="datatype" />
    <UML:Stereotype isSpecification="false" isLeaf="false" visibility="public" namespace="m1" xmi.id="AuFT0A3YFCCD" isRoot="false" isAbstract="false" name="folder" />
    <UML:Stereotype isSpecification="false" isLeaf="false" visibility="public" namespace="m1" xmi.id="FhgzbVMrg2dw" isRoot="false" isAbstract="false" name="datatype" />
    <UML:Stereotype isSpecification="false" isLeaf="false" visibility="public" namespace="m1" xmi.id="ZbOSOA2Hzs79" isRoot="false" isAbstract="false" name="folder" />
    <UML:Stereotype isSpecification="false" isLeaf="false" visibility="public" namespace="m1" xmi.id="MqCfvfszL6Ho" isRoot="false" isAbstract="false" name="datatype" />
    <UML:Stereotype isSpecification="false" isLeaf="false" visibility="public" namespace="m1" xmi.id="8vEGJjfcsLsp" isRoot="false" isAbstract="false" name="folder" />
    <UML:Stereotype isSpecification="false" isLeaf="false" visibility="public" namespace="m1" xmi.id="A1pkzvVq95n1" isRoot="false" isAbstract="false" name="datatype" />
    <UML:Stereotype isSpecification="false" isLeaf="false" visibility="public" namespace="m1" xmi.id="3KD8M6JOO32J" isRoot="false" isAbstract="false" name="folder" />
    <UML:Stereotype isSpecification="false" isLeaf="false" visibility="public" namespace="m1" xmi.id="Ri3hrkIj9itK" isRoot="false" isAbstract="false" name="folder" />
    <UML:Stereotype isSpecification="false" isLeaf="false" visibility="public" namespace="m1" xmi.id="CdMn0FEE9t2q" isRoot="false" isAbstract="false" name="folder" />
    <UML:Stereotype isSpecification="false" isLeaf="false" visibility="public" namespace="m1" xmi.id="w025BjA5uUHn" isRoot="false" isAbstract="false" name="folder" />
    <UML:Stereotype isSpecification="false" isLeaf="false" visibility="public" namespace="m1" xmi.id="wKUpalUjDKIV" isRoot="false" isAbstract="false" name="folder" />
    <UML:Stereotype isSpecification="false" isLeaf="false" visibility="public" namespace="m1" xmi.id="L4Dd5vKoazk2" isRoot="false" isAbstract="false" name="folder" />
    <UML:Stereotype isSpecification="false" isLeaf="false" visibility="public" namespace="m1" xmi.id="MHLPQYIbqWvR" isRoot="false" isAbstract="false" name="folder" />
    <UML:Stereotype isSpecification="false" isLeaf="false" visibility="public" namespace="m1" xmi.id="ECdeiVXEWVaU" isRoot="false" isAbstract="false" name="datatype" />
    <UML:Stereotype isSpecification="false" isLeaf="false" visibility="public" namespace="m1" xmi.id="IQqJ1jZ9M6xI" isRoot="false" isAbstract="false" name="folder" />
    <UML:Stereotype isSpecification="false" isLeaf="false" visibility="public" namespace="m1" xmi.id="hlqSvrUuGKfM" isRoot="false" isAbstract="false" name="folder" />
    <UML:Stereotype isSpecification="false" isLeaf="false" visibility="public" namespace="m1" xmi.id="S8515A2u3yb0" isRoot="false" isAbstract="false" name="folder" />
    <UML:Stereotype isSpecification="false" isLeaf="false" visibility="public" namespace="m1" xmi.id="neZ9ApLKoTKb" isRoot="false" isAbstract="false" name="folder" />
    <UML:Stereotype isSpecification="false" isLeaf="false" visibility="public" namespace="m1" xmi.id="2fgUtglPLjU1" isRoot="false" isAbstract="false" name="folder" />
    <UML:Stereotype isSpecification="false" isLeaf="false" visibility="public" namespace="m1" xmi.id="daPFZSE1iEls" isRoot="false" isAbstract="false" name="folder" />
    <UML:Stereotype isSpecification="false" isLeaf="false" visibility="public" namespace="m1" xmi.id="ULgUUWgOqkFq" isRoot="false" isAbstract="false" name="folder" />
    <UML:Stereotype isSpecification="false" isLeaf="false" visibility="public" namespace="m1" xmi.id="DkMnPWHucdNs" isRoot="false" isAbstract="false" name="folder" />
    <UML:Stereotype isSpecification="false" isLeaf="false" visibility="public" namespace="m1" xmi.id="tFdgvSSomvcv" isRoot="false" isAbstract="false" name="folder" />
    <UML:Stereotype isSpecification="false" isLeaf="false" visibility="public" namespace="m1" xmi.id="jvjY7YEFmjX9" isRoot="false" isAbstract="false" name="folder" />
    <UML:Stereotype isSpecification="false" isLeaf="false" visibility="public" namespace="m1" xmi.id="oirK5Mh1J8Ir" isRoot="false" isAbstract="false" name="folder" />
    <UML:Stereotype isSpecification="false" isLeaf="false" visibility="public" namespace="m1" xmi.id="1" isRoot="false" isAbstract="false" name="folder" />
    <UML:Stereotype isSpecification="false" isLeaf="false" visibility="public" namespace="m1" xmi.id="4" isRoot="false" isAbstract="false" name="datatype" />
    <UML:Stereotype isSpecification="false" isLeaf="false" visibility="public" namespace="m1" xmi.id="ULgUUWgOqkFq" isRoot="false" isAbstract="false" name="folder" />
Comment 12 Achim Spangler 2006-12-06 17:56:06 UTC
Hi again,
I noticed, that ALL duplicates are having name "folder" or "datatype". So maybe this is a hint for the problem reason.

Thanks,
Achim

P.S.: I work on Kubuntu Dapper, KDE 3.5.5 with current SVN
Comment 13 Achim Spangler 2006-12-06 18:01:48 UTC
Hello again, ....
I did a manual cleanup of my XMI file.
Loaded it.
Just moved some diagram widgets around, to get a SAVE.
==>>
I have again all those redundant "datatype" and "folder" stereotypes.
==>>
Is it possible that some sort of backward compatibility mode auto-generate-on-save or auto-generate-on-load algorithm triggers creation of the redundant copies during the SAVE or LOAD procedure?

Thanks,
Achim
Comment 14 Oliver Kellogg 2006-12-07 07:49:42 UTC
Thanks Achim.
On the load side, it's clear - the duplicates all have different
xmi.id's so they must be treated as distinct objects.
The problem is on the creation/save side - but I'm still puzzled.
Could you set a breakpoint on the UMLStereotype constructor,
stereotype.cpp:29 -

    if (existing) {
        kError() << "UMLStereotype constructor: " << name << " already exists"
                  << kdBacktrace(25) << endl;
    }

and append the backtrace. That would really be helpful.


Comment 15 Achim Spangler 2006-12-07 17:26:22 UTC
Hi Oliver,
I've found at least a quick hack solution.
The function UMLDoc::loadUMLObjectsFromXMI() calls addStereotype(s); (line 1713) even if it has detected, that a corresponding Stereotype with the same ID exists already.

This might be caused by my xmi file, which has been initially created before the Package data structure changes. I extracted the hopefully relevant parts of the xmi file into one attachement.

I attach also a patch that solves the problem for me, by simply NOT creating a strereotype for "folder" or "datatype" when it already exists. Maybe we should change in this case also the referring node, to refer to the already existing streotype node. 

But I do not understand, how a _correct_ "folder" or "datatyp" streotype linkage should look like.

Bye,
Achim
Comment 16 Achim Spangler 2006-12-07 17:28:48 UTC
Created attachment 18829 [details]
extracts from testcase
Comment 17 Achim Spangler 2006-12-07 17:31:43 UTC
Created attachment 18831 [details]
proof of concept patch

This patch should be extended to fix the XML node, which triggers the redundant
"folder" or "datatype" stereotype creation, during load. This patch simply
blocks the creation of redundant stereotype with name "folder" or "datatype".
Comment 18 Oliver Kellogg 2006-12-08 07:47:44 UTC
SVN commit 611440 by okellogg:

findOrCreateStereotype(): Use name as xmi.id.
Should prevent same named stereotypes that only differ in xmi.id from being
treated as distinct objects on load.
CCBUG:135606


 M  +1 -1      umldoc.cpp  


--- branches/KDE/3.5/kdesdk/umbrello/umbrello/umldoc.cpp #611439:611440
@@ -838,7 +838,7 @@
     if (s != NULL) {
         return s;
     }
-    s = new UMLStereotype(name);
+    s = new UMLStereotype(name, STR2ID(name));
     addStereotype(s);
     //emit modified();
     return s;
Comment 19 Achim Spangler 2006-12-08 10:36:03 UTC
Created attachment 18843 [details]
test  case after Olivers fix

Hi Oliver,
is it normal to have TWO stereotypes with NAME "folder", where one has
xmi.id="folder" and the other has xmi.id="hatrNYCy0YN5"??

Or is this an indication for some furhter existing problems?

At least the good news:
Those copies don't get increased any more - so I can live with the current
situation.

I have extracted the hopefully important parts from my private project in this
attachement.

Thanks,
Achim
Comment 20 Oliver Kellogg 2006-12-08 19:48:49 UTC
SVN commit 611560 by okellogg:

The bulk of this PR was fixed by r611440, the remaining duplication mentioned in
Comment #19 could be cleaned up manually (use the xmi.id="folder" everywhere.)
BUG:135606


 M  +1 -0      ChangeLog  


--- branches/KDE/3.5/kdesdk/umbrello/ChangeLog #611559:611560
@@ -12,6 +12,7 @@
 * Optimized printer margins
   http://www.geeksoc.org/~jr/umbrello/uml-devel/9895.html
 * Bugs/wishes from http://bugs.kde.org:
+* Umbrello saves too much copies at xmi (135606)
 * Artifacts of a component diagram are wrongly placed in Deployment View folder (137564)
 * Incorrect export to SQL (138139)