Skip to content

Commit 6d2b9c9

Browse files
truptipatil-13shipilev
authored andcommitted
8355478: DoubleActionESC.java fails intermittently
Backport-of: d1052c70cbddb025e7f5b71bd61176e63277bba0
1 parent 3db9097 commit 6d2b9c9

File tree

2 files changed

+27
-22
lines changed

2 files changed

+27
-22
lines changed

test/jdk/ProblemList.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -813,6 +813,7 @@ java/awt/font/GlyphVector/TestGlyphVectorLayout.java 8354987 generic-all
813813
java/awt/font/TextLayout/TestJustification.java 8250791 macosx-all
814814
java/awt/TrayIcon/DragEventSource/DragEventSource.java 8252242 macosx-all
815815
java/awt/FileDialog/DefaultFocusOwner/DefaultFocusOwner.java 7187728 macosx-all,linux-all
816+
java/awt/FileDialog/DoubleActionESC.java 8356981 linux-all
816817
java/awt/print/PageFormat/Orient.java 8016055 macosx-all
817818
java/awt/TextArea/TextAreaCursorTest/HoveringAndDraggingTest.java 8024986 macosx-all,linux-all
818819
java/awt/TextComponent/CorrectTextComponentSelectionTest.java 8237220 macosx-all

test/jdk/java/awt/FileDialog/DoubleActionESC.java

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2005, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2005, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -34,12 +34,15 @@
3434
import java.awt.event.KeyEvent;
3535
import java.util.concurrent.CountDownLatch;
3636

37+
import static java.util.concurrent.TimeUnit.SECONDS;
38+
3739
/*
3840
* @test
3941
* @bug 5097243
4042
* @summary Tests that FileDialog can be closed by ESC any time
4143
* @key headful
4244
* @run main DoubleActionESC
45+
* @run main/othervm -Dsun.awt.disableGtkFileDialogs=true DoubleActionESC
4346
*/
4447

4548
public class DoubleActionESC {
@@ -49,47 +52,48 @@ public class DoubleActionESC {
4952
private static Robot robot;
5053
private static volatile Point p;
5154
private static volatile Dimension d;
52-
private static volatile CountDownLatch latch;
5355
private static final int REPEAT_COUNT = 2;
56+
private static final long LATCH_TIMEOUT = 10;
5457

55-
public static void main(String[] args) throws Exception {
56-
latch = new CountDownLatch(1);
58+
private static final CountDownLatch latch = new CountDownLatch(REPEAT_COUNT);
5759

60+
public static void main(String[] args) throws Exception {
5861
robot = new Robot();
59-
robot.setAutoDelay(100);
62+
robot.setAutoDelay(50);
6063
try {
6164
EventQueue.invokeAndWait(() -> {
6265
createAndShowUI();
6366
});
6467

68+
robot.waitForIdle();
6569
robot.delay(1000);
70+
6671
EventQueue.invokeAndWait(() -> {
6772
p = showBtn.getLocationOnScreen();
6873
d = showBtn.getSize();
6974
});
7075

7176
for (int i = 0; i < REPEAT_COUNT; ++i) {
72-
Thread thread = new Thread(() -> {
73-
robot.mouseMove(p.x + d.width / 2, p.y + d.height / 2);
74-
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
75-
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
76-
});
77-
thread.start();
78-
robot.delay(3000);
77+
robot.mouseMove(p.x + d.width / 2, p.y + d.height / 2);
78+
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
79+
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
80+
robot.waitForIdle();
81+
robot.delay(1000);
7982

80-
Thread thread1 = new Thread(() -> {
81-
robot.keyPress(KeyEvent.VK_ESCAPE);
82-
robot.keyRelease(KeyEvent.VK_ESCAPE);
83-
robot.waitForIdle();
84-
});
85-
thread1.start();
86-
robot.delay(3000);
83+
robot.keyPress(KeyEvent.VK_ESCAPE);
84+
robot.keyRelease(KeyEvent.VK_ESCAPE);
85+
robot.waitForIdle();
86+
robot.delay(1000);
8787
}
8888

89-
latch.await();
90-
if (fd.isVisible()) {
91-
throw new RuntimeException("File Dialog is not closed");
89+
if (!latch.await(LATCH_TIMEOUT, SECONDS)) {
90+
throw new RuntimeException("Test failed: Latch timeout reached");
9291
}
92+
EventQueue.invokeAndWait(() -> {
93+
if (fd.isVisible()) {
94+
throw new RuntimeException("File Dialog is not closed");
95+
}
96+
});
9397
} finally {
9498
EventQueue.invokeAndWait(() -> {
9599
if (f != null) {

0 commit comments

Comments
 (0)