JDK-8187364 : Unable to enter zero width non-joiner (ZWNJ) symbol in Swing text component
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 8,8u144,9,10,11,12
  • Priority: P2
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows
  • Submitted: 2017-09-08
  • Updated: 2019-09-04
  • Resolved: 2018-11-12
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 12 JDK 8 Other
11.0.3-oracleFixed 12 b23Fixed 8u192Fixed openjdk8u212Fixed
Description
FULL PRODUCT VERSION :
JDK 8 or later release family, JDK 7, JDK 6

ADDITIONAL OS VERSION INFORMATION :
MS Windows 10 OS

A DESCRIPTION OF THE PROBLEM :
Zero width non-joiner (ZWNJ) character cannot be entered in Swing text components using Persian keyboard layout, while it can successfully be entered in AWT text components.

To confirm that the problem is with input of ZWNJ character and not its rendering, a correct text entered in AWT text component can be copied and inserted into Swing text component, where it will be displayed also correctly.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Compile and run the attached test case "ZeroWidthNonJoinerCharCannotBeEntered.java" with JDK to be tested.
2. Set "Persian" keyboard layout.
3. Perform the following sequence of keyboard input events both in any AWT text component and in any Swing text component on the window shown by the test case:
- press 'q' button, press Ctrl+Shift+2, press 'q' button again.

The bug is reproduced, if the text entered in Swing text component differs from the text in AWT text component assuming that the text in AWT text component is correct.
Correct text: "�������"
Incorrect text: "����"
Comments
Fix Request (8u) This is a corner case in Swing that needs to be fixed for better UX. This simple patch applies with reshuffling to 8u. I manually checked the reproducer on Windows and Persian, and it is indeed broken without the patch, and fixed with the patch.
25-02-2019

Fix Request This is a corner case in Swing that needs to be fixed for better UX. I see the patch is in 11.0.3-oracle. Patch applies cleanly to 11u. I manually checked the reproducer on Windows and Persian, and it is indeed fixed with the patch.
20-02-2019

Verified practically that the bug affects only MS Windows OS. On macOS and Linux OS zero width non-joiner (ZWNJ) character cannot be entered by means of "Ctrl+Shift+2" key combination with Persian keyboard layout in other native applications. ROOT CAUSE OF THE BUG: Root cause of the bug was defined. In the method "javax.swing.text.DefaultEditorKit.DefaultKeyTypedAction.actionPerformed(ActionEvent)" ZWNJ character "\u200C" is not inserted to the document of "javax.swing.JTextField" through the call "target.replaceSelection(content);", because a prior call to the method "sun.awt.SunToolkit.isPrintableCharacterModifiersMask(int)" returns "false" for the case, when key modifiers integer variable equals 3 ("Ctrl+Shift" keys are pressed).
02-11-2018

The test case was attached to the bug as "ZeroWidthNonJoinerCharCannotBeEntered.java" file. The bug was reproduced on MS Windows 10 OS with JDK 12 compiled from the latest version of the development source code, JDK 12+15, JDK 10+43, JDK 8u162 b12, JDK 8 b132, JDK 7u201 b11, JDK 6u211 b11.
01-11-2018

Feel free to fix in 10 by RDP2 date: http://mail.openjdk.java.net/pipermail/jdk-dev/2017-October/000085.html
02-11-2017