United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-4379922 Component.processKeyEvent is not called by event dispatch thread
JDK-4379922 : Component.processKeyEvent is not called by event dispatch thread

Details
Type:
Bug
Submit Date:
2000-10-17
Status:
Resolved
Updated Date:
2004-09-24
Project Name:
JDK
Resolved Date:
2004-09-24
Component:
client-libs
OS:
solaris_2.6
Sub-Component:
java.awt
CPU:
sparc
Priority:
P2
Resolution:
Fixed
Affected Versions:
1.4.0
Fixed Versions:
5.0 (b28)

Related Reports
Relates:
Relates:
Relates:

Sub Tasks

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
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

======================================================================
                                     
2003-10-17
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


                                     
2004-09-25



Hardware and Software, Engineered to Work Together