JDK-8068283 : Mac OS Incompatibility between JDK 6 and 8 regarding input method handling
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 7u4,8u25,9
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2014-12-25
  • Updated: 2018-09-17
  • Resolved: 2015-01-20
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 8 JDK 9
8u31Fixed 9 b52Fixed
Related Reports
Relates :  
Relates :  
Relates :  
Relates :  
Description
The problem is described in the following OpenJDK mailing list thread: 
http://mail.openjdk.java.net/pipermail/awt-dev/2014-December/008761.html
Comments
Review started: http://cr.openjdk.java.net/%7Eanashaty/8068283/9/webrev.00/
20-01-2015

The new fix version: --- a/src/macosx/native/sun/awt/AWTView.m Mon Nov 17 18:32:15 2014 +0300 +++ b/src/macosx/native/sun/awt/AWTView.m Tue Jan 20 16:37:17 2015 +0300 @@ -889,9 +889,9 @@ // text, or 'text in progress'. We also need to send the event if we get an insert text out of the blue! // (i.e., when the user uses the Character palette or Inkwell), or when the string to insert is a complex // Unicode value. - NSUInteger utf8Length = [aString lengthOfBytesUsingEncoding:NSUTF8StringEncoding]; + NSUInteger utf16Length = [aString lengthOfBytesUsingEncoding:NSUTF16StringEncoding]; - if ([self hasMarkedText] || !fProcessingKeystroke || (utf8Length > 1)) { + if ([self hasMarkedText] || !fProcessingKeystroke || (utf16Length > 2)) { JNIEnv *env = [ThreadUtilities getJNIEnv]; static JNF_MEMBER_CACHE(jm_selectPreviousGlyph, jc_CInputMethod, "selectPreviousGlyph", "()V");
20-01-2015

The updated fix suggested by Sergey Malenkov: --- AWTView.m.old 2014-12-08 14:21:10.976429400 +0300 +++ AWTView.m 2014-12-11 15:43:26.473456000 +0300 @@ -889,11 +889,11 @@ // text, or 'text in progress'. We also need to send the event if we get an insert text out of the blue! // (i.e., when the user uses the Character palette or Inkwell), or when the string to insert is a complex // Unicode value. - NSUInteger utf8Length = [aString lengthOfBytesUsingEncoding:NSUTF8StringEncoding]; - - if ([self hasMarkedText] || !fProcessingKeystroke || (utf8Length > 1)) { - JNIEnv *env = [ThreadUtilities getJNIEnv]; + JNIEnv *env = [ThreadUtilities getJNIEnv]; + jstring insertedText = JNFNSToJavaString(env, aString); + jsize insertedLength = (*env)->GetStringLength(env, insertedText); + if ([self hasMarkedText] || !fProcessingKeystroke || (insertedLength > 1)) { static JNF_MEMBER_CACHE(jm_selectPreviousGlyph, jc_CInputMethod, "selectPreviousGlyph", "()V"); // We need to select the previous glyph so that it is overwritten. if (fPAHNeedsToSelect) { @@ -902,14 +902,13 @@ } static JNF_MEMBER_CACHE(jm_insertText, jc_CInputMethod, "insertText", "(Ljava/lang/String;)V"); - jstring insertedText = JNFNSToJavaString(env, aString); JNFCallVoidMethod(env, fInputMethodLOCKABLE, jm_insertText, insertedText); // AWT_THREADING Safe (AWTRunLoopMode) - (*env)->DeleteLocalRef(env, insertedText); // The input method event will create psuedo-key events for each character in the committed string. // We also don't want to send the character that triggered the insertText, usually a return. [3337563] fKeyEventsNeeded = NO; } + (*env)->DeleteLocalRef(env, insertedText); fPAHNeedsToSelect = NO;
12-01-2015

BTW, on Mac JDK6 not all <Alt>-Char combinations could be used as shortcuts, as Anton T. mentioned in the JDK-7144063 the <Alt>+T for example also doesn't generate the correct KEY_PRESSED event since that combination generates 3-byte UTF-8 character (E2 80 A0). However the fix proposed by Sergey Malenkov solves this problem as well: --- a/src/macosx/native/sun/awt/AWTView.m Wed Dec 10 17:20:48 2014 +0400 +++ b/src/macosx/native/sun/awt/AWTView.m Wed Dec 10 19:51:56 2014 +0300 @@ -889,7 +889,7 @@ // text, or 'text in progress'. We also need to send the event if we get an insert text out of the blue! // (i.e., when the user uses the Character palette or Inkwell), or when the string to insert is a complex // Unicode value. - NSUInteger utf8Length = [aString lengthOfBytesUsingEncoding:NSUTF8StringEncoding]; + NSUInteger utf8Length = [aString length]; if ([self hasMarkedText] || !fProcessingKeystroke || (utf8Length > 1)) { JNIEnv *env = [ThreadUtilities getJNIEnv];
25-12-2014

In the JDK-7144063 it was made a decision that keyboard shortcuts like <Alt>+Char for MacOS should be disregarded since the 'normal' native app avoids such combination in favor to <Cmd>+<Alt>+Char. That looks true indeed, however if the <Alt>+Char shortcut is manually assigned to an action (I tried the XCode), this action is executed and the symbol is not typed anymore in the code area. The native behavior seems more appropriate to me. Taking into account crossplatform applications with the accustomed shortcuts (e.g. IDEA) this problem appears to be quite actual.
25-12-2014