Bug 360065 - NPE in dndaddon.DnDManager
Summary: NPE in dndaddon.DnDManager
Status: RESOLVED WORKSFORME
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.2   Edit
Hardware: PC Windows 7
: P3 normal with 2 votes (vote)
Target Milestone: ---   Edit
Assignee: Platform UI Triaged CLA
QA Contact:
URL:
Whiteboard: candidate43
Keywords:
: 367127 367948 (view as bug list)
Depends on:
Blocks:
 
Reported: 2011-10-06 02:22 EDT by Dani Megert CLA
Modified: 2014-07-23 12:10 EDT (History)
9 users (show)

See Also:


Attachments
Stack from when I encountered this problem (4.66 KB, text/plain)
2011-10-26 16:23 EDT, Chris Goldthorpe CLA
no flags Details
Suggested fix (1.45 KB, patch)
2011-10-27 14:32 EDT, Chris Goldthorpe CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Dani Megert CLA 2011-10-06 02:22:08 EDT
I20111004-2000

!ENTRY org.eclipse.e4.ui.workbench 4 0 2011-10-06 08:18:30.742
!MESSAGE Internal Error
!STACK 0
java.lang.NullPointerException
	at org.eclipse.e4.ui.workbench.addons.dndaddon.DnDManager$3$1.run(DnDManager.java:172)
	at org.eclipse.swt.widgets.Synchronizer.syncExec(Synchronizer.java:180)
	at org.eclipse.ui.internal.UISynchronizer.syncExec(UISynchronizer.java:150)
	at org.eclipse.swt.widgets.Display.syncExec(Display.java:4683)
	at org.eclipse.e4.ui.workbench.addons.dndaddon.DnDManager$3.handleEvent(DnDManager.java:156)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1077)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1062)
	at org.eclipse.swt.widgets.Tracker.wmMouse(Tracker.java:1169)
	at org.eclipse.swt.widgets.Tracker.open(Tracker.java:582)
	at org.eclipse.e4.ui.workbench.addons.dndaddon.DnDManager.startDrag(DnDManager.java:199)
	at org.eclipse.e4.ui.workbench.addons.dndaddon.DnDManager$1$1.dragDetected(DnDManager.java:109)
	at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:127)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
	at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4165)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3754)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$9.run(PartRenderingEngine.java:972)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:888)
	at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:90)
	at org.eclipse.ui.internal.Workbench$3.run(Workbench.java:565)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:520)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
	at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:123)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:352)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:601)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:624)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:579)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1431)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1407)
Comment 1 Dani Megert CLA 2011-10-06 02:22:30 EDT
Happened while dragging the Package Explorer around in a new workspace.
Comment 2 Eric Moffatt CLA 2011-10-07 14:05:14 EDT
Can you remember where the cursor was when the NPE occurred (in the shared area, another stack, outside the WBW) ?

I'm just trying to gather enough info to reproduce this, I've been unsuccessful so far...
Comment 3 Dani Megert CLA 2011-10-10 05:39:59 EDT
(In reply to comment #2)
> Can you remember where the cursor was when the NPE occurred (in the shared
> area, another stack, outside the WBW) ?
No, sorry. I also quickly tried to reproduce it now - but no "luck".
Comment 4 Chris Goldthorpe CLA 2011-10-26 16:23:53 EDT
Created attachment 206033 [details]
Stack from when I encountered this problem

I just ran into the same NPE myself when using I20111025-2000. The stack trace looks similar and is attached.

In my case I had two stacked Java editors and dragged one of the editors to be to the left of the other so that after the operation each editor would be half the size it was before and tiled instead of stacked. The NPE showed up after I released the mouse. I tried again a few times and could not reproduce.
Comment 5 Chris Goldthorpe CLA 2011-10-27 14:15:17 EDT
I have some more information about this bug, which I started to look into in the debugger and by adding trace statements. It is not easy to reproduce but if you attempt enough window moves you will hit it sooner or later.

The NPE in DnDManager.java line 172 is happening because dragAgent is null. I added some println statements and determined that dragAgent is being set to null on the third line of DnDManager.startDrag(DragDetectEvent):

protected void startDrag(DragDetectEvent e) {
		info.update(e);
		dragAgent = getDragAgent(info);

After dragAgent has been set to null the anonymous listener for the SWT.Move event gets an NPE when it tries to handle an event. So the sequence was
1. startDrag() is called and getDragAgent() returns a non null value.
2. startDrag() is called again and getDragAgent() returns a null value.
3. The EventHandler created during the first call to startDrag recieves an event and dragAgent is now null, causing an NPE.

The underlying problem is that startDrag() is using instance variables rather than local variables, and referencing those instance variables in a handler. 

I will attach a patch with a suggested fix
Comment 6 Chris Goldthorpe CLA 2011-10-27 14:32:45 EDT
Created attachment 206089 [details]
Suggested fix

This patch will eliminate this NPE by using a local variable rather than an instance variable for dragAgent. Someone who is familiar with this code should review this to see if this is the correct solution. Note that there are other instance variables in DnDManager which should be checked to see if they could cause reentrancy problems.
Comment 7 Eric Moffatt CLA 2011-10-28 15:09:59 EDT
Chris, thanks (a lot!) for looking into this, we've had this spurious effect for some time...

I'll take a look at the patch once M3 goes out (actually after I get back next week...'-)
Comment 8 Remy Suen CLA 2011-12-06 14:46:52 EST
I20111205-2330

Line numbers are different but I guess it's the same problem.

java.lang.NullPointerException
	at org.eclipse.e4.ui.workbench.addons.dndaddon.DnDManager$3$1.run(DnDManager.java:170)
	at org.eclipse.swt.widgets.Synchronizer.syncExec(Synchronizer.java:180)
	at org.eclipse.ui.internal.UISynchronizer.syncExec(UISynchronizer.java:150)
	at org.eclipse.swt.widgets.Display.syncExec(Display.java:4683)
	at org.eclipse.e4.ui.workbench.addons.dndaddon.DnDManager$3.handleEvent(DnDManager.java:154)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1077)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1062)
	at org.eclipse.swt.widgets.Tracker.wmMouse(Tracker.java:1169)
	at org.eclipse.swt.widgets.Tracker.open(Tracker.java:582)
	at org.eclipse.e4.ui.workbench.addons.dndaddon.DnDManager.startDrag(DnDManager.java:197)
	at org.eclipse.e4.ui.workbench.addons.dndaddon.DnDManager$1$1.dragDetected(DnDManager.java:109)
	at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:127)
Comment 9 Eric Moffatt CLA 2011-12-07 11:10:13 EST
Sheesh, sorry folks...this dropped off my radar. I've tagged it for M5 and thanks again for the patch !
Comment 10 John Arthorne CLA 2012-01-11 11:49:59 EST
I'm seeing this too in a recent 4.2 build.
Comment 11 Michael Rennie CLA 2012-01-26 12:28:20 EST
(In reply to comment #9)
> Sheesh, sorry folks...this dropped off my radar. I've tagged it for M5 and
> thanks again for the patch !

I encountered this dragging around the debug view in I20120125-2200
Comment 12 Brian de Alwis CLA 2012-03-18 20:36:38 EDT
Just encountered in 4.2M6.
Comment 13 Eric Moffatt CLA 2012-04-04 14:22:46 EDT
Sheesh...was hoping that this had been fixed by the changes I made for dragging trim...Brian, any particulars about what you were doing? I'm trying to get a handle on how I can consistently repro this one...
Comment 14 Michael Rennie CLA 2012-04-09 12:26:36 EDT
(In reply to comment #13)
> Sheesh...was hoping that this had been fixed by the changes I made for dragging
> trim...Brian, any particulars about what you were doing? I'm trying to get a
> handle on how I can consistently repro this one...

Just reproduced in:

Version: 4.2.0
Build id: I20120321-0610

java.lang.NullPointerException
	at org.eclipse.e4.ui.workbench.addons.dndaddon.DnDManager$4$1.run(DnDManager.java:183)
	at org.eclipse.swt.widgets.Synchronizer.syncExec(Synchronizer.java:180)
	at org.eclipse.ui.internal.UISynchronizer.syncExec(UISynchronizer.java:150)
	at org.eclipse.swt.widgets.Display.syncExec(Display.java:4683)
	at org.eclipse.e4.ui.workbench.addons.dndaddon.DnDManager$4.handleEvent(DnDManager.java:180)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1077)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1062)
	at org.eclipse.swt.widgets.Tracker.wmMouse(Tracker.java:1169)
	at org.eclipse.swt.widgets.Tracker.open(Tracker.java:582)
	at org.eclipse.e4.ui.workbench.addons.dndaddon.DnDManager.startDrag(DnDManager.java:200)
	at org.eclipse.e4.ui.workbench.addons.dndaddon.DnDManager$1.dragDetected(DnDManager.java:83)
	at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:127)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
	at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4165)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3754)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$9.run(PartRenderingEngine.java:1016)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:910)
	at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:85)
	at org.eclipse.ui.internal.Workbench$4.run(Workbench.java:580)
Comment 15 Michael Rennie CLA 2012-04-09 14:37:50 EDT
Steps to reproduce:

1. open Java perspective or reset it
2. Click + drag in the editor area like you were selecting a block of text (but no editor is open)
3. grab the Package Explorer and drag it over to the editor area
4. drop it and immediately start another click+drag like step 2.

You will then get the NPE I pasted in comment #14
Comment 16 Eric Moffatt CLA 2012-04-10 15:41:22 EDT
Mike, when you dragged the Package Explorer where did you drop it in the editor area (i.e. split to the left, above ...? or into the tabs area of the stack ?

I just tried to repro this and couldn't get it to happen (but I've been working on the DnD for a few days now so MMMV...
Comment 17 Michael Rennie CLA 2012-04-10 23:39:58 EDT
(In reply to comment #16)
> Mike, when you dragged the Package Explorer where did you drop it in the editor
> area (i.e. split to the left, above ...? or into the tabs area of the stack ?
> 
> I just tried to repro this and couldn't get it to happen (but I've been working
> on the DnD for a few days now so MMMV...

I dropped it in the editor area, it didn't matter where. The key to reproduce is to start another drag really fast after you drop the view.
Comment 18 Eric Moffatt CLA 2012-04-11 12:25:08 EDT
Thanks Mike, once I get the 'edge' dragging working (finally!) I'll take a look at this. I think I have a possible solution; I'll 'defer' the execution of the actual 'drop' operation until after the previous DnD has been completely torn down (so you won't be able to start another drag while a previous one is finishing).
Comment 19 Eric Moffatt CLA 2012-04-17 13:53:11 EDT
I'll defer this for now. I'll be beating on the DnD over the M7 testing period and if I trip over it I may move it back to an RC milestone...
Comment 20 Michael Rennie CLA 2012-07-23 16:02:37 EDT
*** Bug 367948 has been marked as a duplicate of this bug. ***
Comment 21 Michael Rennie CLA 2012-07-23 16:02:59 EDT
*** Bug 367127 has been marked as a duplicate of this bug. ***
Comment 22 Lars Vogel CLA 2014-07-02 14:39:32 EDT
(In reply to Michael Rennie from comment #15)
> Steps to reproduce:
> 
> 1. open Java perspective or reset it
> 2. Click + drag in the editor area like you were selecting a block of text
> (but no editor is open)
> 3. grab the Package Explorer and drag it over to the editor area
> 4. drop it and immediately start another click+drag like step 2.
> 
> You will then get the NPE I pasted in comment #14

I tried this an was unable to get the NPE in Luna. Can you please retest and see if you still get this error with NPE?
Comment 23 Michael Rennie CLA 2014-07-23 12:10:03 EDT
(In reply to Lars Vogel from comment #22)
> (In reply to Michael Rennie from comment #15)
> > Steps to reproduce:
> > 
> > 1. open Java perspective or reset it
> > 2. Click + drag in the editor area like you were selecting a block of text
> > (but no editor is open)
> > 3. grab the Package Explorer and drag it over to the editor area
> > 4. drop it and immediately start another click+drag like step 2.
> > 
> > You will then get the NPE I pasted in comment #14
> 
> I tried this an was unable to get the NPE in Luna. Can you please retest and
> see if you still get this error with NPE?

I can no longer reproduce it in 4.4 or 4.5.