Merge tag jb8u152-b1248.22

Change-Id: I9ba434e5b3c1ee21bd0acd0ded237cff65f524fb
diff --git a/src/macosx/classes/sun/lwawt/macosx/CInputMethod.java b/src/macosx/classes/sun/lwawt/macosx/CInputMethod.java
index 7842e0f..be127c2 100644
--- a/src/macosx/classes/sun/lwawt/macosx/CInputMethod.java
+++ b/src/macosx/classes/sun/lwawt/macosx/CInputMethod.java
@@ -376,14 +376,6 @@
         fAwtFocussedComponentPeer = null;
     }
 
-    private boolean isValid() {
-        return  fIMContext != null &&
-                fAwtFocussedComponent != null &&
-                fAwtFocussedComponentPeer != null &&
-                fCurrentText != null &&
-                fCurrentTextAsString != null;
-    }
-
     /**
         * Returns a control object from this input method, or null. A
      * control object provides methods that control the behavior of the
@@ -603,7 +595,7 @@
         final String[] retString = new String[] {""};
 
         try {
-            if (isValid())
+            if (fIMContext != null)
             LWCToolkit.invokeAndWait(new Runnable() {
                 public void run() { synchronized(retString) {
                     int location = locationIn;
@@ -656,7 +648,7 @@
         final int[] returnValue = new int[2];
 
         try {
-            if (isValid())
+            if (fIMContext != null)
             LWCToolkit.invokeAndWait(new Runnable() {
                 public void run() { synchronized(returnValue) {
                     AttributedCharacterIterator theIterator = fIMContext.getSelectedText(null);
@@ -732,7 +724,7 @@
         final int[] rect = new int[4];
 
         try {
-            if (isValid())
+            if (fIMContext != null)
             LWCToolkit.invokeAndWait(new Runnable() {
                 public void run() { synchronized(rect) {
                     int insertOffset = fIMContext.getInsertPositionOffset();
@@ -751,7 +743,7 @@
                     if (composedTextOffset > 0 && (fAwtFocussedComponent instanceof JTextComponent)) {
                         Rectangle r2 = fIMContext.getTextLocation(TextHitInfo.beforeOffset(0));
 
-                        if (r.equals(r2)) {
+                        if (r.equals(r2) && fCurrentTextAsString != null) {
                             // FIXME: (SAK) If the candidate text wraps over two lines, this calculation pushes the candidate
                             // window off the right edge of the component.
                             String inProgressSubstring = fCurrentTextAsString.substring(0, composedTextOffset);
@@ -777,7 +769,7 @@
         final int[] insertPositionOffset = new int[1];
 
         try {
-            if (isValid())
+            if (fIMContext != null)
             LWCToolkit.invokeAndWait(new Runnable() {
                 public void run() { synchronized(offsetInfo) {
                     offsetInfo[0] = fIMContext.getLocationOffset(screenX, screenY);
diff --git a/src/macosx/native/sun/awt/AWTView.m b/src/macosx/native/sun/awt/AWTView.m
index 7e6d0fb..dd521b9 100644
--- a/src/macosx/native/sun/awt/AWTView.m
+++ b/src/macosx/native/sun/awt/AWTView.m
@@ -65,6 +65,13 @@
     return shouldUsePressAndHold;
 }
 
+#ifndef kCFCoreFoundationVersionNumber10_13_Max
+#define kCFCoreFoundationVersionNumber10_13_Max 1499
+#endif
+
+#define IS_OSX_GT10_13 (floor(kCFCoreFoundationVersionNumber) > \
+    kCFCoreFoundationVersionNumber10_13_Max)
+
 @implementation AWTView
 
 @synthesize _dropTarget;
@@ -285,18 +292,35 @@
     fProcessingKeystroke = YES;
     fKeyEventsNeeded = YES;
 
-    if ([event keyCode] == 24 && (([event modifierFlags] & (NSControlKeyMask | NSCommandKeyMask)) != 0)) {
+    if ([event keyCode] == kVK_ANSI_Equal && (([event modifierFlags] & (NSControlKeyMask | NSCommandKeyMask)) != 0)) {
         return;
     }
 
-    // Allow TSM to look at the event and potentially send back NSTextInputClient messages.
-    [self interpretKeyEvents:[NSArray arrayWithObject:event]];
+    // Allow TSM to look at the event and potentially send back NSTextInputClient messages
+    if (fInputMethodLOCKABLE) {
+        [self interpretKeyEvents:[NSArray arrayWithObject:event]];
+    }
 
-    if (fEnablePressAndHold && [event willBeHandledByComplexInputMethod]) {
+    if (fEnablePressAndHold && [event willBeHandledByComplexInputMethod] && fInputMethodLOCKABLE) {
         fProcessingKeystroke = NO;
         if (!fInPressAndHold) {
             fInPressAndHold = YES;
             fPAHNeedsToSelect = YES;
+        } else if (IS_OSX_GT10_13) {
+            switch([event keyCode]) {
+                case kVK_Escape:
+                case kVK_Delete:
+                case kVK_Return:
+                case kVK_ForwardDelete:
+                case kVK_PageUp:
+                case kVK_PageDown:
+                case kVK_DownArrow:
+                case kVK_UpArrow:
+                case kVK_Home:
+                case kVK_End:
+                   [self abandonInput];
+                   break;
+            }
         }
         return;
     }
@@ -1206,6 +1230,12 @@
     }
     fPAHNeedsToSelect = NO;
 
+    // Abandon input to reset IM and unblock input after entering accented symbols
+    // (macOS 10.14+ only)
+
+    if (IS_OSX_GT10_13) {
+        [self abandonInput];
+    }
 }
 
 - (void) doCommandBySelector:(SEL)aSelector
diff --git a/src/solaris/classes/sun/awt/X11/XBaseWindow.java b/src/solaris/classes/sun/awt/X11/XBaseWindow.java
index 2648f1a..f9c23dc 100644
--- a/src/solaris/classes/sun/awt/X11/XBaseWindow.java
+++ b/src/solaris/classes/sun/awt/X11/XBaseWindow.java
@@ -586,7 +586,7 @@
     public void toFront() {
         XToolkit.awtLock();
         try {
-            if (Boolean.parseBoolean(System.getProperty("com.jetbrains.suppressWindowRaise", "false"))) {
+            if (XlibUtil.isRaiseAllowed()) {
                 XlibWrapper.XLowerWindow(XToolkit.getDisplay(), getWindow());
             } else {
                 XlibWrapper.XRaiseWindow(XToolkit.getDisplay(), getWindow());
diff --git a/src/solaris/classes/sun/awt/X11/XWindowPeer.java b/src/solaris/classes/sun/awt/X11/XWindowPeer.java
index 12fad95..7d76464 100644
--- a/src/solaris/classes/sun/awt/X11/XWindowPeer.java
+++ b/src/solaris/classes/sun/awt/X11/XWindowPeer.java
@@ -630,7 +630,11 @@
     public void handleWindowFocusInSync(long serial) {
         WindowEvent we = new WindowEvent((Window)target, WindowEvent.WINDOW_GAINED_FOCUS);
         XKeyboardFocusManagerPeer.getInstance().setCurrentFocusedWindow((Window) target);
-        sendEvent(we);
+        if (EventQueue.isDispatchThread()) {
+            ((Component)we.getSource()).dispatchEvent(we);
+        } else {
+            sendEvent(we);
+        }
     }
     // NOTE: This method may be called by privileged threads.
     //       DO NOT INVOKE CLIENT CODE ON THIS THREAD!
@@ -1398,7 +1402,8 @@
              */
             XToolkit.awtLock();
             try {
-                if (Boolean.parseBoolean(System.getProperty("com.jetbrains.suppressWindowRaise", "false"))) {
+                if (XlibUtil.isRaiseAllowed())
+                {
                     XlibWrapper.XLowerWindow(XToolkit.getDisplay(), getWindow());
                 } else {
                     XlibWrapper.XRaiseWindow(XToolkit.getDisplay(), getWindow());
@@ -2017,7 +2022,7 @@
             this.visible = visible;
             if (visible) {
                 applyWindowType();
-                if (Boolean.parseBoolean(System.getProperty("com.jetbrains.suppressWindowRaise", "false"))) {
+                if (XlibUtil.isRaiseAllowed()) {
                     XlibWrapper.XMapWindow(XToolkit.getDisplay(), getWindow());
                 } else {
                     XlibWrapper.XMapRaised(XToolkit.getDisplay(), getWindow());
diff --git a/src/solaris/classes/sun/awt/X11/XlibUtil.java b/src/solaris/classes/sun/awt/X11/XlibUtil.java
index f06af98..47983b5 100644
--- a/src/solaris/classes/sun/awt/X11/XlibUtil.java
+++ b/src/solaris/classes/sun/awt/X11/XlibUtil.java
@@ -30,6 +30,8 @@
 import java.awt.Point;
 import java.awt.Rectangle;
 
+import java.security.AccessController;
+import java.security.PrivilegedAction;
 import java.util.Collections;
 import java.util.HashSet;
 import java.util.Set;
@@ -406,4 +408,10 @@
             return 1 << (7 + button);
         }
     }
+
+
+    static Boolean isRaiseAllowed() {
+        return AccessController.doPrivileged((PrivilegedAction<Boolean>) () ->
+                Boolean.parseBoolean(System.getProperty("com.jetbrains.suppressWindowRaise", "false")));
+    }
 }
diff --git a/test/java/awt/InputMethods/InputMethodKeyEventsTest/InputMethodKeyEventsTest.java b/test/java/awt/InputMethods/InputMethodKeyEventsTest/InputMethodKeyEventsTest.java
new file mode 100644
index 0000000..2217cbb
--- /dev/null
+++ b/test/java/awt/InputMethods/InputMethodKeyEventsTest/InputMethodKeyEventsTest.java
@@ -0,0 +1,144 @@
+/*
+ * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/* @test
+ * @bug 8177414
+ * @summary KEY_PRESSED and KEY_TYPED events are not generated if a key's held
+ * @library ../../regtesthelpers
+ * @build Util
+ * @run main/manual InputMethodKeyEventsTest
+ */
+
+import java.awt.*;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.KeyEvent;
+import java.awt.event.KeyListener;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import test.java.awt.regtesthelpers.Util;
+
+public class InputMethodKeyEventsTest {
+    private static final AtomicBoolean testCompleted = new AtomicBoolean(false);
+    private static volatile boolean testResult = false;
+
+    private static Dialog controlDialog;
+    private static Frame testFrame;
+
+    private static final String instructions =
+            "Verify that KEY_PRESSED and KEY_TYPED events are generated after a key's " +
+            "\npressed and held.\n" +
+            "\nThis test is for OS X only. For other platforms please simply press \"Pass\".\n" +
+            "\n1. Go to \"System Preferences -> Keyboard -> Input Sources\" and add \"British\" IM." +
+            "\n2. Set current IM to \"British\"." +
+            "\n3. Set focus to the frame located at north-west corner." +
+            "\n4. Pres and hold the \"i\" key for 3 seconds." +
+            "\n5. Press and release the \"i\" key again. Use log area to ensure that " +
+            "\n   KEY_TYPED and KEY_PRESSED events are still generated." +
+            "\nIf KEY_PRESSED, KEY_TYPED and KEY_RELEASED are generated for every key press then " +
+            "\npress \"Pass\", otherwise press \"Fail\".";
+
+    public static void main(String[] args) {
+        try {
+            Robot robot = Util.createRobot();
+
+            createAndShowGUI();
+            Util.waitForIdle(robot);
+
+            Util.waitForCondition(testCompleted);
+            if (!testResult) {
+                throw new RuntimeException("Test FAILED!");
+            }
+        } finally {
+            if (controlDialog != null) {
+                controlDialog.dispose();
+            }
+            if (testFrame != null) {
+                testFrame.dispose();
+            }
+        }
+    }
+
+    private static void createAndShowGUI() {
+        controlDialog = new Dialog((Frame)null, "InputMethodKeyEventsTest");
+
+        TextArea messageArea = new TextArea(instructions, 15, 80, TextArea.SCROLLBARS_BOTH);
+        controlDialog.add("North", messageArea);
+
+        TextArea logArea = new TextArea("Test's logs are displayed here\n", 15, 80, TextArea.SCROLLBARS_BOTH);
+        controlDialog.add("Center", logArea);
+
+        Button passedButton = new Button("Pass");
+        passedButton.addActionListener(new ActionListener() {
+            @Override
+            public void actionPerformed(ActionEvent e) {
+                testResult = true;
+                completeTest();
+            }
+        });
+
+        Button failedButton = new Button("Fail");
+        failedButton.addActionListener(new ActionListener() {
+            @Override
+            public void actionPerformed(ActionEvent e) {
+                testResult = false;
+                completeTest();
+            }
+        });
+
+        Panel buttonPanel = new Panel();
+        buttonPanel.add("West",passedButton);
+        buttonPanel.add("East", failedButton);
+        controlDialog.add("South", buttonPanel);
+
+        controlDialog.setBounds(250, 0, 500, 500);
+        controlDialog.setVisible(true);
+
+        testFrame = new Frame("InputMethodKeyEventsTest");
+        testFrame.setSize(200, 200);
+        testFrame.addKeyListener(new KeyListener() {
+            @Override
+            public void keyTyped(KeyEvent e) {
+                logArea.append("KEY_TYPED keyCode = " + e.getKeyCode() + "\n");
+            }
+
+            @Override
+            public void keyPressed(KeyEvent e) {
+                logArea.append("KEY_PRESSED keyCode = " + e.getKeyCode() + "\n");
+            }
+
+            @Override
+            public void keyReleased(KeyEvent e) {
+                logArea.append("KEY_RELEASED keyCode = " + e.getKeyCode() + "\n");
+            }
+        });
+        testFrame.setVisible(true);
+    }
+
+    private static void completeTest() {
+        testCompleted.set(true);
+        synchronized (testCompleted) {
+            testCompleted.notifyAll();
+        }
+    }
+}
diff --git a/test/java/util/ResourceBundle/RestrictedBundleTest.java b/test/java/util/ResourceBundle/RestrictedBundleTest.java
index 7a19691..d6366d0 100644
--- a/test/java/util/ResourceBundle/RestrictedBundleTest.java
+++ b/test/java/util/ResourceBundle/RestrictedBundleTest.java
@@ -23,7 +23,6 @@
 /**
  * @test
  * @bug 4126805
- * @ignore until 6842022 is resolved
  * @run applet RestrictedBundleTest.html
  * @summary I was able to reproduce this bug with 1.2b2, but not with the current 1.2
  * build.  It appears that it was fixed by changes to the class-loading mechanism,
diff --git a/test/java/util/ResourceBundle/Test4300693.java b/test/java/util/ResourceBundle/Test4300693.java
index e357189..52108ed 100644
--- a/test/java/util/ResourceBundle/Test4300693.java
+++ b/test/java/util/ResourceBundle/Test4300693.java
@@ -22,7 +22,6 @@
  */
 /*
     @test
-    @ignore 6876961
     @summary test that ResourceBundle.getBundle can be called recursively
     @build  Test4300693RB
     @run main Test4300693
diff --git a/test/jbProblemsList.txt b/test/jbProblemsList.txt
index d4d83d3..5b8f6a9 100644
--- a/test/jbProblemsList.txt
+++ b/test/jbProblemsList.txt
@@ -118,6 +118,7 @@
 java/awt/Focus/AutoRequestFocusTest/AutoRequestFocusToFrontTest.java                6848406 generic-all
 java/awt/Focus/ActualFocusedWindowTest/ActualFocusedWindowRetaining.java            6829264 generic-all
 java/awt/Focus/ChoiceFocus/ChoiceFocus.java                                         8169103 windows-all,macosx-all
+java/awt/Focus/ClearGlobalFocusOwnerTest/ClearGlobalFocusOwnerTest.java             JRE-898 macosx-all
 java/awt/Focus/ClearLwQueueBreakTest/ClearLwQueueBreakTest.java                     8198618 macosx-all
 java/awt/Focus/CloseDialogActivateOwnerTest/CloseDialogActivateOwnerTest.java       7124555 generic-all
 java/awt/Focus/ConsumeNextKeyTypedOnModalShowTest/ConsumeNextKeyTypedOnModalShowTest.java 6986252 macosx-all
@@ -161,7 +162,8 @@
 java/awt/Graphics2D/MTGraphicsAccessTest/MTGraphicsAccessTest.java                  8145808 generic-all
 java/awt/Graphics2D/WhiteTextColorTest.java                                         8054638 generic-all
 java/awt/GridLayout/LayoutExtraGaps/LayoutExtraGaps.java                            8000171 windows-all
-java/awt/JAWT/JAWT.sh                                                               8197798 windows-all
+java/awt/JAWT/JAWT.sh                                                               8197798,8170729 generic-all
+java/awt/KeyboardFocusmanager/TypeAhead/ButtonActionKeyTest/ButtonActionKeyTest.html JRE-898 macosx-all
 java/awt/KeyboardFocusmanager/TypeAhead/SubMenuShowTest/SubMenuShowTest.html        8158380,8198624 generic-all
 java/awt/KeyboardFocusmanager/TypeAhead/TestDialogTypeAhead.html                    8198626,8074807 generic-all
 java/awt/LightweightDispatcher/LWDispatcherMemoryLeakTest.java                      8163261 generic-all
@@ -544,6 +546,9 @@
 sun/security/krb5/auto/SSL.java                                                       8171496 generic-all
 sun/security/krb5/auto/Unreachable.java                                               7164518 macosx-all
 com/sun/org/apache/xml/internal/security/transforms/ClassLoaderTest.java	          7147060 generic-all
+sun/security/pkcs11/KeyStore/SecretKeysBasic.sh                                       8209398 linux-all
+sun/security/pkcs11/Secmod/GetPrivateKey.java                                         8212134 generic-all
+sun/security/pkcs11/Secmod/JksSetPrivateKey.java                                      8212134 generic-all
 sun/security/pkcs11/Secmod/AddPrivateKey.java                                         6988842 solaris-all
 sun/security/pkcs11/ec/ReadCertificates.java                                          6988842 solaris-all
 sun/security/pkcs11/ec/ReadPKCS12.java                                                6988842 solaris-all
@@ -598,8 +603,7 @@
 
 javax/swing/JMenu/4692443/bug4692443.java                                             8076178 generic-all
 javax/swing/JMenu/8072900/WrongSelectionOnMouseOver.java                              8142534 generic-all
-javax/swing/JMenuBar/4750590/bug4750590.java                                          8158496 windows-all
-javax/swing/JMenuBar/4750590/bug4750590.java                                          8076178 macosx-all
+javax/swing/JMenuBar/4750590/bug4750590.java                                          8076178,8158496 macosx-all,windows-all,linux-all
 javax/swing/JMenuItem/4171437/bug4171437.java                                         8040916 generic-all
 javax/swing/JMenuItem/4654927/bug4654927.java                                         8172536 generic-all
 javax/swing/JMenuItem/6209975/bug6209975.java                                         8025083 generic-all
@@ -607,7 +611,7 @@
 javax/swing/JOptionPane/6464022/bug6464022.java                                       7124548 macosx-all
 javax/swing/JPopupMenu/4458079/bug4458079.java                                        8040917 generic-all
 javax/swing/JPopupMenu/4966112/bug4966112.java                                        8064915,8074385 generic-all
-javax/swing/JPopupMenu/6800513/bug6800513.java                                        8080868 macosx-all,windows-all
+javax/swing/JPopupMenu/6800513/bug6800513.java                                        8080868 generic-all
 javax/swing/JPopupMenu/6827786/bug6827786.java                                        8042378,8042378 generic-all
 javax/swing/JPopupMenu/6987844/bug6987844.java                                        8169956 generic-all
 javax/swing/JPopupMenu/7156657/bug7156657.java                                        7185563 generic-all
@@ -687,7 +691,7 @@
 tools/pack200/CommandLineTests.java                                                     8059906 generic-all
 tools/pack200/Pack200Test.java                                                                  solaris-all, macosx-all
 tools/pack200/UnpackerMemoryTest.java                                                   8140611 linux-all
-tools/launcher/FXLauncherTest.java                                                      8068049 linux-all,macosx-all
+tools/launcher/FXLauncherTest.java                                                      8068049 generic-all
 tools/launcher/MultipleJRE.sh                                                           8180478 windows-all
 
 ############################################################################