JDK-4867453 : Component.removeNotify() should always deactivate InputContext
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 1.4.0,1.4.2,1.4.2_07
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_nt,windows_2000,windows_xp
  • CPU: x86
  • Submitted: 2003-05-21
  • Updated: 2003-07-25
  • Resolved: 2003-07-25
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
1.4.2_10Fixed
Related Reports
Duplicate :  
Relates :  
Description

Name: rpR10076			Date: 05/21/2003


Previously similar problem was described in bug
4289940 : (P4/S4) - Can't dispose InputContext while it's active
However, the reliable way to reproduce 4289940 was through
Forte4Java, which contained a bug.
That's why the problem in AWT code wasn't noticed.
However, the simple applet like the one below reproduces the
exception in appletviewer (this was submitted on the jdc some
time ago, thanks for that).

===
public class TestApplet extends java.applet.Applet {
    private int dir;
    public void start() {
        enableEvents(java.awt.AWTEvent.KEY_EVENT_MASK);
    }
    public void stop() {
        disableEvents(java.awt.AWTEvent.KEY_EVENT_MASK);
        System.out.println("stop");
    }
    public void destroy() {
        System.out.println("destroy");
    }
    protected void processEvent(java.awt.AWTEvent e) {
        if (e.getID() == java.awt.event.KeyEvent.KEY_TYPED) {
            ++dir;
            repaint();
        }
        super.processEvent(e);
    }
    public void paint(java.awt.Graphics g) {
        java.awt.Dimension d = getSize();
        int n = d.width * (dir & 3) / 3;
        g.drawLine(n, 0, d.width - n, d.height);
    }
}
===

To reproduce the bug, load this applet in the appletviewer
click on it, press space several times, and try to exit by
closing the appletviewer window. I reproduced it on Windows.
An exception like this will appear:

Exception during disposal:
java.lang.reflect.InvocationTargetException
        at java.awt.EventQueue.invokeAndWait(EventQueue.java:834)
        at java.awt.Window.dispose(Window.java:574)
        at sun.applet.AppletViewer$3.run(AppletViewer.java:821)
        at java.lang.Thread.run(Thread.java:534)
Caused by: java.lang.IllegalStateException: Can't dispose InputContext while it's active
        at sun.awt.im.InputContext.dispose(InputContext.java:601)
        at java.awt.Window$1DisposeAction.run(Window.java:560)
        at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:171)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:454)
        at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:208)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:157)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:151)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:143)
        at java.awt.EventDispatchThread.run(EventDispatchThread.java:104)

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

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: tiger FIXED IN: tiger INTEGRATED IN: tiger tiger-b13
14-06-2004

EVALUATION Commit to fix in Tiger. ###@###.### 2003-05-21 Name: rpR10076 Date: 07/03/2003 If the use disables key events after input methods are already activated, our check in Component.areInputMethodsEnabled() will fail. Need to check just of INPUT_METHODS_ENABLED_MASK. Similar issue with enableInputMethods(boolean). See Suggested fix for diffs. ======================================================================
11-06-2004

SUGGESTED FIX Name: rpR10076 Date: 07/03/2003 ------- Component.java ------- *** /tmp/sccs.eLaa.r Thu Jul 3 16:18:37 2003 --- Component.java Thu Jul 3 14:38:45 2003 *************** *** 1068,1074 **** eventMask |= AWTEvent.INPUT_METHODS_ENABLED_MASK; } else { ! if (areInputMethodsEnabled()) { InputContext inputContext = getInputContext(); if (inputContext != null) { inputContext.endComposition(); --- 1152,1158 ---- eventMask |= AWTEvent.INPUT_METHODS_ENABLED_MASK; } else { ! if ((eventMask & AWTEvent.INPUT_METHODS_ENABLED_MASK) != 0) { InputContext inputContext = getInputContext(); if (inputContext != null) { inputContext.endComposition(); *************** *** 5546,5552 **** // If there is any input context for this component, notify // that this component is being removed. (This has to be done // before hiding peer.) ! if (areInputMethodsEnabled()) { InputContext inputContext = getInputContext(); if (inputContext != null) { inputContext.removeNotify(this); --- 5630,5636 ---- // If there is any input context for this component, notify // that this component is being removed. (This has to be done // before hiding peer.) ! if ((eventMask & AWTEvent.INPUT_METHODS_ENABLED_MASK) != 0) { InputContext inputContext = getInputContext(); if (inputContext != null) { inputContext.removeNotify(this); ======================================================================
11-06-2004