JDK-6663665 : getAvailableLocales is repeatedly called when try to select input method
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 6u4
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2008-02-15
  • Updated: 2011-01-19
  • Resolved: 2008-07-03
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.
JDK 6 JDK 7
6u10Resolved 7Resolved
Related Reports
Duplicate :  
Relates :  
Description
When input method selection popup appear, InputMethodDescriptor.getAvailableLocales() is being called repeadedly and sometimes interfere with user operation.
In order to reproduce,
place attaced WuBi.jar in jre/lib/ext.
lanunch Notepad demo.
from system menu click Select Input Method.
try to select wubi or Test input method.
You should notice following trace messages repeatedly output in console.

WuBi IM:getAvailableLocales() is being called.
Test IM:getAvailableLocales() is being called.

This doesn't happen (called once, not repeatedly many times) in 6u3.

Comments
EVALUATION It is a regression of 6544309. Before the fix EventQueue.invokeAndWait() was used. It prevented the "while" loop to be called many times in a row.
08-04-2008

EVALUATION The problem is in InputMethodManager.run() method. It turned out that the "while" loop is performed many times in a row when the user opens the Input Method Menu. It causes showInputMethodMenuOnRequesterEDT() method be called repeatedly. The method creates "show input method menu" tasks and places them in a event queue. As the result, there are many attempts to show the Input Method Menu instead of single one. A fix is in the attachment.
08-04-2008

SUGGESTED FIX The idea of the fix is to add a boolean variable, which will indicate whether the Input Method Menu is preparing to be shown or not. src/share/classes/sun/awt/im/InputMethodManager.java @@ -245,10 +245,13 @@ // component that is requesting input method switch // must be Frame or Dialog private Component requestComponent; + // determines whether popup menu is preparing to be shown or not + private boolean menuIsPreparingToShow; + // input context that is requesting input method switch private InputContext requestInputContext; // IM preference stuff private static final String preferredIMNode = "/sun/awt/im/preferredInputMethod"; @@ -297,10 +300,12 @@ // Loop for processing input method change requests while (true) { waitForChangeRequest(); initializeInputMethodLocatorList(); try { + if (!menuIsPreparingToShow) { + setMenuIsPreparingToShow(true); if (requestComponent != null) { try { showInputMethodMenuOnRequesterEDT(requestComponent); } catch (Exception ex) { throw new RuntimeException(ex); @@ -308,20 +313,26 @@ } else { // show the popup menu within the event thread EventQueue.invokeAndWait(new Runnable() { public void run() { showInputMethodMenu(); + setMenuIsPreparingToShow(false); } }); } + } } catch (InterruptedException ie) { } catch (InvocationTargetException ite) { // should we do anything under these exceptions? } } } + private synchronized void setMenuIsPreparingToShow(boolean menuIsPreparingToShow) { + this.menuIsPreparingToShow = menuIsPreparingToShow; + } + // Shows Input Method Menu on the EDT of requester component // to avoid side effects. See 6544309. private void showInputMethodMenuOnRequesterEDT(Component requester) throws InterruptedException, InvocationTargetException { @@ -335,10 +346,11 @@ InvocationEvent event = new InvocationEvent(requester, new Runnable() { public void run() { showInputMethodMenu(); + setMenuIsPreparingToShow(false); } }, lock, true);
08-04-2008

EVALUATION This strange behavior is observed with JDK6 since 6u4 and JDK7 since b15. AWT team has no fixes integrated/backported into these releases, but Swing team has: 6544309. I don't know if this fix was incomplete/incorrect or some more supporting changes are required from IM team, so dispatching this CR to the author of 6544309 for further investigation.
27-02-2008