mirror of
https://github.com/JetBrains/JetBrainsRuntime.git
synced 2026-01-15 04:51:43 +01:00
JRE-624 CThreading isAppKit() fails to detect main app thread if it was renamed
(cherry picked from commitc8f248a936) with fix for JBR-5300 Change source code and test files to use GPL license (cherry picked from commit9aa93e5907)
This commit is contained in:
74
test/jdk/jb/sun/lwawt/macosx/CThreading/IsAppKit.java
Normal file
74
test/jdk/jb/sun/lwawt/macosx/CThreading/IsAppKit.java
Normal file
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Copyright 2000-2023 JetBrains s.r.o.
|
||||
* 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
|
||||
* @summary regression test on JRE-624 CThreading.isAppKit() fails to detect main app thread if it was renamed
|
||||
* @compile -XDignore.symbol.file IsAppKit.java
|
||||
* @run main/othervm IsAppKit
|
||||
*/
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.concurrent.*;
|
||||
import sun.lwawt.macosx.*;
|
||||
|
||||
/*
|
||||
* Description: The test checks detection of the main application thread
|
||||
*
|
||||
*/
|
||||
|
||||
public class IsAppKit {
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
final CountDownLatch counter = new CountDownLatch(1);
|
||||
|
||||
SwingUtilities.invokeAndWait(() -> {
|
||||
JFrame frame = new JFrame();
|
||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
frame.pack();
|
||||
frame.setVisible(true);
|
||||
counter.countDown();
|
||||
});
|
||||
|
||||
counter.await();
|
||||
|
||||
CThreading.privilegedExecuteOnAppKit(() -> {
|
||||
String name = Thread.currentThread().getName();
|
||||
if (!"AWT-AppKit".equals(name)) {
|
||||
throw new RuntimeException("Unexpected thread name: " + name);
|
||||
}
|
||||
|
||||
Thread.currentThread().setName("Some other thread name");
|
||||
return null;
|
||||
});
|
||||
|
||||
|
||||
String name = CThreading.privilegedExecuteOnAppKit(() -> {
|
||||
return Thread.currentThread().getName();
|
||||
});
|
||||
|
||||
if (!"AWT-AppKit".equals(name)) {
|
||||
throw new RuntimeException("Unexpected thread name: " + name);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user