Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 296786

Summary: [actions] Opening a project in Package Explorer forces me to select the project to open twice
Product: [Eclipse Project] JDT Reporter: Tomasz Zarna <tomasz.zarna>
Component: UIAssignee: Raksha Vasisht <raksha.vasisht>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: daniel_megert, markus.kell.r, remy.suen, Szymon.Brandys
Version: 3.6Flags: markus.kell.r: review+
Target Milestone: 3.7 M7   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
Screen shot
none
workspace with troublesome projects
none
Proposed fix none

Description Tomasz Zarna CLA 2009-12-03 05:59:08 EST
I20091201-1600

Steps:
1. Close a project in Package Explorer.
2. Pick 'Open project' from context menu for the project.
=> Instead of opening the project, 'Open Project' dialog pops out asking to me to select the project(s) I want to open one more time.

I'm using Working Sets as Top Level Elements.
Comment 1 Tomasz Zarna CLA 2009-12-03 06:02:22 EST
Szymon has been experiencing the same inconvenience for some time.
Comment 2 Markus Keller CLA 2009-12-03 07:49:37 EST
I can't reproduce that. When the selection contains a closed project, the OpenProjectAction does not show the dialog.

The dialog is only shown when no closed project is selected. Note that the dashed rectangle around a tree item is not a selection -- that's just a focus cursor.

The implementation of this is in org.eclipse.jdt.ui.actions.OpenProjectAction.run(IStructuredSelection).
Comment 3 Tomasz Zarna CLA 2009-12-03 10:44:56 EST
I admit it does not happen each time. It appears to be a timing issue when 2 'Open project' jobs (for the same project) are batched and wait for 'Building workspace' to complete (triggered on the project's closure).
Comment 4 Tomasz Zarna CLA 2009-12-08 10:44:03 EST
Created attachment 154018 [details]
Screen shot

I20091208-0100

More reliable steps:
1. Switch to a large workspace. This seems to be crucial since auto-build takes more time then.
2. Make sure 'Build Automatically' option is on
3. Right click on o.e.jdt.core and do 'Close project'
=> Workspace starts build
4. As soon as project's icon changes to 'closed', right click again on the project and pick 'Open project'
=> Workspace is still building
5. Quickly right click again on the same project and do 'Open project' one more time
=> See screen shot

I know it's a matter of timing and a bit of luck but I was able to reproduce it quite easily on Pawel's I20091207-1800 in his workspace as well.
Comment 5 Tomasz Zarna CLA 2010-05-27 07:40:35 EDT
Created attachment 170168 [details]
workspace with troublesome projects

I stripped and packed my workspace as this hit me again running 3.6RC2. 

Steps:
1. Extract the archive
2. Run Eclipse and point it to use the workspace from the archive
3. Go to Java perspective
4. In Package Explorer expand 'extssh' working set
5. Select o.e.core.net.linux.x86 project (closed)
6. Right click on the project and select 'Open'
=> Instead of opening the project, 'Open Project' dialog pops out asking to me
to select the project(s) I want to open one more time.

btw, ignore the previous comment, as it turned out, the building process has nothing to do with this issue.
Comment 6 Tomasz Zarna CLA 2010-05-27 07:44:20 EDT
Another curiosity:
7. Open the project by selecting it in the dialog
8. Delete it, but leave it on disk
9. Refresh (F5) the working set
=> The project re-appears in the Package Explorer, but it's gone in the Project Explorer
Comment 7 Tomasz Zarna CLA 2010-05-27 07:45:29 EDT
Reopening, see the comments above.
Comment 8 Markus Keller CLA 2010-05-27 08:27:42 EDT
Reproduced, looks like a problem with the resource working set.

Also note the broken org.eclipse.releng in the working set (project not available on disk). The ResourceWorkingSetUpdater should probably take care of this.
Comment 9 Remy Suen CLA 2010-05-27 09:06:03 EDT
(In reply to comment #8)
> Reproduced, looks like a problem with the resource working set.
> 
> Also note the broken org.eclipse.releng in the working set (project not
> available on disk). The ResourceWorkingSetUpdater should probably take care of
> this.

There's also bug 311168 that may be related about working sets and non-existent projects.
Comment 10 Markus Keller CLA 2011-04-19 05:08:30 EDT
Raksha, could you please have a look?
Comment 11 Raksha Vasisht CLA 2011-04-21 03:34:02 EDT
Created attachment 193781 [details]
Proposed fix

(In reply to comment #5)
> Created attachment 170168 [details] [diff]
> workspace with troublesome projects
> 
> I stripped and packed my workspace as this hit me again running 3.6RC2. 
> 
> Steps:
> 1. Extract the archive
> 2. Run Eclipse and point it to use the workspace from the archive
> 3. Go to Java perspective
> 4. In Package Explorer expand 'extssh' working set
> 5. Select o.e.core.net.linux.x86 project (closed)
> 6. Right click on the project and select 'Open'
> => Instead of opening the project, 'Open Project' dialog pops out asking to me
> to select the project(s) I want to open one more time.

I see that the problem is in org.eclipse.jdt.ui.actions.OpenProjectAction.isClosedProject(Object) where we assume that the selection is an IProject instance, whereas in this attached example the selection is actually a JavaProject and hence goes not being detected as a closed project and opens a dialog with all the closed projects in the workspace. 
I'm not sure why the selection shows up as Java Project only when in Working Sets mode and not in Projects mode in PE. I can't reproduce the problem when I create new projects or check out a projectunder a resource working set. The attached patch takes care of the scenario when the selection is a JavaProject. 

(In reply to comment #6)
> Another curiosity:
> 7. Open the project by selecting it in the dialog
> 8. Delete it, but leave it on disk
> 9. Refresh (F5) the working set
> => The project re-appears in the Package Explorer, but it's gone in the Project
> Explorer
 I think this has been fixed in bug 300368 comment# 15. It also gives you a workaround for older builds and existing stale projects.
Comment 12 Markus Keller CLA 2011-04-21 11:40:23 EDT
Patch is good, please release.
Comment 13 Raksha Vasisht CLA 2011-04-21 12:02:07 EDT
(In reply to comment #12)
> Patch is good, please release.

Thanks, Committed to HEAD.
Comment 14 Dani Megert CLA 2011-04-26 10:27:59 EDT
Verified in I20110425-1800: the fix looks good. I suspect that the given workspace somehow got corrupted at some point, e.g. abnormally exited and hence the Platform's working set manager had the Java project stored but somehow it got closed in-between. Under normal circumstances a closed project is an IProject in the working set manager.