JDK-4343300 : Drag and Drop generates EXCEPTION_ACCESS_VIOLATION
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 1.3.0
  • Priority: P2
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_nt
  • CPU: x86
  • Submitted: 2000-06-05
  • Updated: 2000-10-11
  • Resolved: 2000-09-19
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other Other
1.3.1 ladybirdFixed 1.4.0Fixed
Related Reports
Relates :  
Relates :  
Description

Name: rlT66838			Date: 06/05/2000


java version "1.3.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)

jre 1.3 produces the following error

#
# An EXCEPTION_ACCESS_VIOLATION exception has been detected in native code
outside the VM.
# Program counter=0x5006cecd
#

and jre1.3.0rc1 (distributed with Netscape 6 PR1) produces this error

#
# HotSpot Virtual Machine Error, EXCEPTION_ACCESS_VIOLATION
#
# Error ID: 4F533F57494E13120E43505002BE
#

abnormal program termination

It is generated by this line:
e.startDrag(new Cursor(Cursor.HAND_CURSOR), transferable, sourceHandler);

near the end of this Java program, the DragNDrop application in chapter 16 of
Sams Java 2 Platform Unleashed (a fairly popular book):

import java.awt.*;
import java.awt.event.*;
import java.awt.dnd.*;
import java.awt.datatransfer.*;
import java.io.*;

public class DragNDrop extends Frame {
	int screenWidth = 400;
	int screenHeight = 400;
	Panel panel = new Panel();
	Label topLabel = new Label("Enter text in this text area:");
	Label bottomLabel = new Label("And then drag it to this text area:");
	TextArea textArea1 = new TextArea();
	TextArea textArea2 = new TextArea();

	// Drag and drop variables
	DragSource source = new DragSource();
	DropTarget target = new DropTarget(textArea2, DnDConstants.ACTION_COPY, new DropTargetHandler(), true);
	TextTransfer transferable = new TextTransfer();
	DragSourceHandler sourceHandler = new DragSourceHandler();

	public static void main(String args[]) {
		DragNDrop app = new DragNDrop();
	}

	public DragNDrop() {
		super("DragNDrop");
		setup();
		setSize(screenWidth, screenHeight);
		addWindowListener(new WindowEventHandler());
		show();
	}

	void setup() {
		target.setActive(true);
		panel.setLayout(new GridLayout(4, 1));
		panel.add(topLabel);
		panel.add(textArea1);
		Toolkit toolkit = Toolkit.getDefaultToolkit();
		try {
		toolkit.createDragGestureRecognizer(Class.forName("java.awt.dnd.MouseDragGesture Recognizer"),
				source, textArea1, DnDConstants.ACTION_COPY, new DragHandler());
		}
		catch (ClassNotFoundException ex) {
			System.out.println("Recognizer class not found.");
			System.exit(0);
		}
		panel.add(bottomLabel);
		panel.add(textArea2);
		add("Center", panel);
	}

	class DragSourceHandler implements DragSourceListener {
		public void dropActionChanged(DragSourceDragEvent ev) {
			System.out.println("Source: Drop action changed");
		}

		public void dragEnter(DragSourceDragEvent ev) {
			System.out.println("Source: Drag enter");
		}

		public void dragOver(DragSourceDragEvent ev) {
		}

		public void dragExit(DragSourceEvent ev) {
			System.out.println("Source: Drag exit");
		}

		public void dragDropEnd(DragSourceDropEvent ev) {
			System.out.println("Source: Drag drop end");
		}
	}

	class DropTargetHandler implements DropTargetListener {
		public void dragEnter(DropTargetDragEvent ev) {
			System.out.println("Target: Drag enter");
			DataFlavor df[] = ev.getCurrentDataFlavors();
			for (int i = 0; i < df.length; i++) {
				if (df[i].equals(DataFlavor.plainTextFlavor) ||
					df[i].equals(DataFlavor.stringFlavor)) {
					ev.acceptDrag(DnDConstants.ACTION_COPY);
					return;
				}
			}
			ev.rejectDrag();
		}

		public void dragOver(DropTargetDragEvent ev) {
		}

		public void dragExit(DropTargetEvent ev) {
			System.out.println("Target: Drag exit");
		}

		public void dropActionChanged(DropTargetDragEvent ev) {
			System.out.println("Target: Drop action changed");
		}

		public void drop(DropTargetDropEvent ev) {
			System.out.println("Target: Dropped");
			ev.acceptDrop(DnDConstants.ACTION_COPY);
			Transferable transfer = ev.getTransferable();
			DataFlavor df[] = ev.getCurrentDataFlavors();
			String input = "";
			try {
				for (int i = 0; i < df.length; i++) {
					if (df[i].equals(DataFlavor.stringFlavor) ||
					df[i].equals(DataFlavor.plainTextFlavor)) {
						input = (String) transfer.getTransferData(df[i]);
					}
				}
				textArea2.setText(input);
			}
			catch (Exception e) {
				System.out.println(e.toString());
			}
			try {
			        target.getDropTargetContext().dropComplete(true);
			}
			catch (Exception e) {
			}
		}
	}

	class TextTransfer implements Transferable {
		public DataFlavor[] getTransferDataFlavors() {
			DataFlavor flavors[] = new DataFlavor[1];
			flavors[0] = DataFlavor.plainTextFlavor;
			return flavors;
		}

		public boolean isDataFlavorSupported(DataFlavor flavor) {
			return (flavor.equals(DataFlavor.plainTextFlavor));
		}

		public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
			return textArea1.getText();
		}
	}

	class DragHandler implements DragGestureListener {
		public void dragGestureRecognized(DragGestureEvent e) {
			e.startDrag(new Cursor(Cursor.HAND_CURSOR), transferable, sourceHandler);
		}
	}

	class WindowEventHandler extends WindowAdapter {
		public void windowClosing(WindowEvent e) {
			System.exit(0);
		}
	}
}


(Review ID: 105662) 
======================================================================

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: ladybird merlin-beta FIXED IN: ladybird merlin-beta INTEGRATED IN: ladybird merlin-beta
14-06-2004

EVALUATION Works fine on Windows 1.2.2 and Solaris 1.3. On Windows 1.3 and merlin-25, the crash occurs as reported in the description. On Solaris merlin-25, the cursor does not change to a hand as it should. This regression was probably introduced by the kestrel cursor rewrite. david.mendenhall@eng 2000-08-01 Name: dsR10078 Date: 09/09/2000 ###@###.### The test crashes since we don't check if the underlying win32 cursor is created when setting a new cursor for a DragSource. On Solaris the cursor doesn't change to hand cursor, since Motif text area has a drop site registered by Motif. When the mouse is over a drop site the cursor is changhed to the default value. This is according to the javadoc, since the cursor passed to the DragGestureEvent.startDrag() is only the initial cursor. And if a customer doesn't want the cursor to change to the default value he should update it in dragOver() and dropActionChanged() upcalls. ======================================================================
11-06-2004

WORK AROUND Name: rlT66838 Date: 06/05/2000 I can comment the line of code in question and eliminate the error, but then drag and drop is disabled in the application. The point of the app is to demonstrate drag and drop's capability. ======================================================================
11-06-2004

SUGGESTED FIX Name: dsR10078 Date: 09/09/2000 ###@###.### Create the underlying win32 cursor if it doesn't exist when setting a new cursor for a DragSource. --- awt_DnDDS.cpp Thu Sep 7 20:44:58 2000 *************** *** 363,368 **** --- 363,372 ---- jlong pData = env->GetLongField(cursor, AwtCursor::pDataID); m_cursor = (AwtCursor *)jlong_to_ptr(pData); + if (m_cursor == NULL) { + m_cursor = AwtCursor::CreateSystemCursor(cursor); + } + if( TRUE == m_cursor->IsCustomCursor() ) { AwtToolkit::GetInstance().NotifyCustomCursor(); } else { ======================================================================
11-06-2004