United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-6492266 Cannot select a Java input method in an WebStarted application
JDK-6492266 : Cannot select a Java input method in an WebStarted application

Details
Type:
Bug
Submit Date:
2006-11-10
Status:
Closed
Updated Date:
2011-03-08
Project Name:
JDK
Resolved Date:
2011-03-07
Component:
client-libs
OS:
generic,windows_xp
Sub-Component:
javax.swing
CPU:
x86,generic
Priority:
P3
Resolution:
Fixed
Affected Versions:
6,6u1,7
Fixed Versions:

Related Reports
Backport:
Backport:
Duplicate:
Duplicate:
Duplicate:
Relates:
Relates:
Relates:

Sub Tasks

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
EVALUATION

b86 started showing the problem.
                                     
2006-11-14
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.
                                     
2006-11-18
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.
                                     
2006-12-15
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!
                                     
2007-01-22
SUGGESTED FIX

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

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



Hardware and Software, Engineered to Work Together