United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-4766655 : Cannot input underscore '_' in AWT Components with Japanese Keyboard

Details
Type:
Bug
Submit Date:
2002-10-22
Status:
Resolved
Updated Date:
2002-11-15
Project Name:
JDK
Resolved Date:
2002-11-15
Component:
client-libs
OS:
windows_xp
Sub-Component:
java.awt
CPU:
x86
Priority:
P3
Resolution:
Fixed
Affected Versions:
1.4.1
Fixed Versions:
1.4.2 (mantis)

Related Reports
Relates:

Sub Tasks

Description

Name: rmT116609			Date: 10/22/2002


FULL PRODUCT VERSION :
java version "1.4.1_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_01-b01)
Java HotSpot(TM) Client VM (build 1.4.1_01-b01, mixed mode)


FULL OPERATING SYSTEM VERSION :
Microsoft Windows XP [Version 5.1.2600]


EXTRA RELEVANT SYSTEM CONFIGURATION :
Japanese JIS keyboard with Japanese operating system.

DESCRIPTION OF THE PROBLEM :
When the character '_' is typed in on java.awt.TextArea, the character '|' is typed in, instead.

The problem occurs only on java.awt.TextArea and  java.awt.TextField with Japanese keyboard.

It does not occur on any version of J2SDK1.3.x.

It occurs only on Microsoft Windows.

It does not occur on javax.swing.* components.


REGRESSION.  Last worked in version 1.3.1

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1.Boot any java program that uses AWT Text Components.
2.Type '_' on the Text component.
3.That's all.


EXPECTED VERSUS ACTUAL BEHAVIOR :
Expected:
  The character '_' is typed in.

Actual Result:
  The character '|' is typed in, instead.


ERROR MESSAGES/STACK TRACES THAT OCCUR :
There are no error messages.


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.awt.*;

public class SimpleAWTTextFrame extends java.awt.Frame {
  public static void main(String args[]) {
    SimpleAWTTextFrame f = new SimpleAWTTextFrame();
    f.setSize(100,100);
    f.setVisible(true);
  }
  
  TextField textfield;
  public SimpleAWTTextFrame() {
    textfield = new TextField();
    add(textfield);
  }
}

---------- END SOURCE ----------

CUSTOMER WORKAROUND :
Cut and Paste, use US Keyboard,  or use javax.swing.* instead.
(Review ID: 165943) 
======================================================================

                                    

Comments
EVALUATION

The problem is that both the yen sign and the back-slash share the same codepoint. Furthermore both characters are represented by the same Java
virtual Key VK_BACK_SLASH. In nativeHandleEvent we check whether the user
has modified the KeyEvent by converting the Java key char to windows key
and comparing if it is  different from the Native event stored away in the
KeyEvent. If it is different, we then use the new key. The problem is that
when we map from the Java key char for backslash to Windows key we always find
the first windows key that maps to this which is 0xDC (VK_OEM_5) even though
the original windows key was 0xE2 (VK_OEM_102). This looks like a change and we cannot distinguish  this inadvertant change from a real user change. 

###@###.### 2002-11-04

                                     
2002-11-04
SUGGESTED FIX

*** /export/bino/mantis/webrev/src/windows/native/sun/windows/awt_Component.cpp-        Wed Nov  6 19:31:04 2002
--- awt_Component.cpp   Wed Nov  6 19:08:05 2002

*** 3055,3065 ****
      return (LOWORD(GetKeyboardLayout(0)) == MAKELANGID(LANG_JAPANESE, SUBLANG_DEFAULT))
          && (GetKeyboardType(0) == 7);
  }
  
  void AwtComponent::JavaKeyToWindowsKey(UINT javaKey,
!                                      UINT *windowsKey, UINT *modifiers)
  {
      // Handle the few cases where a Java VK code corresponds to a Windows
      // key/modifier combination or applies only to specific keyboard layouts
      switch (javaKey) {
          case java_awt_event_KeyEvent_VK_ALL_CANDIDATES:
--- 3055,3065 ----
      return (LOWORD(GetKeyboardLayout(0)) == MAKELANGID(LANG_JAPANESE, SUBLANG_DEFAULT))
          && (GetKeyboardType(0) == 7);
  }
  
  void AwtComponent::JavaKeyToWindowsKey(UINT javaKey,
!                                      UINT *windowsKey, UINT *modifiers, UINT originalWindowsKey)
  {
      // Handle the few cases where a Java VK code corresponds to a Windows
      // key/modifier combination or applies only to specific keyboard layouts
      switch (javaKey) {
          case java_awt_event_KeyEvent_VK_ALL_CANDIDATES:

*** 3089,3105 ****
--- 3089,3127 ----
              *modifiers = 0;
              return;
          }
      }
  
+     // Bug 4766655
+     // Two Windows keys could map to the same Java key, so
+     // give preference to the originalWindowsKey if it is
+     // specifed (not IGNORE_KEY).
+     if (originalWindowsKey == IGNORE_KEY) {
          for (int j = 0; dynamicKeyMapTable[j].windowsKey != 0; j++) {
              if (dynamicKeyMapTable[j].javaKey == javaKey) {
                  *windowsKey = dynamicKeyMapTable[j].windowsKey;
                  *modifiers = 0;
                  return;
              }
          }
+     }
+     else {
+         BOOL found = false;
+         for (int j = 0; dynamicKeyMapTable[j].windowsKey != 0; j++) {
+             if (dynamicKeyMapTable[j].javaKey == javaKey) {
+                 *windowsKey = dynamicKeyMapTable[j].windowsKey;
+                 *modifiers = 0;
+                 found = true;
+                 if (*windowsKey == originalWindowsKey) {
+                     return;   /* if ideal case found return, else keep looking */
+                 }
+             }
+         }
+         if (found) {
+             return;
+         }
+     }
  
      *windowsKey = 0;
      *modifiers = 0;
      return;
  }

*** 6287,6297 ****
                        break; 
                  } 
  
                    if (keyCode != java_awt_event_KeyEvent_VK_UNDEFINED) {
                      UINT newWinKey, ignored;
!                     p->JavaKeyToWindowsKey(keyCode, &newWinKey, &ignored);
                      if (newWinKey != 0) {
                          winKey = newWinKey;
                      }
                  }
  
--- 6309,6319 ----
                        break; 
                  } 
  
                    if (keyCode != java_awt_event_KeyEvent_VK_UNDEFINED) {
                      UINT newWinKey, ignored;
!                     p->JavaKeyToWindowsKey(keyCode, &newWinKey, &ignored, winKey);
                      if (newWinKey != 0) {
                          winKey = newWinKey;
                      }
                  }
  

*** /export/bino/mantis/webrev/src/windows/native/sun/windows/awt_Component.h-  Wed Nov  6 19:31:06 2002
--- awt_Component.h     Wed Nov  6 19:25:00 2002

*** 394,404 ****
      static void InitDynamicKeyMapTable();
      static void BuildDynamicKeyMapTable();
      static jint GetJavaModifiers();
      static jint GetButton(int mouseButton);
      static UINT WindowsKeyToJavaKey(UINT windowsKey, UINT modifiers);
!     static void JavaKeyToWindowsKey(UINT javaKey, UINT *windowsKey, UINT *modifiers);
      UINT WindowsKeyToJavaChar(UINT wkey, UINT modifiers);
  
      /* routines used for input method support */
      void SetInputMethod(jobject im, BOOL useNativeCompWindow);
      static int GetContextData(HIMC hIMC, DWORD dwIndex, LPVOID* lplpData);
--- 394,411 ----
      static void InitDynamicKeyMapTable();
      static void BuildDynamicKeyMapTable();
      static jint GetJavaModifiers();
      static jint GetButton(int mouseButton);
      static UINT WindowsKeyToJavaKey(UINT windowsKey, UINT modifiers);
!     static void JavaKeyToWindowsKey(UINT javaKey, UINT *windowsKey, UINT *modifiers, UINT originalWindowsKey);
! 
!     INLINE static void AwtComponent::JavaKeyToWindowsKey(UINT javaKey,
!                                      UINT *windowsKey, UINT *modifiers)
!     {
!         JavaKeyToWindowsKey(javaKey, windowsKey, modifiers, IGNORE_KEY);
!     }
!     
      UINT WindowsKeyToJavaChar(UINT wkey, UINT modifiers);
  
      /* routines used for input method support */
      void SetInputMethod(jobject im, BOOL useNativeCompWindow);
      static int GetContextData(HIMC hIMC, DWORD dwIndex, LPVOID* lplpData);

                                     
2004-06-11
CONVERTED DATA

BugTraq+ Release Management Values

COMMIT TO FIX:
mantis

FIXED IN:
mantis

INTEGRATED IN:
mantis
mantis-b08


                                     
2004-06-14



Hardware and Software, Engineered to Work Together