JDK-4988798 : REGRESSION: Old modifiers reset when instantiating a MouseEvent
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 1.4.2
  • Priority: P3
  • Status: Closed
  • Resolution: Won't Fix
  • OS: windows_2000
  • CPU: x86
  • Submitted: 2004-02-04
  • Updated: 2006-07-17
  • Resolved: 2006-07-17
Related Reports
Relates :  
Description
Name: gm110360			Date: 02/04/2004


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

FULL OPERATING SYSTEM VERSION :
Microsoft Windows 2000 [Version 5.00.2195]
Service Pack 3

A DESCRIPTION OF THE PROBLEM :
The "old modifiers" ALT_MASK and META_MASK are reset if
combined with BUTTON1_MASK when instantiating a MouseEvent.

In this situation, the constructor of MouseEvent calls
setNewModifiers(), which resets the BUTTON2_MASK and
BUTTON3_MASK. Unfortunately these corresponds to ALT_MASK
and META_MASK.

REGRESSION.  Last worked in version 1.3.1

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Run the attached program


EXPECTED VERSUS ACTUAL BEHAVIOR :
With JDK 1.4.1, the output is:
isAltDown: false

While with JDK 1.3.1 it is:
isAltDown: true

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.awt.event.MouseEvent;
import javax.swing.JButton;

public class MouseEventTest {

  public MouseEventTest() {
    MouseEvent e = new MouseEvent(new JButton(),
                                  MouseEvent.MOUSE_PRESSED,
                                  1,
                                  MouseEvent.BUTTON1_MASK | MouseEvent.ALT_MASK,
                                  10,
                                  10,
                                  1,
                                  false);

    boolean isAltDown =
        (e.getModifiers() & MouseEvent.ALT_MASK) == MouseEvent.ALT_MASK;
    System.out.println( "isAltDown: " + isAltDown);
    System.exit(0);
  }

  public static void main(String[] args) {
    MouseEventTest mouseEventTest1 = new MouseEventTest();
  }
}
---------- END SOURCE ----------

Release Regression From : 1.3.1_10
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: 181632) 
======================================================================

Comments
WORK AROUND Use BUTTON1_DOWN_MASK here: MouseEvent e = new MouseEvent(new JButton(), MouseEvent.MOUSE_PRESSED, 1, MouseEvent.BUTTON1_MASK | MouseEvent.ALT_MASK, 10, 10, 1, false);
17-07-2006

EVALUATION MouseEvent.setNewModifiers() if ((modifiers & BUTTON1_MASK) != 0) { modifiers |= BUTTON1_DOWN_MASK; } if ((modifiers & BUTTON2_MASK) != 0) { >> modifiers |= BUTTON2_DOWN_MASK; } Here is the problem: if ALT_MASK is also mentioned in MouseEvent constructor then this method has no any chance to tract modifier value correctly. So we can not make anything here. I can imagine that changing a const value for BUTTONx_MASK and these key masks (ALT, META, SHIFT, ALT_GRAPH, CTRL) would help here. This is so indeed and using BUTTON1_DOWN_MASK instead worksarownds the problem. JavaDoc already has that recommendation.
17-07-2006

EVALUATION Name: ssR10077 Date: 02/05/2004 Due to our implementation ALT_MASK=BUTTON2_MASK so the the MOUSE_PESSED, BUTTON1_MASK + ALT_MAKS produced an invalid MouseEvent accordig to javadoc (MOUSE_PESSED should have modifiers for only one button what canged it's state). This was fixed in 1.4. But looks like users expect it to work anyway. So due to bug-to-bug compatibility we should probably make it work somehow. ======================================================================
17-09-2004