JDK-6855323 : Robot(GraphicsDevice) constructor initializes LEGAL_BUTTON_MASK variable improperly
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 7
  • Priority: P2
  • Status: Closed
  • Resolution: Fixed
  • OS: generic,linux_redhat_5.0
  • CPU: generic
  • Submitted: 2009-06-26
  • Updated: 2011-03-07
  • Resolved: 2011-03-07
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
7 b66Fixed
Related Reports
Duplicate :  
Duplicate :  
Relates :  
Description
AWT Robot has two constructors that initialize instance differently. Robot(GraphicsDevice) constructor does not invoke default constructor implementation and by this reason  misses initialization of  LEGAL_BUTTON_MASK variable.

Improper initialization of  LEGAL_BUTTON_MASK could bring to an exception.

Exception in thread "main" java.lang.IllegalArgumentException: Invalid combination of button flags
	at java.awt.Robot.checkButtonsArgument(Robot.java:325)
	at java.awt.Robot.mousePress(Robot.java:257)
	at FileListBetweenJVMsTest.<init>(FileListBetweenJVMsTest.java:119)
	at FileListBetweenJVMsTest.main(FileListBetweenJVMsTest.java:150)

The exception is caused by the fact that  LEGAL_BUTTON_MASK value is 0.

Comments
SUGGESTED FIX http://sa.sfbay.sun.com/projects/awt_data/7/6855323
08-07-2009

EVALUATION Regression introduced in changeset 491 with the fix for CR 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons That time LEGAL_BUTTON_MASK has moved from static-initializer to CTOR so in case of using new Robot(myGrEnv) we have LEGAL_BUTTON_MASK unassigned (i.e. == zero) which in turn causes every event to get rejected as non-valid. @@ -98,6 +95,19 @@ public class Robot { } init(GraphicsEnvironment.getLocalGraphicsEnvironment() .getDefaultScreenDevice()); + int tmpMask = 0; + if (Toolkit.getDefaultToolkit().areExtraMouseButtonsEnabled()){ + for (int i = 0; i < peer.getNumberOfButtons(); i++){ + tmpMask |= InputEvent.getMaskForButton(i+1); + } + } + tmpMask |= InputEvent.BUTTON1_MASK| + InputEvent.BUTTON2_MASK| + InputEvent.BUTTON3_MASK| + InputEvent.BUTTON1_DOWN_MASK| + InputEvent.BUTTON2_DOWN_MASK| + InputEvent.BUTTON3_DOWN_MASK; + LEGAL_BUTTON_MASK = tmpMask; }
26-06-2009