Bug 110378 - [Misc] Project > Share Project... with non-project resource selected causes NPE
Summary: [Misc] Project > Share Project... with non-project resource selected causes NPE
Status: VERIFIED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: Team (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows 2000
: P3 normal (vote)
Target Milestone: 3.4 M1   Edit
Assignee: Tomasz Zarna CLA
QA Contact:
URL:
Whiteboard: hasPatch
Keywords: contributed
Depends on:
Blocks:
 
Reported: 2005-09-22 16:49 EDT by Mark Melvin CLA
Modified: 2007-08-07 12:12 EDT (History)
1 user (show)

See Also:


Attachments
Fix (1.13 KB, patch)
2007-07-09 09:14 EDT, Tomasz Zarna CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Mark Melvin CLA 2005-09-22 16:49:14 EDT
Open Eclipse with a non-CVS project in your workspace.  Expand the project, and
select a file, then exit Eclipse.  Restart Eclipse (the file should still be
selected, yet the Share Project menu item is enabled), and without touching the
Navigator View, goto Project > Share Project...  You should be greeted with a
NullPointerException dialog.
Comment 1 Kim Horne CLA 2005-09-23 09:59:50 EDT
I've debugged this a bit (because someone is chopping off the stack).  Here's the cause of the NPE:

Thread [main] (Suspended (exception NullPointerException))
	ConfigureProjectAction(TeamAction).getSelectedResources() line: 154
	ConfigureProjectAction(TeamAction).getSelectedProjects() line: 124
	ConfigureProjectAction$1.run(IProgressMonitor) line: 50
	TeamAction$2.run() line: 234
	BusyIndicator.showWhile(Display, Runnable) line: 69
	ConfigureProjectAction(TeamAction).run(IRunnableWithProgress, String, int) line: 231
	ConfigureProjectAction.run(IAction) line: 47
	ConfigureProjectAction(ActionDelegate).runWithEvent(IAction, Event) line: 70
	WWinPluginAction(PluginAction).runWithEvent(Event) line: 241
	WWinPluginAction.runWithEvent(Event) line: 223
	PluginActionContributionItem(ActionContributionItem).handleWidgetSelection(Event, boolean) line: 
538
	ActionContributionItem.access$2(ActionContributionItem, Event, boolean) line: 488
	ActionContributionItem$5.handleEvent(Event) line: 400
	EventTable.sendEvent(Event) line: 66
	MenuItem(Widget).sendEvent(Event) line: 1412
	MenuItem(Widget).sendEvent(int, Event, boolean) line: 1436
	MenuItem(Widget).sendEvent(int, Event) line: 1421
	MenuItem(Widget).notifyListeners(int, Event) line: 1251
	Display.runDeferredEvents() line: 3118
	Display.readAndDispatch() line: 2766
	Workbench.runEventLoop(Window$IExceptionHandler, Display) line: 1755
	Workbench.runUI() line: 1719
	Workbench.createAndRunWorkbench(Display, WorkbenchAdvisor) line: 368
	PlatformUI.createAndRunWorkbench(Display, WorkbenchAdvisor) line: 143
	IDEApplication.run(Object) line: 106
	PlatformActivator$1.run(Object) line: 226
	EclipseStarter.run(Object) line: 377
	EclipseStarter.run(String[], Runnable) line: 164
	NativeMethodAccessorImpl.invoke0(Method, Object, Object[]) line: not available [native method]
	NativeMethodAccessorImpl.invoke(Object, Object[]) line: 39
	DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: 25
	Method.invoke(Object, Object...) line: 585
	Main.invokeFramework(String[], URL[]) line: 338
	Main.basicRun(String[]) line: 282
	Main.run(String[]) line: 977
	Main.main(String[]) line: 952


Passing to team.
Comment 2 Michael Valenta CLA 2005-10-28 12:06:34 EDT
Fix released to HEAD
Comment 3 Michael Valenta CLA 2005-11-01 08:59:20 EST
Bogdan, please verify during 3.2 M3 test pass
Comment 4 Bogdan Gheorghe CLA 2005-11-01 13:33:16 EST
Verified in I20051101-0010
Comment 5 Mark Melvin CLA 2007-02-26 16:39:55 EST
We were resolving bugs in our bug system and I thought this bug was fixed because I could no longer reproduce it.  However, one of our other developers could reliably reproduce it.  After some further head bashing we found out that this bug still exists iff you have an editor open when you exit Eclipse.  So - to reproduce:

1) Open Eclipse with at least one *non-CVS* project in your workspace.
2) Close all editors.
3) Open any file so you have one editor open.
4) Select any "file" in any *non-CVS* project in the navigator view.
5) Close the workbench.
6) Restart Eclipse.
7) Without touching *anything*, goto Project > Share Project...

The file will be selected, and the menu item will be enabled and you will get a very weird exception dialog.
Comment 6 Tomasz Zarna CLA 2007-06-21 11:11:15 EDT
I'm able to reproduce this one. Here is the stack trace:

java.lang.ArrayIndexOutOfBoundsException: 0
at org.eclipse.team.internal.ui.actions.ConfigureProjectAction$1.run(ConfigureProjectAction.java:48)
at org.eclipse.team.internal.ui.actions.TeamAction$2.run(TeamAction.java:237)
at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:67)
at org.eclipse.team.internal.ui.actions.TeamAction.run(TeamAction.java:234)
at org.eclipse.team.internal.ui.actions.ConfigureProjectAction.execute(ConfigureProjectAction.java:45)
at org.eclipse.team.internal.ui.actions.TeamAction.run(TeamAction.java:477)
at org.eclipse.team.internal.ui.actions.TeamAction.runWithEvent(TeamAction.java:511)
at org.eclipse.ui.internal.PluginAction.runWithEvent(PluginAction.java:246)
at org.eclipse.ui.internal.WWinPluginAction.runWithEvent(WWinPluginAction.java:229)
at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:545)
at org.eclipse.jface.action.ActionContributionItem.access$2(ActionContributionItem.java:490)
at org.eclipse.jface.action.ActionContributionItem$5.handleEvent(ActionContributionItem.java:402)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:66)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:938)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3682)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3293)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2389)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2353)
at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2219)
at org.eclipse.ui.internal.Workbench$4.run(Workbench.java:466)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:289)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:461)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:106)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:153)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:106)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:76)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:363)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:176)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:504)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:443)
at org.eclipse.equinox.launcher.Main.run(Main.java:1169)
at org.eclipse.equinox.launcher.Main.main(Main.java:1144)

As you can see the NPE is caused because there is actually no Project selected. I can see at least two solutions for the problem:
1. Make sure that "Share Project" entry in the main menu is disabled for all non-project resources (the entry in the popup menu is disabled like it should be).
2. Modify the TeamAction#getSelectedProjects() method so it will return a project even when there is a file/folder selected. We can look for the project of a given resource.
Comment 7 Michael Valenta CLA 2007-07-06 08:51:08 EDT
The question is why is the menu enabled in the first place. The ConfigureProjectAction#isEnabled() method clearly only returns true if a single project is selected. It appears that, on startup, there is a scenario where the isEnabled is not being called before the operation is run. This may be a bug in the workbench so we should track it down (i.e. try and debug it and confirm that isEnabled is not being called and, if confirmed, forward the bug to Platform/UI).

Having said that, we should also add a check to the execute to exit if there isn't a selected project.
Comment 8 Mark Melvin CLA 2007-07-06 09:36:58 EDT
Yes.  I have had similar issues in the past with some of my actions being enabled when they were clearly not *supposed* to be and I never did track them down.  It was driving me nuts.  Eventually I just decided it was a feature. ;)  Although I never made the connection to an editor being open...
Comment 9 Tomasz Zarna CLA 2007-07-09 09:14:18 EDT
Created attachment 73312 [details]
Fix

The check for proper selection added to the execute method. After some debugging done I can confirm that the isEnabled test is not called for the Project > Share Project... as well as for other Team Actions located in the main toolbar menu.

First, I though about disabling the menu entry (the action) after the check in the execute method fails. But I think that after forwarding the bug to Platform/UI they will find a better way to handle this case.
Comment 10 Michael Valenta CLA 2007-07-09 11:12:22 EDT
I have released the patch to HEAD. Now that we've fixed the problem in Team, it would be good if we could create a simple example plug-in that shows the failure. We can then create a separate bug against Platform/UI and attach the example. Tomek, can you do this please.
Comment 11 Tomasz Zarna CLA 2007-07-09 14:56:38 EDT
Done. The bug with a simple plug-in is here: bug 195879.
Comment 12 Michael Valenta CLA 2007-07-09 15:00:20 EDT
Thanks. Marking the Team specific issue fixed.
Comment 13 Michael Valenta CLA 2007-08-07 12:12:29 EDT
Verified in build I20070807-0010