JDK-4379917 : Component.processFocusEvent 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: 2004-09-24
  • 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 :  
Description
Name: dsR10051			Date: 10/17/2000



The method 
protected void java.awt.Component.processFocusEvent(FocusEvent e)
is not called by event dispatch thread even if a FocusListener 
object is registered via addFocusListener 
(See JavaDoc for Component.processFocusEvent).

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

public class ComponentTest4 {
    public static void main (String[] args) {
        EventQueue eq = Toolkit.getDefaultToolkit().getSystemEventQueue();
        ChildComponent chcomponent = new ChildComponent();
        FocusEvent e = new FocusEvent(chcomponent, FocusEvent.FOCUS_LOST);
        DummyFocusListener cl = new DummyFocusListener();
        chcomponent.addFocusListener(cl);

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

                    chcomponent.wait();

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

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

    boolean focusEventProcessed = false;
    public synchronized void processFocusEvent(FocusEvent e) {
        focusEventProcessed = true;
        System.out.println("processFocusEvent called");
        System.out.flush();
        super.processFocusEvent(e);
        System.out.println("processFocusEvent done");
        System.out.flush();
        notifyAll();
    }
}

class DummyFocusListener extends FocusAdapter {
}

--- 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 ComponentTest4
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 The focus specification states that a Focus Lost event will not occur on a component which is not the focus owner. This program sends a synthetic Focus Lost event to a component other than the focus owner. The focus implementation retargets such events to be sent to the focus owner; therefore, the components that was originally targeted by the generated event never receives it. This is correct behavior in accordane with the focus specification. hania.gajewska@Eng 2000-12-03 We haven't found any place where API specification says explicitly that "Focus Lost event will not occur on a component which is not the focus owner". If this statement is correct, please add the corresponding clarification to the Component.processFocusEvent() method description. Otherwise, if the current javadoc is left as is, namely: --------------- Processes focus events occurring on this component by dispatching them to any registered FocusListener objects. This method is not called unless focus events are enabled for this component. Focus events are enabled when one of the following occurs: A FocusListener object is registered via addFocusListener. Focus events are enabled via enableEvents. --------------- then one would conclude from this spec that all focus events should be successfully processed regardless of focus state of a component, so we would still believe that this is a contradiction between implementation and the spec. Reopening this as specification bug. ###@###.### 2001-01-19 ------------ Name: osR10079 Date: 10/16/2003 Here is a new javadoc for processFocusEvent() (part of CCC-request for 4379922): /** * Processes focus events occurring on this component by * dispatching them to any registered * <code>FocusListener</code> objects. * <p> * This method is not called unless focus events are * enabled for this component. Focus events are enabled * when one of the following occurs: * <p><ul> * <li>A <code>FocusListener</code> object is registered * via <code>addFocusListener</code>. * <li>Focus events are enabled via <code>enableEvents</code>. * </ul> ! * <p> ! * If focus events are enabled for a <code>Component</code>, ! * the current <code>KeyboardFocusManager</code> determines ! * whether or not a focus event should be dispatched to ! * registered <code>FocusListener</code> objects. If the ! * events are to be dispatched, the <code>KeyboardFocusManager</code> ! * calls the <code>Component</code>'s <code>dispatchEvent</code> ! * method, which results in a call to the <code>Component</code>'s ! * <code>processFocusEvent</code> method. ! * <p> ! * If focus events are enabled for a <code>Component</code>, calling ! * the <code>Component</code>'s <code>dispatchEvent</code> method ! * with a <code>FocusEvent</code> as the argument will result in a ! * call to the <code>Component</code>'s <code>processFocusEvent</code> ! * method regardless of the current <code>KeyboardFocusManager</code>. ! * <p> * Note that if the event parameter is <code>null</code> * the behavior is unspecified and may result in an * exception. * * @param e the focus event * @see java.awt.event.FocusEvent * @see java.awt.event.FocusListener + * @see java.awt.KeyboardFocusManager * @see #addFocusListener * @see #enableEvents + * @see #dispatchEvent * @since JDK1.1 */ protected void processFocusEvent(FocusEvent e); ###@###.### 2003-10-17 ======================================================================
17-10-2003