Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 343541 - - IndirectSet triggers raiseAddChangeEvent even when no element was added
Summary: - IndirectSet triggers raiseAddChangeEvent even when no element was added
Status: NEW
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows 7
: P3 normal with 1 vote (vote)
Target Milestone: ---   Edit
Assignee: Nobody - feel free to take it CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-04-21 10:10 EDT by Jakub Kahovec CLA
Modified: 2022-06-09 10:30 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jakub Kahovec CLA 2011-04-21 10:10:14 EDT
Hi,

I was debugging some code and noticed that when adding an element into the IndirectSet, an event raiseAddChangeEvent is being triggered even when the object is actually not added, causing IMHO unnecessary overhead.

Here is the snippet :

    public boolean add(Object element) {
        boolean added = true;
        // PERF: If not instantiated just record the add to avoid the instantiation.
        if (shouldAvoidInstantiation()) {
            if (hasRemovedElements() && getRemovedElements().contains(element)) {
                getRemovedElements().remove(element);
            } else if (getAddedElements().contains(element)) {
                // Must avoid recursion for relationship maintenance.                
                return false;
            } else {
                getAddedElements().add(element);
            }
        } else {
            added = getDelegate().add(element);
        }
        raiseAddChangeEvent(element);
        return added;
    }



Note the line

    added = getDelegate().add(element);



Variable added is set to false if the element is already present in the delegated set but at the end of the method the event raiseAddChangeEvent is triggered regardless the added variable

I think the event should only be triggered when the element was actually added.

Jakub
Comment 1 Tom Ware CLA 2011-05-12 15:37:15 EDT
Setting target and priority.  See the following page for the meanings of these fields:

http://wiki.eclipse.org/EclipseLink/Development/Bugs/Guidelines

Community: Please vote for this bug if it is important to you.  Votes are one of the main criteria we use to determine which bugs to fix next.
Comment 2 Eclipse Webmaster CLA 2022-06-09 10:30:11 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink