Skip to content

Commit f6ddc4b

Browse files
Amos ShiGoeLin
Amos Shi
authored andcommitted
8296083: javax/swing/JTree/6263446/bug6263446.java fails intermittently on a VM
Reviewed-by: phh Backport-of: 728dc4de173f2bb1e06b3b3574cb430621e2969b
1 parent 94bf6db commit f6ddc4b

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

test/jdk/javax/swing/JTree/6263446/bug6263446.java

+24-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2011, 2022, 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
@@ -38,7 +38,7 @@
3838

3939
public class bug6263446 {
4040

41-
private static final String FIRST = "AAAAAAAAAAA";
41+
private static final String FIRST = "AAAAA";
4242
private static final String SECOND = "BB";
4343
private static final String ALL = FIRST + " " + SECOND;
4444
private static JTree tree;
@@ -62,59 +62,75 @@ public void run() {
6262
try {
6363
Point point = getClickPoint();
6464
robot.mouseMove(point.x, point.y);
65+
robot.waitForIdle();
6566

6667
// click count 3
6768
click(1);
69+
robot.waitForIdle();
6870
assertNotEditing();
6971

7072
click(2);
73+
robot.waitForIdle();
7174
assertNotEditing();
7275

7376
click(3);
77+
robot.waitForIdle();
7478
assertEditing();
7579
cancelCellEditing();
7680
assertNotEditing();
7781

7882
click(4);
83+
robot.waitForIdle();
7984
checkSelectedText(FIRST);
8085

8186
click(5);
87+
robot.waitForIdle();
8288
checkSelectedText(ALL);
8389

8490
// click count 4
8591
setClickCountToStart(4);
92+
robot.waitForIdle();
8693

8794
click(1);
95+
robot.waitForIdle();
8896
assertNotEditing();
8997

9098
click(2);
99+
robot.waitForIdle();
91100
assertNotEditing();
92101

93102
click(3);
103+
robot.waitForIdle();
94104
assertNotEditing();
95105

96106
click(4);
107+
robot.waitForIdle();
97108
assertEditing();
98109
cancelCellEditing();
99110
assertNotEditing();
100111

101112
click(5);
113+
robot.waitForIdle();
102114
checkSelectedText(FIRST);
103115

104116
click(6);
117+
robot.waitForIdle();
105118
checkSelectedText(ALL);
106119

107120
// start path editing
108121
startPathEditing();
109122
assertEditing();
110123

111124
click(1);
125+
robot.waitForIdle();
112126
checkSelection(null);
113127

114128
click(2);
129+
robot.waitForIdle();
115130
checkSelection(FIRST);
116131

117132
click(3);
133+
robot.waitForIdle();
118134
checkSelection(ALL);
119135
} finally {
120136
if (frame != null) {
@@ -128,7 +144,6 @@ private static void click(int times) {
128144
for (int i = 0; i < times; i++) {
129145
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
130146
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
131-
robot.waitForIdle();
132147
}
133148
}
134149

@@ -141,7 +156,7 @@ private static Point getClickPoint() throws Exception {
141156
public void run() {
142157
Rectangle rect = tree.getRowBounds(0);
143158
// UPDATE !!!
144-
Point p = new Point(rect.x + rect.width / 2, rect.y + 2);
159+
Point p = new Point(rect.x + rect.width/2, rect.y + rect.height/2);
145160
SwingUtilities.convertPointToScreen(p, tree);
146161
result[0] = p;
147162

@@ -166,9 +181,11 @@ private static void createAndShowGUI() {
166181

167182

168183
frame.getContentPane().add(tree);
184+
frame.setAlwaysOnTop(true);
169185
frame.pack();
170186
frame.setLocationRelativeTo(null);
171187
frame.setVisible(true);
188+
frame.toFront();
172189
}
173190

174191
private static void setClickCountToStart(final int clicks) throws Exception {
@@ -183,6 +200,7 @@ public void run() {
183200
field.setAccessible(true);
184201
DefaultCellEditor ce = (DefaultCellEditor) field.get(editor);
185202
ce.setClickCountToStart(clicks);
203+
186204
} catch (IllegalAccessException e) {
187205
throw new RuntimeException(e);
188206
} catch (NoSuchFieldException e) {
@@ -248,7 +266,9 @@ public void run() {
248266
private static void checkSelectedText(String sel) throws Exception {
249267
assertEditing();
250268
checkSelection(sel);
269+
robot.waitForIdle();
251270
cancelCellEditing();
271+
robot.waitForIdle();
252272
assertNotEditing();
253273
}
254274

0 commit comments

Comments
 (0)