Bug 216758 - [EditorMgmt] NavigationHistory - mergeInto produces NavigationHistoryEntries with disposed locations
Summary: [EditorMgmt] NavigationHistory - mergeInto produces NavigationHistoryEntries ...
Status: VERIFIED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.3.1   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.4 M7   Edit
Assignee: Boris Bokowski CLA
QA Contact:
URL:
Whiteboard:
Keywords: helpwanted
Depends on:
Blocks:
 
Reported: 2008-01-28 08:42 EST by Heiko Böttger CLA
Modified: 2008-05-02 11:48 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 Heiko Böttger CLA 2008-01-28 08:42:39 EST
Build ID: M20071023-1652

Steps To Reproduce:
1. Call mergeInto on a NavigationHistoryEntry with a NavigationLocation set using a NavigationHistoryEntry as param which has no location (location == null).

2. Call dispose on the same NavigationHistoryEntry.

The NavigationLocation is disposed, but shouldn't. It happens in our editor, when eclipse starts while it was previously open.


More information:
    /**
     * Disposes this entry and its location.
     */
    void dispose() {
        if (location != null) {
			location.dispose();
		}
        editorInfo = null;
    }

    /**
     * Merges this entry into the current entry. Returns true
     * if the merge was possible otherwise returns false.
     */
    boolean mergeInto(NavigationHistoryEntry currentEntry) {
        if (editorInfo.editorInput != null
                && editorInfo.editorInput
                        .equals(currentEntry.editorInfo.editorInput)) {
            if (location != null) {
                if (currentEntry.location == null) {
                    currentEntry.location = location;
//location is used by both entries, but will be disposed with the first entry
                    return true;
                } else {
                    return location.mergeInto(currentEntry.location);
                }
            } else if (currentEntry.location == null) {
                return true;
            }
        }
        return false;
    }
Comment 1 Boris Bokowski CLA 2008-01-29 00:45:57 EST
Do you have a suggestion as how to fix this?
Comment 2 Paul Webster CLA 2008-01-29 08:46:26 EST
What about if currentEntry.location == null first create a new Location and then call location.mergeInto(currentEntry.location);

Later,
PW
Comment 3 Heiko Böttger CLA 2008-01-30 02:45:40 EST
I think creating a new location as suggested in #2 would be the best solution. 

Another possibility is to set the this.location = null.

if (currentEntry.location == null) {
  currentEntry.location = location;
  location = null;
  return true;
} else {

This would imply that the entry on which mergedInto was called won't be used after. I wonder how it comes that there is an entry without a location, i thought that the location should always be restored by a call to #restoreLocation before it is merged.
Comment 4 Boris Bokowski CLA 2008-04-28 16:12:26 EDT
Fixed in HEAD by setting this.location to null.
Comment 5 Boris Bokowski CLA 2008-04-30 16:44:41 EDT
Heiko, could you verify (using a recent I build) that my fix works for you?
Comment 6 Boris Bokowski CLA 2008-05-02 11:48:57 EDT
Verified by code inspection in I20080502-0100.