Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8226806

[macOS 10.14] Methods of Java Robot should be called from appropriate thread

    XMLWordPrintable

Details

    • b16
    • os_x

    Backports

      Description

        ADDITIONAL SYSTEM INFORMATION :
        MacBook Pro, Intel Core i7 (64 bit)
        macOS Mojave 10.14.5
        jdk-12.0.1.jdk / jdk-11.0.3.jdk / jdk1.8.0_212.jdk

        A DESCRIPTION OF THE PROBLEM :
        On recent macOS updates, like Mojave, running Java apps which uses Robot logs the following message to the Java error output:
        yyyy-mm-dd hh:mm:ss.NNN java[NNN:NNN] pid(NNN)/euid(NNN) is calling TIS/TSM in non-main thread environment, ERROR : This is NOT allowed. Please call TIS/TSM in main thread!!!

        It looks like currently on macOS Java Robot methods (jdk/src/java.desktop/macosx/native/libawt_lwawt/awt/CRobot.m) work in some background thread, but it should be performed on Main Thread.

        So correctness of apps using Java Robot may possibly be affected.

        For example, such message appears in Java error output during the following JDK jtreg tests run on macOS Mojave:

        java/awt/event/KeyEvent/SwallowKeyEvents/SwallowKeyEvents.java
        java/awt/KeyboardFocusmanager/ConsumeNextMnemonicKeyTypedTest/ConsumeForModalDialogTest/ConsumeForModalDialogTest.java
        java/awt/KeyboardFocusmanager/TypeAhead/EnqueueWithDialogButtonTest/EnqueueWithDialogButtonTest.java

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        Compile and run simple reproducer - NonMainThreadTest.java:

        <javac> NonMainThreadTest.java
        <java> NonMainThreadTest

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        Empty java error output.
        Specifically, no following message in the java error output:

        yyyy-mm-dd hh:mm:ss.NNN java[NNN:NNN] pid(NNN)/euid(NNN) is calling TIS/TSM in non-main thread environment, ERROR : This is NOT allowed. Please call TIS/TSM in main thread!!!
        ACTUAL -
        ---

        > jdk1.8.0_202.jdk/Contents/Home/bin/java -showversion NonMainThreadTest

        java version "1.8.0_202"
        Java(TM) SE Runtime Environment (build 1.8.0_202-b08)
        Java HotSpot(TM) 64-Bit Server VM (build 25.202-b08, mixed mode)

        Test start
        2019-06-24 17:42:45.886 java[1950:42575] pid(1950)/euid(502) is calling TIS/TSM in non-main thread environment, ERROR : This is NOT allowed. Please call TIS/TSM in main thread!!!
        2019-06-24 17:42:45.886 java[1950:42575] pid(1950)/euid(502) is calling TIS/TSM in non-main thread environment, ERROR : This is NOT allowed. Please call TIS/TSM in main thread!!!
        2019-06-24 17:42:45.886 java[1950:42575] pid(1950)/euid(502) is calling TIS/TSM in non-main thread environment, ERROR : This is NOT allowed. Please call TIS/TSM in main thread!!!
        2019-06-24 17:42:45.886 java[1950:42575] pid(1950)/euid(502) is calling TIS/TSM in non-main thread environment, ERROR : This is NOT allowed. Please call TIS/TSM in main thread!!!
        Test end

        ---

        > jdk-11.0.3.jdk/Contents/Home/bin/java -showversion NonMainThreadTest

        java version "11.0.3" 2019-04-16 LTS
        Java(TM) SE Runtime Environment 18.9 (build 11.0.3+12-LTS)
        Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.3+12-LTS, mixed mode)
        Test start
        2019-06-24 17:43:12.137 java[1952:42798] pid(1952)/euid(502) is calling TIS/TSM in non-main thread environment, ERROR : This is NOT allowed. Please call TIS/TSM in main thread!!!
        2019-06-24 17:43:12.137 java[1952:42798] pid(1952)/euid(502) is calling TIS/TSM in non-main thread environment, ERROR : This is NOT allowed. Please call TIS/TSM in main thread!!!
        2019-06-24 17:43:12.138 java[1952:42798] pid(1952)/euid(502) is calling TIS/TSM in non-main thread environment, ERROR : This is NOT allowed. Please call TIS/TSM in main thread!!!
        2019-06-24 17:43:12.138 java[1952:42798] pid(1952)/euid(502) is calling TIS/TSM in non-main thread environment, ERROR : This is NOT allowed. Please call TIS/TSM in main thread!!!
        Test end

        ---

        > jdk-12.0.1.jdk/Contents/Home/bin/java -showversion NonMainThreadTest

        java version "12.0.1" 2019-04-16
        Java(TM) SE Runtime Environment (build 12.0.1+12)
        Java HotSpot(TM) 64-Bit Server VM (build 12.0.1+12, mixed mode, sharing)
        Test start
        2019-06-24 17:43:27.710 java[1953:42931] pid(1953)/euid(502) is calling TIS/TSM in non-main thread environment, ERROR : This is NOT allowed. Please call TIS/TSM in main thread!!!
        2019-06-24 17:43:27.710 java[1953:42931] pid(1953)/euid(502) is calling TIS/TSM in non-main thread environment, ERROR : This is NOT allowed. Please call TIS/TSM in main thread!!!
        ...
        2019-06-24 17:43:27.712 java[1953:42931] pid(1953)/euid(502) is calling TIS/TSM in non-main thread environment, ERROR : This is NOT allowed. Please call TIS/TSM in main thread!!!
        Test end

        ---

        ---------- BEGIN SOURCE ----------
        ---

        import java.awt.Frame;
        import java.awt.Robot;
        import java.awt.event.KeyEvent;

        public class NonMainThreadTest {

            public static void main(String[] args) throws Exception {
                System.out.println("Test start");

                Frame frame = new Frame();
                frame.setSize(100, 100);
                frame.setVisible(true);

                Robot robot = new Robot();
                robot.setAutoDelay(100);
                int anyKey = KeyEvent.VK_ESCAPE;
                robot.keyPress(anyKey);
                robot.keyRelease(anyKey);
                robot.waitForIdle();

                frame.dispose();

                System.out.println("Test end");
            }
        }

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

        FREQUENCY : always


        Attachments

          Issue Links

            Activity

              People

                serb Sergey Bylokhov
                webbuggrp Webbug Group
                Votes:
                0 Vote for this issue
                Watchers:
                10 Start watching this issue

                Dates

                  Created:
                  Updated:
                  Resolved: