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

Bug 133276

Summary: [DND] DropTarget throws exceptions when being disposed of during DND operation
Product: [Eclipse Project] Platform Reporter: Florian Priester <fwp>
Component: SWTAssignee: Platform-SWT-Inbox <platform-swt-inbox>
Status: CLOSED WONTFIX QA Contact: Kevin Barnes <cocoakevin>
Severity: normal    
Priority: P3 CC: duongn, snorthov, veronika_irvine
Version: 3.2Keywords: triaged
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard: stalebug
Attachments:
Description Flags
Patch to check for dispose none

Description Florian Priester CLA 2006-03-25 16:12:03 EST
SWT-win32, v3229

When a drop target is disposed of in DropTargetListener.drop,
the following exception is thrown:

Exception in thread "main" java.lang.NullPointerException
  at org.eclipse.swt.dnd.DropTarget.refresh(DropTarget.java:545)
  at org.eclipse.swt.dnd.DropTarget.Drop(DropTarget.java:427)
  at org.eclipse.swt.dnd.DropTarget$3.method6(DropTarget.java:238)
  at org.eclipse.swt.internal.ole.win32.COMObject.callback6(COMObject.java:117)
  at org.eclipse.swt.internal.win32.OS.DispatchMessageW(Native Method)
  at org.eclipse.swt.internal.win32.OS.DispatchMessage(OS.java:1879)
  at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2964)

This is a recent regression.

---

import org.eclipse.swt.dnd.*;
import org.eclipse.swt.widgets.*;

public class DropTargetTest {
  public static void main(String[] args) {
    Display display = new Display();
    
    Shell shell = new Shell(display);
    shell.setText("Drop some text on the shell");
    
    final DropTarget target = new DropTarget(
      shell,
      DND.DROP_DEFAULT | DND.DROP_COPY);
    
    final TextTransfer transfer = TextTransfer.getInstance();
    target.setTransfer(new Transfer[] {transfer});
    
    target.addDropListener(new DropTargetAdapter() {
      public void dragEnter(DropTargetEvent event) {
        event.detail = DND.DROP_COPY;
      }
      
      public void drop(DropTargetEvent event) {
        if (transfer.isSupportedType(event.currentDataType)) {
          target.dispose();
        }
      }
    });
    
    shell.setSize(400, 400);
    shell.open();
    
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) display.sleep();
    }
    
    display.dispose();
  }
}
Comment 1 Veronika Irvine CLA 2006-03-27 12:02:57 EST
Thanks Florian - an excellent bug report as usual.

Fixed for this week's milestone build.
Comment 2 Veronika Irvine CLA 2006-03-27 12:47:41 EST
fixed
Comment 3 Florian Priester CLA 2006-03-27 15:30:18 EST
Verified with the latest SWT from CVS.

Out of curiosity, I also checked what happened when the dispose() call
is made from any of the other methods of DropTargetListener.

-dragLeave:

When the data is dropped (without leaving the target area), the following
exception occurs:

Exception in thread "main" org.eclipse.swt.SWTException: Widget is disposed
  at org.eclipse.swt.SWT.error(SWT.java:3374)
  at org.eclipse.swt.SWT.error(SWT.java:3297)
  at org.eclipse.swt.SWT.error(SWT.java:3268)
  at org.eclipse.swt.widgets.Widget.error(Widget.java:432)
  at org.eclipse.swt.widgets.Widget.checkWidget(Widget.java:327)
  at org.eclipse.swt.widgets.Widget.getStyle(Widget.java:598)
  at org.eclipse.swt.dnd.DropTarget.setEventData(DropTarget.java:585)
  at org.eclipse.swt.dnd.DropTarget.Drop(DropTarget.java:375)
  at org.eclipse.swt.dnd.DropTarget$3.method6(DropTarget.java:238)
  at org.eclipse.swt.internal.ole.win32.COMObject.callback6(COMObject.java:117)
  at org.eclipse.swt.internal.win32.OS.DispatchMessageW(Native Method)
  at org.eclipse.swt.internal.win32.OS.DispatchMessage(OS.java:1879)
  at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2964)

-dropAccept:

This results in another NPE:

Exception in thread "main" java.lang.NullPointerException
  at org.eclipse.swt.dnd.DropTarget.Drop(DropTarget.java:408)
  at org.eclipse.swt.dnd.DropTarget$3.method6(DropTarget.java:238)
  at org.eclipse.swt.internal.ole.win32.COMObject.callback6(COMObject.java:117)
  at org.eclipse.swt.internal.win32.OS.DispatchMessageW(Native Method)
  at org.eclipse.swt.internal.win32.OS.DispatchMessage(OS.java:1879)
  at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2964)

Reopening since you might want to fix these cases too.
Comment 4 John Arthorne CLA 2006-06-01 18:04:19 EDT
Clearing stale milestone.
Comment 5 Duong Nguyen CLA 2006-12-01 13:48:09 EST
Created attachment 54911 [details]
Patch to check for dispose

Steve, can you verify this patch. Thanks.
Comment 6 Leo Ufimtsev CLA 2017-08-03 12:28:14 EDT
This is a one-off bulk update. (The last one in the triage migration).

Moving bugs from swt-triaged@eclipse to platform-swt-inbox@eclipse.org and adding "triaged" keyword as per new triage process:
https://wiki.eclipse.org/SWT/Devel/Triage

See Bug 518478 for details.

Tag for notification/mail filters:
@TriageBulkUpdate
Comment 7 Eclipse Genie CLA 2020-03-08 17:03:01 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. As such, we're closing this bug.

If you have further information on the current state of the bug, please add it and reopen this bug. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.