United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-4867453 : Component.removeNotify() should always deactivate InputContext

Details
Type:
Bug
Submit Date:
2003-05-21
Status:
Resolved
Updated Date:
2003-07-25
Project Name:
JDK
Resolved Date:
2003-07-25
Component:
client-libs
OS:
windows_nt,windows_xp,windows_2000
Sub-Component:
java.awt
CPU:
x86
Priority:
P4
Resolution:
Fixed
Affected Versions:
1.4.0,1.4.2,1.4.2_07
Fixed Versions:
5.0 (tiger)

Related Reports
Backport:
Duplicate:
Relates:

Sub Tasks

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
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);
======================================================================
                                     
2004-06-11
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.


======================================================================
                                     
2004-06-11
CONVERTED DATA

BugTraq+ Release Management Values

COMMIT TO FIX:
tiger

FIXED IN:
tiger

INTEGRATED IN:
tiger
tiger-b13


                                     
2004-06-14



Hardware and Software, Engineered to Work Together