JDK-4379922 : Component.processKeyEvent is not called by event dispatch thread
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 1.4.0
  • Priority: P2
  • Status: Resolved
  • Resolution: Fixed
  • OS: solaris_2.6
  • CPU: sparc
  • Submitted: 2000-10-17
  • Updated: 2017-05-16
  • Resolved: 2004-09-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
5.0 b28Fixed
Related Reports
Relates :  
Relates :  
Relates :  
Description
Name: dsR10051			Date: 10/17/2000



The method 
protected void java.awt.Component.processKeyEvent(KeyEvent e)
is not called by event dispatch thread even if a KeyListener 
object is registered via addKeyListener 
(See JavaDoc for Component.processKeyEvent).

Here is a minimized test:
import java.awt.*;
import java.awt.event.*;

public class ComponentTest5 {
    public static void main (String[] args) {
        EventQueue eq = Toolkit.getDefaultToolkit().getSystemEventQueue();
        ChildComponent chcomponent = new ChildComponent();
        KeyEvent e = new KeyEvent(chcomponent, KeyEvent.KEY_RELEASED, (long)0, 0, KeyEvent.VK_UNDEFINED);
        DummyKeyListener cl = new DummyKeyListener();
        chcomponent.addKeyListener(cl);

        eq.postEvent(e);
        synchronized (chcomponent) {
            while(!chcomponent.keyEventProcessed) {
                try {
                    System.out.println("Waiting");
                    System.out.flush();

                    chcomponent.wait();

                    System.out.println("Waiting");
                    System.out.flush();
                } catch (InterruptedException ie) {
                    ie.printStackTrace();
                }
            }
        }
        System.exit(0);
    }
}

class ChildComponent extends Component {
    public ChildComponent() {
        super();
    }

    boolean keyEventProcessed = false;
    public synchronized void processKeyEvent(KeyEvent e) {
        keyEventProcessed = true;
        System.out.println("processKeyEvent called");
        System.out.flush();
        super.processKeyEvent(e);
        System.out.println("processKeyEvent done");
        System.out.flush();
        notifyAll();
    }
}

class DummyKeyListener extends KeyAdapter {
}

--- Output ---
%/net/sword/export3/JDK1.4.0beta-b36/solaris/bin/java -version
java version "1.4.0beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0beta-b36)
Java HotSpot(TM) Client VM (build 1.4beta-B36, mixed mode)
%/net/sword/export3/JDK1.4.0beta-b36/solaris/bin/java ComponentTest5      
Waiting
^C
%

======================================================================

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: tiger FIXED IN: tiger-beta INTEGRATED IN: tiger-b28 tiger-beta VERIFIED IN: 1.5.0_01
25-09-2004

EVALUATION Commit to fix in Merlin (JCK failure). eric.hawkes@eng 2000-11-13 See 4292099 for a related issue. eric.hawkes@eng 2001-05-05 See also 4379917. ###@###.### 2003-08-14 Name: osR10079 Date: 10/16/2003 Here is a new javadoc for processkeyEvent() : /** * Processes key events occurring on this component by * dispatching them to any registered * <code>KeyListener</code> objects. * <p> * This method is not called unless key events are * enabled for this component. Key events are enabled * when one of the following occurs: * <p><ul> * <li>A <code>KeyListener</code> object is registered * via <code>addKeyListener</code>. * <li>Key events are enabled via <code>enableEvents</code>. * </ul> * ! * <p> ! * If key events are enabled for a <code>Component</code>, ! * the current <code>KeyboardFocusManager</code> determines ! * whether or not a key event should be dispatched to ! * registered <code>KeyListener</code> objects. The ! * <code>DefaultKeyboardFocusManager</code> will not dispatch ! * key events to a <code>Component</code> that is not the focus ! * owner or is not showing. ! * <p> ! * As of J2SE 1.4, <code>KeyEvent</code>s are redirected to ! * the focus owner. Please see the ! * <a href="doc-files/FocusSpec.html">Focus Specification</a> ! * for further information. ! * <p> ! * Calling a <code>Component</code>'s <code>dispatchEvent</code> ! * method with a <code>KeyEvent</code> as the argument will ! * result in a call to the <code>Component</code>'s ! * <code>processKeyEvent</code> method regardless of the ! * current <code>KeyboardFocusManager</code> as long as the ! * component is showing, focused, and enabled, and key events ! * are enabled on it. * <p> * If the event parameter is <code>null</code> * the behavior is unspecified and may result in an * exception. * * @param e the key event * @see java.awt.event.KeyEvent * @see java.awt.event.KeyListener + * @see java.awt.KeyboardFocusManager + * @see java.awt.DefaultKeyboardFocusManager + * @see #processEvent + * @see #dispatchEvent * @see #addKeyListener * @see #enableEvents * @see #isShowing * @since JDK1.1 */ protected void processKeyEvent(KeyEvent e); ###@###.### 2003-10-17 ======================================================================
17-10-2003