JDK-6495530 : MouseEvent.isAltDown() returns true when middle mouse pressed
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 6
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • OS: windows_2000
  • CPU: x86
  • Submitted: 2006-11-20
  • Updated: 2011-04-29
Description
FULL PRODUCT VERSION :
java version "1.6.0-rc"
Java(TM) SE Runtime Environment (build 1.6.0-rc-b103)
Java HotSpot(TM) Client VM (build 1.6.0-rc-b103, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows 2000 [Version 5.00.2195]

A DESCRIPTION OF THE PROBLEM :
MouseEvent.isAltDown() returns true when middle mouse button is pressed

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Attach MouseListener, print result of isAltDown() when mouse button pressed. Press middle mouse button WITHOUT holding the Alt-key down. true is returned.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Method should reflect the state of the Alt-key.
ACTUAL -
Returns always true when middle button is pressed.

REPRODUCIBILITY :
This bug can be reproduced always.

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


public class Test
{
	public static void main(String ... args)
	{
		try
		{
			JFrame frame = new JFrame();
			frame.getContentPane().addMouseListener(new MouseAdapter()
			{
				public void mousePressed(MouseEvent e)
				{
					System.out.print(e.isAltDown());
				}
			});
			frame.setSize(800,600);
			frame.setVisible(true);
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
	}
}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Unknown.

Comments
EVALUATION This is a known issue. We recommend to use BUTTONx_DOWN_MASK rather then BUTTONx_MASK but don't follow this rule ourselves. BTW, similar effect could be observed with Button3 and isMetaDown() method. The spec reads: "getAltDown() : Returns whether or not the Alt modifier is down on this event." Indeed, this method shouldn't return true in that scenario. We can check getModifiersEx() rather then just "modifiers" here: public boolean isAltDown() { return (modifiers & ALT_MASK) != 0; } Furthermore, this approach might be spreaded into others (at least getMetaDown()).
20-11-2006

EVALUATION I have println'ed the mouse events sent when I press the middle mouse button, and found that the 'modifiers' field contains wrong value while 'extModifiers' is correct. The bug is easily reproduced on my WinXP Pro + SP1 desktop.
20-11-2006