JDK-8214578 : [macos] Problem with backslashes on macOS/JIS keyboard: Java ignores system settings
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 8u202,11.0.2,12,13,14
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: os_x
  • CPU: x86
  • Submitted: 2018-11-26
  • Updated: 2022-01-12
  • Resolved: 2019-11-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.
JDK 11 JDK 13 JDK 14 JDK 8
11.0.7-oracleFixed 13.0.4Fixed 14 b25Fixed 8u251Fixed
Related Reports
Relates :  
Relates :  
Relates :  
Description
ADDITIONAL SYSTEM INFORMATION :
macOS 10.13.6 (but other versions also have the same problem)

A DESCRIPTION OF THE PROBLEM :
Java apps ignore system settings regarding handling yen key.
Yen key generated a different scancode than the backslash key, and macOS has settings to handle those correctly. Java apps seems to ignore that.

There is a fix https://bugs.openjdk.java.net/browse/JDK-8191178 which tries to improve the handling of yen symbol, but actually it makes things worse for the backslash case, making impossible to input backslash at all in some cases.

Please see https://youtrack.jetbrains.com/issue/JRE-572 for the further discussion.

REGRESSION : Last worked in version 8u172

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Install macOS 10.13 High Sierra, set system language to English
2. Find a keyboard with JIS layout
3. Add Japanese input source
4. Change Settings -> Keyboard -> Input Sources -> Japanese -> "Â¥" key generates -> \ (Backslash)
5. Change Input method to Romaji
6. Check that other apps correctly interpret that key as backslash now
7. Check that a Java app still interprets it as "yen"

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
See https://youtrack.jetbrains.com/issue/JRE-572#focus=streamItem-27-3178131-0-0
ACTUAL -
See https://youtrack.jetbrains.com/issue/JRE-572#focus=streamItem-27-3178131-0-0

---------- BEGIN SOURCE ----------
import javax.swing.*; 

public class JTextFieldTest { 
    public static void main(String[] args) { 
        SwingUtilities.invokeLater(() -> { 
            JFrame f = new JFrame(); 
            JTextField field = new JTextField(20); 
            f.add(field); 
            f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); 
            f.pack(); 
            f.setLocationRelativeTo(null); 
            f.setVisible(true); 
        }); 
    } 
} 
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Before the fix https://bugs.openjdk.java.net/browse/JDK-8191178 (checked with 8u202b03) it was possible to input backslash with Command+Yen, the fix breaks that behavior.

FREQUENCY : always



Comments
8u review in discussion here: https://mail.openjdk.java.net/pipermail/jdk8u-dev/2021-October/014331.html https://mail.openjdk.java.net/pipermail/jdk8u-dev/2021-October/014346.html
05-11-2021

Fix request (13u) Requesting backport to 13u for parity with 11u, applies cleanly.
04-06-2020

ix request (11u) I would like to downport this for parity with 11.0.7-oracle. Applies clean.
02-12-2019

URL: https://hg.openjdk.java.net/jdk/jdk/rev/d0bfaae2ff33 User: psadhukhan Date: 2019-11-21 09:06:33 +0000
21-11-2019

URL: https://hg.openjdk.java.net/jdk/client/rev/d0bfaae2ff33 User: psadhukhan Date: 2019-11-07 06:01:06 +0000
07-11-2019

https://discussions.apple.com/thread/250732490
14-10-2019

fix is on review: http://mail.openjdk.java.net/pipermail/awt-dev/2019-October/015436.html http://cr.openjdk.java.net/~psadhukhan/8214578/webrev.2/
09-10-2019

When NSTextInputClient.insertText() method is called with "\" codePoint with japanese as input source insertText() checks whether this codePoint is complex or not, so in this case, it is not complex, InputMethodEvent is not generated and no "\" is inserted in JTextField. Proposed fix is to see if keyboard layout is Japanese (kotoeri) and codePoint is "\" then take it as complex codepoint and generate IME, so that whatever system setting is set for "yen" symbol either to "\" or to "yen", it is correctly interpreted and inputted in CInputMethod.insertText() method, to be seen in JTextField.
26-09-2019

I tried onscreen keyboard and use backslash "\" and it gets printed as "\" in the textfield in my testing as shown in the attached screenshot, so it's still not reproducible for me.
05-09-2019

On my mac10.13.3, when I do "Settings -> Keyboard -> Input Sources -> Japanese -> "Â¥" key generates -> \ (Backslash) " and run ------------------ public class JTextFieldTest { public static void main(String[] args) { SwingUtilities.invokeLater(() -> { JFrame f = new JFrame(); JTextField field = new JTextField(20); f.add(field); f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); f.pack(); f.setLocationRelativeTo(null); f.setVisible(true); }); } } ------------- and change Input method to Romaji and try to insert "\" it is inserted as "\" only. If I again change ""Settings -> Keyboard -> Input Sources -> Japanese -> "Â¥" key generates -> ¥" then inserting "\" inserts "¥". So, it is not reproducible for me. BTW, it was mentioned "Find a keyboard with JIS layout". I am using macbook pro keyboard which I am not sure if it is JIS layout or not.
15-03-2019

As per description in macOS X (10.13.6) Java apps ignore system settings w.r.t yen (JIS) key. yen key has a different scancode than the backslash key. Issue is also being discussed at: https://youtrack.jetbrains.com/issue/JRE-572 Non-JIS keyboard pproduces different scancodes and uses different scancode-to-vkey translation mappings than JIS keyboards. Isuse is also reproducible on 8u202-b3 using a random USB PC US layout keyboard and Karabiner Elements. Apprently, the isue occurs due to the fix in 8u202 and 11.0.2 (JDK-8191178) which tries to improve the handling of yen symbol. The issue does reproduce in JDK 12 as well. Steps to reproduce: 1) Install Karabiner Elements 2) Go to macOS Settings -> Keyboard -> [Keyboard Tab] -> Change Keyboard Type -> Click something -> Select JIS at the end 3) Open Karabiner Elements Settings -> Simple Modifications -> Select your keyboard -> from any key to "international3" 4) Open the test program and press the changed key On 8u144 yen; alt+yen give ¥\ On 8u202 the result is ¥¥fimage When using other apps the result is \¥ Detailed steps with video snippet available in subsequent comment. Note: Don't forget to change OS X keyboard type back after experimentation.
01-12-2018