Bug 122188 - crash when creating a datatype with the same name as a class
Summary: crash when creating a datatype with the same name as a class
Status: RESOLVED FIXED
Alias: None
Product: umbrello
Classification: Applications
Component: general (show other bugs)
Version: unspecified
Platform: Compiled Sources Linux
: NOR crash
Target Milestone: ---
Assignee: Umbrello Development Group
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-02-17 23:12 UTC by Yan Morin
Modified: 2006-02-18 20:44 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Yan Morin 2006-02-17 23:12:08 UTC
Version:           1.5.2 (using KDE KDE 3.5.1)
Installed from:    Compiled From Sources

How to reproduce
1. Create a class with the name "test"
2. Create a datatype with the name "test"
3. The user see the popup: 
"The name you entered was not unique! Creation process has been canceled." 

4. Click on OK
5. Crash...

it's because UMLListViewItem::okRename is call, then call the UMLListView to remove itself (this). Then it crash because this is not valid anymore.
in umllistviewitem.cpp
    332 void UMLListViewItem::okRename( int col ) {
    339         if ( s_pListView->slotItemRenamed( this, col ) ) {

in umllistview.cpp   
2234 bool UMLListView::slotItemRenamed( QListViewItem * item , int /*col*/ ) {
2274             delete item;

It's also happen when you create a Datatype or a class, then erase the name and press "enter".
Comment 1 Yan Morin 2006-02-17 23:44:20 UTC
Solution?
1. slotItemRenamed() called by UMLListViewItem should not delete the item. An empty item could exist and the user should remove it manually?

2. createChildUMLObject() at line 2306 called bye slotItemRenamed (so by UMLListViewItem object) should not delete the item. 

3. There is no bug when creating a diagram with the same name, because it asks the name before adding it to the ListView.
Comment 2 Oliver Kellogg 2006-02-18 20:44:53 UTC
SVN commit 511082 by okellogg:

UMLListView::slotItemRenamed(): Rename to itemRenamed() because it's not used
 as a slot.  Move physical deletion of the item to UMLListViewItem::okRename().
BUG:122188


 M  +4 -1      ChangeLog  
 M  +4 -6      umbrello/umllistview.cpp  
 M  +5 -7      umbrello/umllistview.h  
 M  +2 -2      umbrello/umllistviewitem.cpp  


--- branches/KDE/3.5/kdesdk/umbrello/ChangeLog #511081:511082
@@ -5,13 +5,16 @@
 * fixed problem with font size computation/word wrap in note widgets
   http://sourceforge.net/mailarchive/forum.php?thread_id=9558795&forum_id=472
 * Bugs/wishes from http://bugs.kde.org:
-* Umbrello doesnt allow some keywords for return types (115991)
+* Import Rose model files (81364)
+* Default data types not added for old Java generator (115991)
 * Multiplicity labels positioned incorrectly when moving entities (120598)
 * Types of entity's attributes are displayed instead of their names (120742)
 * Unable to delete entity from entity list in "UML Model" frame (120750)
 * Interface names not italicized in diagram view (120761)
 * Cannot Resize Sequence Diagram Synchronous Messages (120910)
 * Crash when importing Python files (121952)
+* "void" is imported as class and not datatypes (122184)
+* Crash when creating a datatype with the same name as a class (122188)
 
 Version 1.5.1
 
--- branches/KDE/3.5/kdesdk/umbrello/umbrello/umllistview.cpp #511081:511082
@@ -2231,7 +2231,7 @@
     // is called (automatically by QListViewItem.)
 }
 
-bool UMLListView::slotItemRenamed( QListViewItem * item , int /*col*/ ) {
+bool UMLListView::itemRenamed( QListViewItem * item , int /*col*/ ) {
     //if true the item was cancel before this message
     if( m_bIgnoreCancelRename ) {
         return true;
@@ -2242,13 +2242,12 @@
     QString newText = renamedItem -> text( 0 );
     renamedItem -> setCreating( false );
 
-    //if the length of any type then delete it.
-    if( newText.length() == 0 ) {
+    // If the type is empty then delete it.
+    if (newText.isEmpty() || newText.contains(QRegExp("^\\s+$"))) {
         KMessageBox::error(
             kapp -> mainWidget(),
             i18n( "The name you entered was invalid.\nCreation process has been canceled." ),
             i18n( "Name Not Valid" ) );
-        delete item;
         return false;
     }
     // No need to do anything for folders if the string length was > 0
@@ -2271,7 +2270,6 @@
                 kapp -> mainWidget(),
                 i18n( "The name you entered was not unique!\nCreation process has been canceled." ),
                 i18n( "Name Not Unique" ) );
-            delete item;
             return false;
         }
     }
@@ -2291,7 +2289,7 @@
         {
             Uml::Object_Type ot = convert_LVT_OT(type);
             if (! ot) {
-                kdError() << "UMLListView::slotItemRenamed() internal" << endl;
+                kdError() << "UMLListView::itemRenamed() internal" << endl;
                 return false;
             }
             createUMLObject( renamedItem, ot );
--- branches/KDE/3.5/kdesdk/umbrello/umbrello/umllistview.h #511081:511082
@@ -302,6 +302,11 @@
     UMLListViewItem * moveObject(Uml::IDType srcId, Uml::ListView_Type srcType,
                                  UMLListViewItem *newParent);
 
+    /**
+     * Called for informing the list view that an item was renamed.
+     */
+    bool itemRenamed(QListViewItem* item , int col);
+
     void closeDatatypesFolder();
 
     UMLListViewItem *theRootView() { return m_rv; }
@@ -529,13 +534,6 @@
      */
     void slotCutSuccessful();
 
-    /**
-     *     When a user requests a new item we wait for the signal
-     *     to then verify the item.  The class only connects to the
-     *     rename signal while needed.
-     */
-    bool slotItemRenamed(QListViewItem* item , int col);
-
 signals:
 
     /**
--- branches/KDE/3.5/kdesdk/umbrello/umbrello/umllistviewitem.cpp #511081:511082
@@ -336,11 +336,11 @@
         m_bCreating = false;
         QString savedLabel = m_Label;
         m_Label = text(col);
-        if ( s_pListView->slotItemRenamed( this, col ) ) {
+        if ( s_pListView->itemRenamed( this, col ) ) {
             s_pListView->ensureItemVisible(this);
             doc->setModified(true);
         } else {
-            m_Label = savedLabel;
+            delete this;
         }
         return;
     }