JDK-6492266 : Cannot select a Java input method in an WebStarted application
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 6,6u1,7
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: generic,windows_xp
  • CPU: generic,x86
  • Submitted: 2006-11-10
  • Updated: 2011-03-08
  • Resolved: 2011-03-07
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 JDK 6 JDK 7
5.0u25Fixed 6u2Fixed 7 b10Fixed
Related Reports
Duplicate :  
Duplicate :  
Duplicate :  
Relates :  
Relates :  
Relates :  
Description
How to reproduce:

1. Install some input method, e.g., CodePointIM demo into 'lib/ext' directory.
2. Run some Swing WebStart application that have a text field, e.g., Bugster.
3. Move focus to the text field.
4. Bring up the 'input method selection' pop up menu.  On Windows, click on the system icon on the top-left corner of the frame and then select "Select Input Method" menu item.
5. Popup menu is actually displayed, but you cannot operate with it.

This seems to happen on Java 6 only.  I could not reproduce it with 1.5.0_06.
I found one more regression of 6280964:

Look at the lines in BasicPopupMenuUI.installListeners() :

if (!menuKeyboardHelperInstalled) {
    if (menuKeyboardHelper == null) {
        menuKeyboardHelper = new MenuKeyboardHelper();
    }
    MenuSelectionManager msm = MenuSelectionManager.defaultManager();
    msm.addChangeListener(menuKeyboardHelper);
    menuKeyboardHelperInstalled = true;
}

Here menuKeyboardHelper is a static variable. Now only one instance of MenuKeyboardHelper is shared between all MenuSelectionManagers (and all EDTs). menuKeyboardHelper static field should be replaced by a variable in AppContext (as MouseGrabber at couple of lines above).
Copied from the description of 6484971:

JMenu works unstable when two applets work in different AppContexts,
sometimes they don't respond to key events like stop to move the menu selection
by arrow buttons and stop to react on menuItem's accelerators

How to reproduce:
run the provided applet in one JVM but in differect AppContext's
e.g. in Mozilla you should copy class files to two differect directories
and launch them in two browser's instances

To make sure check the console,
you need to have the same "Singleton" value
and the different AppContext.getAppContext().hashCode() value

Play with the menus of both applets several times,
you will the the described problems

JDK 1.5 and 1.6

import sun.awt.AppContext;
import javax.swing.*;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class MenuTest extends JApplet {

    public void init() {
        System.out.println("Singleton = " + ToolTipManager.sharedInstance().hashCode());
        System.out.println("AppContext.getAppContext().hashCode() = " + AppContext.getAppContext().hashCode());

        JMenu menu = new JMenu("Menu");
        menu.setMnemonic('m');
        menu.add(new JMenuItem("item"));
        JMenuItem item = new JMenuItem("item");
        item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_I, InputEvent.CTRL_MASK));
        item.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                JOptionPane.showConfirmDialog(MenuTest.this, "Is everything ok ?");
            }
        });
        menu.add(item);
        menu.add(new JMenuItem("item"));

        JMenuBar bar = new JMenuBar();
        bar.add(menu);
        setJMenuBar(bar);
    }
}

Comments
WORK AROUND The bug appears only when an application is started through WebStart. You can download the application and execute it locally.
07-02-2007

SUGGESTED FIX Webrev: http://javaweb.sfbay/jcg/1.7.0-dolphin/swing/6492266/
31-01-2007

EVALUATION The main cause is in the fact, that mouse events for lightweight Swing components are grabbed by parent heavyweight container. 'Select Input Method' popup menu is lightweight (see sun.awt.im.JInputMethodPopupMenu). It is shown above Bugster's start dialog. The popup is created from different EDT than the dialog. When popup is shown, all mouse events are grabbed by dialog's EDT and processed from it. Thanks to Artem Ananiev for finding it!
22-01-2007

EVALUATION The problem is in MenuSelectionManager.defaultManager(). Before the fix for 6280964 it stored it's instance in a static field. After the fix it stores the instance in application context. There are several application contexts - one for each ThreadGroup. If an application is started through WebStart and the 'input method selection' popup menu is brought up, several first defaultManager() calls are from 'javawsSecurityThreadGroup', but later ones are from 'main' thread group. As result there are two different instances of MenuSelectionManager and it causes inaccessibility of the popup menu.
15-12-2006

EVALUATION Swing nightly build on May 5 2006 started showing the problem. One of the fixes putbacked on May 4 seems suspicious. When I backed out the fix for 6280964 "1.5 REGRESSION: NullPointerException in JMenu.add()", the Java IM works properly, so fix for 6280964 could be the cause of this CR.
18-11-2006

EVALUATION b86 started showing the problem.
14-11-2006