JDK-7049024 : DnD fails with JTextArea and JTextField
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 7,8
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS: generic,linux_ubuntu
  • CPU: generic,x86
  • Submitted: 2011-05-27
  • Updated: 2013-09-12
  • Resolved: 2011-11-16
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.
JDK 7 JDK 8
7u40Fixed 8 b14Fixed
Description
FULL PRODUCT VERSION :

The problem exists on latest jdk. For now, the internal java8 build is still breaking the testcase.

openjdk version "1.8.0-internal"
OpenJDK Runtime Environment (build 1.8.0-internal-zhouyx_2011_08_01_11_00-b00)
OpenJDK Client VM (build 21.0-b14, mixed mode)

It is first reported on Java7 b142,  and I can see the problem exists on java6 as well.


ADDITIONAL OS VERSION INFORMATION :
Linux  2.6.38-8-generic #42-Ubuntu SMP i686 i386 GNU/Linux


A DESCRIPTION OF THE PROBLEM :
    I have a testcase related to DnD failure with JTextArea and JTextField on linux. The
testcase is as follows:

/*
 * DnDTest.java
 */
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JTextArea;
import javax.swing.JTextField;


public class DnDTest extends Frame {
	Component c;
	public DnDTest() {
		super("Single Frame --- AWT Frame");
		super.setBackground(Color.gray);
		
		// set layout here.
		setLayout(new FlowLayout());
		
		c = new JTextArea("JTextArea component");
		c.setPreferredSize(new Dimension(400, 100));
		add(c);
		
		c = new JTextField("JTextField component(No IM)");
		c.setPreferredSize(new Dimension(400, 20));
		add(c);
		
		addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent event) {
				System.exit(0);
			}
		});
		setSize(850, 360);
		setVisible(true);
	}
	
	public static void main(String[] args) {
		new DnDTest();
	}
}


Reproduce steps:
1. Run the testcase
2. Open a new file with gedit and input some words like "abcde"
3. Drag "abcde" into JTextField and drop it there.
4. Once more, drag "abcde" into JTextField and then move out of the Frame (keep draging) and drag into JTextField again and drop it.

Expectation:
The second DnD inputs another "abcde" into JTextField.

Result:
The second DnD inputs nothing into JTextField.

Investigation:
The JTextArea as well has this problem, and in step 4, if we drag "abcde" over JTextField and then drop into JTextArea, nothing
is input into JTextArea either. However, if "abcde" is drag into JTextField or JTextArea directly or when JTextArea/Field are
empty as in step 2, it works.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Run the testcase with b143
2. Open a new file with gedit and input some words like "abcde"
3. Drag "abcde" into JTextField and drop it there.
4. Once more, drag "abcde" into JTextField and then move out of the Frame (keep draging) and drag into JTextField again and drop it

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The second DnD inputs another "abcde" into JTextField.
ACTUAL -
The second DnD inputs nothing into JTextField.

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
/*
 * DnDTest.java
 */
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JTextArea;
import javax.swing.JTextField;


public class DnDTest extends Frame {
	Component c;
	public DnDTest() {
		super("Single Frame --- AWT Frame");
		super.setBackground(Color.gray);
		
		// set layout here.
		setLayout(new FlowLayout());
		
		c = new JTextArea("JTextArea component");
		c.setPreferredSize(new Dimension(400, 100));
		add(c);
		
		c = new JTextField("JTextField component(No IM)");
		c.setPreferredSize(new Dimension(400, 20));
		add(c);
		
		addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent event) {
				System.exit(0);
			}
		});
		setSize(850, 360);
		setVisible(true);
	}
	
	public static void main(String[] args) {
		new DnDTest();
	}
}
---------- END SOURCE ----------
Additional details from the submitter:

I haven't tested it with earlier version of JDK6. According to the investigation I did when I tried to fix it, I think
it never worked on JDK6.

The problem seems to be like this: dragExit calls setDropLocation and give an argument meaning "this
is not a real drop". While the call tree goes down, the information is lost, and updateSystemSelection treat
it as a real drop and updated something, and the string which is not dropped is cleared.

Comments
EVALUATION Sent mail to the submitter to find out what release (including build number) that they were using. Selecting the value in the pulldown is useful to get the report the the right area, but not knowing the output of 'java -version' makes it hard to know where the test is really failing. Is it build 5 of JDK7?
31-05-2011