Bug 103258 - Category.deleteCategoryAndRemap() fails when there are related categories
Category.deleteCategoryAndRemap() fails when there are related categories
Status: CLOSED RAWHIDE
Product: Red Hat Web Application Framework
Classification: Retired
Component: other (Show other bugs)
nightly
All Linux
medium Severity high
: ---
: ---
Assigned To: Archit Shah
Jon Orris
:
Depends On:
Blocks: 100952
  Show dependency treegraph
 
Reported: 2003-08-28 04:17 EDT by Carsten Clasohm
Modified: 2007-04-18 12:57 EDT (History)
0 users

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2003-12-10 15:41:15 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:


Attachments (Terms of Use)
JSP for reproducing the problem (337 bytes, text/plain)
2003-08-28 04:18 EDT, Carsten Clasohm
no flags Details

  None (edit)
Description Carsten Clasohm 2003-08-28 04:17:14 EDT
Description of problem:
When calling Category.deleteCategoryAndRemap() for a category to which related
categories have been added with addRelatedCategory(), deletion of the "related
categories" association fails with a "IllegalArgumentException: No such object"
exception.


Version-Release number of selected component (if applicable):
6.0

How reproducible:
Always

Steps to Reproduce:
Replace the two category IDs in the attached JSP with actual values from your
cat_categories table and try to run the JSP.


Actual Results:  
java.lang.IllegalArgumentException: No such object:
[com.arsdigita.categorization.com_arsdigita_categorization_Category:parents::com_arsdigita_categorization_Category:related::Link:{parents=[com.arsdigita.categorization.Category:{id=147}],
related=[com.arsdigita.categorization.Category:{id=165}]}]
	at com.redhat.persistence.Session.fetchPropertyData(Session.java:787)
	at com.redhat.persistence.Session$1.onRole(Session.java:115)
	at com.redhat.persistence.metadata.Role.dispatch(Role.java:92)
	at com.redhat.persistence.Session.get(Session.java:113)
	at com.arsdigita.persistence.DataObjectImpl.get(DataObjectImpl.java:489)
	at com.arsdigita.persistence.DataObjectImpl.get(DataObjectImpl.java:200)
	at com.arsdigita.categorization.Category.deleteCategoryAndRemap(Category.java:923)


Additional info:

The cause for this error is the following while loop, which first deletes the
association and then tries to retrieve attributes from the link object it has
just deleted:

        while (cursor.next()) {
            DataObject link = cursor.getLink();
            remove(RELATED_CATEGORIES, cursor.getDataObject());
            if ("child".equals(link.get("relationType"))) {
                Category category = new Category(cursor.getDataObject());
                parent.addChild(category);
                if (Boolean.TRUE.equals(link.get("isDefault"))) {
                    category.setDefaultParentCategory(parent);
                }
            }
        }

One way to fix this:

        while (cursor.next()) {
            DataObject link = cursor.getLink();
	    String relationType = (String)link.get("relationType");
	    Boolean isDefault = (Boolean)link.get("isDefault");
            remove(RELATED_CATEGORIES, cursor.getDataObject());
            if ("child".equals(relationType)) {
                Category category = new Category(cursor.getDataObject());
                parent.addChild(category);
                if (Boolean.TRUE.equals(isDefault)) {
                    category.setDefaultParentCategory(parent);
                }
            }
        }
Comment 1 Carsten Clasohm 2003-08-28 04:18:47 EDT
Created attachment 94025 [details]
JSP for reproducing the problem
Comment 2 Richard Li 2003-08-28 07:47:07 EDT
Carsten: does your 35415 fix the problem, or does it need to be fixed some other
way?
Comment 3 Carsten Clasohm 2003-08-28 07:53:07 EDT
35415 fixes it.
Comment 4 Jon Orris 2003-12-09 18:37:48 EST
Has this been integrated onto the Troika branch at all?
Comment 5 Jon Orris 2003-12-10 15:41:15 EST
Integrated by Archit @35437

Note You need to log in before you can comment on or make changes to this bug.