JDK-8269283 : Drag and drop file to TextComponent times, it would block to die
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 8u291,16
  • Priority: P3
  • Status: Open
  • Resolution: Unresolved
  • OS: windows_10
  • CPU: x86_64
  • Submitted: 2021-06-16
  • Updated: 2023-08-24
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
tbdUnresolved
Related Reports
Relates :  
Description
ADDITIONAL SYSTEM INFORMATION :
Windows 10
java version "1.8.0_291"
Java(TM) SE Runtime Environment (build 1.8.0_291-b10)
Java HotSpot(TM) 64-Bit Server VM (build 25.291-b10, mixed mode)

A DESCRIPTION OF THE PROBLEM :
On Windows 10 with chinese ime(I am not sure other language versions have same question), Drag and drop file to TextComponent, about 5-10 times, the whole java app would block to die.

REGRESSION : Last worked in version 8

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1, Startup Test Code.
2, Drag a file to yellow area and drop. The file name would add to yellow area.
3, Repeatly for 10 times. 
If the bug not ocurred, then exit app and restart again.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Drap and drop works OK, and the file name always add to yellow area.
ACTUAL -
Some times the whole app would blocked, And you can do nothing but kill it.

---------- BEGIN SOURCE ----------
package taishan;

import java.awt.Color;
import java.awt.datatransfer.DataFlavor;
import java.awt.dnd.DropTarget;
import java.awt.dnd.DropTargetDropEvent;

import javax.swing.JEditorPane;
import javax.swing.JFrame;

@SuppressWarnings("serial")
public class DndTest extends JEditorPane
{
    
	private static DndTest mEditor;
	
    public DndTest()
    {
    	this.setBackground(Color.YELLOW);
    }
    
    public static class DragDropListener extends DropTarget
    {
        public DragDropListener(java.awt.Component component)
        {
            super();
            setComponent(component);
        }

        @Override
        public void dragEnter(java.awt.dnd.DropTargetDragEvent dtde)
        {
        	//System.out.println("dragEnter()");
            super.dragEnter(dtde);
        }

        @Override
        public synchronized void dragOver(java.awt.dnd.DropTargetDragEvent dtde)
        {
            //System.out.println("dragOver()");
        }

        @Override
        public void dragExit(java.awt.dnd.DropTargetEvent event)
        {
        }

        @Override
        public void drop(DropTargetDropEvent e)
        {
        	//System.out.println("drop()");
            e.acceptDrop(e.getDropAction());
            DataFlavor[] flavors = e.getTransferable().getTransferDataFlavors();
            for (DataFlavor flavor : flavors)
            {
            	if (flavor.equals(DataFlavor.javaFileListFlavor))
            	{
            		try
            		{
            			mEditor.setText(
            					mEditor.getText()
            					+ "\n"
            				    + e.getTransferable().getTransferData(flavor));
            		}
            		catch (Exception excep)
            		{
            			excep.printStackTrace();
            		}
                    break;
            	}
            }
            
            e.dropComplete(false);
            return;
            //e.rejectDrop();
        }

    }
        
        
        
    public static void main(String[] args)
    {
        JFrame frame = new JFrame();
        frame.setSize(800, 500);

        mEditor = new DndTest();
        mEditor.setText("Taishan Office");
        new DndTest.DragDropListener(mEditor);
        
        frame.getContentPane().add(mEditor);
        
        frame.setVisible(true);
        
    }
    
}

---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
I have found two solutions for this bug.
1, awt_InputMethod.cpp Java_sun_awt_windows_WInputMethod_openCandidateWindow():
comment the InvokeInputMethodFunction()
2, awt_Toolkit.cpp InvokeInputMethodFunction:
modify it like this:
::WaitForSingleObject(m_inputMethodWaitEvent,
                msg == WM_AWT_OPENCANDIDATEWINDOW ? 10 : INFINITE);

FREQUENCY : occasionally



Comments
Follow-up mail sent to the submitter: Please confirm if the issue is reproduced using: 1) JDK 16 and 2) Early access builds of JDK 17 https://www.oracle.com/java/technologies/javase-jdk16-downloads.html https://jdk.java.net/17/ https://jdk.java.net/16/
20-07-2021

response from the submitter: This is my test result: 1, JDK 16.0.1, has this bug. 2, openjdk 17-ea+29, has this bug. 3, JDK 8u291, has this bug. 4, JDK 8u281, NO THIS BUG. Yes, this bug is reproduced with 8u291. This is my work: blocked at jdk\src\windows\native\sun\windows\awt_Toolkit.cpp LRESULT AwtToolkit::InvokeInputMethodFunction(UINT msg, WPARAM wParam, LPARAM lParam). called by jdk\src\windows\native\sun\windows\awt_InputMethod.cpp JNIEXPORT void JNICALL Java_sun_awt_windows_WInputMethod_openCandidateWindow (JNIEnv *env, jobject self, jobject peer, jint x, jint y) InvokeInputMethodFunction was modified at 8u291. Many thanks for your works. ===========
20-07-2021

could be duplicate/ similar issue: JDK-8262446- DragAndDrop hangs on Windows
29-06-2021

Additional Information from submitter: =========================== Drag and drop about 10 times. If the bug doesn't occur, you should kill(close) the process and restart it. Then it would occur. I want to post the screenshot, but can't find a entry. 1. OS is Chinese windows, and has a Chinese input method. 2. Drop for 10 times. If not occurred, kill the process and restart, then repeat. On my environment, it would occurred.
28-06-2021

Requested additional information from the submitter: --------------- This is regarding the above mentioned Java Incident reported. We could not reproduce the issue using JDK 8u291 and the test case provided. We have tried to drag and drop file to TextComponent, more than 10 times, the whole java app didn’t get blocked. Attached the screen shot for your reference.
24-06-2021