JDK-5039416 : REGRESSION: Extra mouse click dispatched after press-drag- release sequence.
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 1.4.2,5.0
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: linux,windows_xp
  • CPU: x86
  • Submitted: 2004-04-28
  • Updated: 2005-12-01
  • Resolved: 2005-05-21
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 JDK 6
5.0u5Fixed 6 b38Fixed
Related Reports
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Description
Name: rmT116609			Date: 04/28/2004


FULL PRODUCT VERSION :
java version "1.5.0-beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta-b32c)
Java HotSpot(TM) Client VM (build 1.5.0-beta-b32c, mixed mode)


ADDITIONAL OS VERSION INFORMATION :
Linux fuji 2.4.20 #2 SMP Tue May 13 19:03:46 CEST 2003 i686 unknown unknown GNU/Linux


EXTRA RELEVANT SYSTEM CONFIGURATION :
none


A DESCRIPTION OF THE PROBLEM :
A mouse click event is dispatched after a mouse press-drag-release sequence has occurred. No click event should be generated if the mouse is dragged between the press and release events.


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Compile and run the attached test case.
2. Click, drag and release the mouse in the window.


EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Mouse pressed
Mouse dragged
...
Mouse dragged
Mouse released

ACTUAL -
Mouse pressed
Mouse dragged
...
Mouse dragged
Mouse released
Mouse clicked

Note the unexpected click event at the end.


ERROR MESSAGES/STACK TRACES THAT OCCUR :
none


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class ExtraClickDemonstration extends JComponent {

	public ExtraClickDemonstration() {
		addMouseListener(new MouseAdapter() {
			public void mousePressed(MouseEvent e) {
				System.err.println("Mouse pressed");
			}
			
			public void mouseReleased(MouseEvent e) {
				System.err.println("Mouse released");
			}
			
			public void mouseClicked(MouseEvent e) {
				System.err.println("Mouse clicked");
			}
		});
		addMouseMotionListener(new MouseMotionAdapter() {
			public void mouseDragged(MouseEvent e) {
				System.err.println("Mouse dragged");
			}
		});
	}
	
	public static void main(String[] args) {
		JFrame frame = new JFrame("Extra Click Demonstration");
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.getContentPane().add(new ExtraClickDemonstration(), BorderLayout.CENTER);
		frame.setSize(new Dimension(480, 300));
		frame.setVisible(true);
	}
}

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

Release Regression From : 1.4.2_04
The above release value was the last known release where this 
bug was known to work. Since then there has been a regression.

(Incident Review ID: 260137) 
======================================================================

Comments
EVALUATION The fix affected both XAWT and Windows platform.
31-03-2006

SUGGESTED FIX *** /net/aquila/export/dav/mustang33/webrev/src/windows/native/sun/windows/awt_Component.cpp- 2005-04-28 07:13:45.000000000 -0400 *** 2488,2498 **** */ if (lastComp != this || x != lastX || y != lastY) { lastComp = this; lastX = x; lastY = y; - jint id; if ( (flags & ALL_MK_BUTTONS) != 0 ) { // 4731797 - if mouse is only dragged a short distance // (less than SM_CXDRAG/SM_CYDRAG), MOUSE_CLICKED event should be // sent on the release. --- 2488,2497 ---- *** 2502,2523 **** if (diffX > ::GetSystemMetrics(SM_CXDRAG)/2 || diffY > ::GetSystemMetrics(SM_CYDRAG)/2) { m_dragged = TRUE; } } ! id = java_awt_event_MouseEvent_MOUSE_DRAGGED; ! } else { ! id = java_awt_event_MouseEvent_MOUSE_MOVED; } ! MSG msg; InitMessage(&msg, lastMessage, flags, MAKELPARAM(x, y), x, y); ! ! SendMouseEvent(id, nowMillisUTC(), x, y, GetJavaModifiers(), 0, JNI_FALSE, java_awt_event_MouseEvent_NOBUTTON, &msg); } return mrConsume; } MsgRouting AwtComponent::WmMouseExit(UINT flags, int x, int y) --- 2501,2527 ---- if (diffX > ::GetSystemMetrics(SM_CXDRAG)/2 || diffY > ::GetSystemMetrics(SM_CYDRAG)/2) { m_dragged = TRUE; } } ! // fix for 5039416 REGRESSION: Extra mouse click dispatched after press-drag- release sequence. ! // shouldn't send DRAGGED event if mouse in the smudge area ! if (m_dragged) { ! MSG msg; ! InitMessage(&msg, lastMessage, flags, MAKELPARAM(x, y), x, y); ! SendMouseEvent(java_awt_event_MouseEvent_MOUSE_DRAGGED, nowMillisUTC(), x, y, ! GetJavaModifiers(), 0, JNI_FALSE, ! java_awt_event_MouseEvent_NOBUTTON, &msg); } ! } else { MSG msg; InitMessage(&msg, lastMessage, flags, MAKELPARAM(x, y), x, y); ! SendMouseEvent(java_awt_event_MouseEvent_MOUSE_MOVED, nowMillisUTC(), x, y, GetJavaModifiers(), 0, JNI_FALSE, java_awt_event_MouseEvent_NOBUTTON, &msg); } + } return mrConsume; } MsgRouting AwtComponent::WmMouseExit(UINT flags, int x, int y) *** /net/aquila/export/dav/mustang33/webrev/src/solaris/classes/sun/awt/X11/XWindow.java- 2005-04-28 07:13:45.000000000 -0400 *** 695,711 **** if (xme.get_window() != window) { Point localXY = toLocal(xme.get_x_root(), xme.get_y_root()); x = localXY.x; y = localXY.y; } ! MouseEvent mme = new MouseEvent(source, type, jWhen, modifiers, x, y, xme.get_x_root(), xme.get_y_root(), clickCount, popupTrigger, MouseEvent.NOBUTTON); - postEventToEventQueue(mme); } // REMIND: need to implement looking for disabled events public native int nativeHandleKeyEvent(Component target,int keyid,long ptr); public native int nativeGetKeyCode(Component target,int keyid,long ptr); --- 695,714 ---- if (xme.get_window() != window) { Point localXY = toLocal(xme.get_x_root(), xme.get_y_root()); x = localXY.x; y = localXY.y; } ! /* Fix for 5039416. ! * According to canvas.c we shouldn't post any MouseEvent if mouse is dragging and clickCount!=0. ! */ ! if ((dragging && clickCount == 0) || !dragging){ MouseEvent mme = new MouseEvent(source, type, jWhen, modifiers, x, y, xme.get_x_root(), xme.get_y_root(), clickCount, popupTrigger, MouseEvent.NOBUTTON); postEventToEventQueue(mme); } + } // REMIND: need to implement looking for disabled events public native int nativeHandleKeyEvent(Component target,int keyid,long ptr); public native int nativeGetKeyCode(Component target,int keyid,long ptr); ###@###.### 2005-04-29 06:49:31 GMT
06-04-2005

EVALUATION Name: osR10079 Date: 04/28/2004 This is XAWT specific problem. ###@###.### 2004-04-29 ====================================================================== Name: osR10079 Date: 04/28/2004 The cause of the problem is in XWindow.java file. We generate MOUSE_CLICKED on ButtonRelease if lastWindowRef references to the same component as "this". But we do not clear lastWindowRef on MotionNotify for some reason. ###@###.### 2004-04-29 ====================================================================== AWT_MULTICLICK_SMUDGE might be an appropriate item to use in this case. According to Motif's implementation ( canvas.c ) we assign NULL to lastPeer when mouse being dragged. Seems that this is already fixed in Mustang b24. (6176814) ###@###.### 2005-2-15 16:12:53 GMT This buggy behaviour already fixed in 6176814. Going to open a SubCR. ###@###.### 2005-2-22 12:42:12 GMT The fix for this bug is not delivered into JDK5.0_01 yet. It will appear in JDK5.0_04. ###@###.### 2005-03-09 09:00:41 GMT Careful analysis shows that XAWT posts MouseEvent always but Motif in some cases doesn't post event at all. I mean MouseMoved/MouseDragged events only. This is because in XAWT if-statement (!clickCount) missed for some reasons. ###@###.### 2005-04-06 12:05:13 GMT This fix is on its way to JDK1.5.0_05 - expect it soon. ###@###.### 2005-06-17 07:56:28 GMT
06-04-2005

WORK AROUND Force the use of Motif toolkit instead of XAWT: by either providing this parameter during startup: -Dawt.toolkit=sun.awt.motif.MToolkit or by setting the following env. variable: AWT_TOOLKIT=MToolkit ###@###.### 2005-2-10 22:33:13 GMT
10-02-2005