Skip to content

Commit 5a3e86c

Browse files
committed
7001973: java/awt/Graphics2D/CopyAreaOOB.java fails
Backport-of: 22b7295e75d3bc7ba2c2cd7b871bb2bb5bf290eb
1 parent f614119 commit 5a3e86c

File tree

2 files changed

+21
-46
lines changed

2 files changed

+21
-46
lines changed

test/jdk/ProblemList.txt

-1
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,6 @@ sun/awt/shell/FileSystemViewMemoryLeak.java 8241806 windows-all
223223
sun/java2d/DirectX/OnScreenRenderingResizeTest/OnScreenRenderingResizeTest.java 8022403 generic-all
224224
sun/java2d/DirectX/OverriddenInsetsTest/OverriddenInsetsTest.java 8196102 generic-all
225225
sun/java2d/DirectX/RenderingToCachedGraphicsTest/RenderingToCachedGraphicsTest.java 8196180 windows-all
226-
java/awt/Graphics2D/CopyAreaOOB.java 7001973 windows-all,macosx-all
227226
sun/java2d/SunGraphics2D/EmptyClipRenderingTest.java 8144029 macosx-all
228227
sun/java2d/SunGraphics2D/DrawImageBilinear.java 8191406 generic-all
229228
sun/java2d/SunGraphics2D/PolyVertTest.java 6986565 generic-all

test/jdk/java/awt/Graphics2D/CopyAreaOOB.java

+21-45
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2021 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
@@ -36,15 +36,9 @@
3636

3737
public class CopyAreaOOB extends Canvas {
3838

39-
private static boolean done;
39+
private static Robot robot = null;
4040

4141
public void paint(Graphics g) {
42-
synchronized (this) {
43-
if (done) {
44-
return;
45-
}
46-
}
47-
4842
int w = getWidth();
4943
int h = getHeight();
5044

@@ -64,10 +58,23 @@ public void paint(Graphics g) {
6458

6559
Toolkit.getDefaultToolkit().sync();
6660

67-
synchronized (this) {
68-
done = true;
69-
notifyAll();
61+
BufferedImage capture = null;
62+
try {
63+
Thread.sleep(500);
64+
if (robot == null) robot = new Robot();
65+
Point pt1 = getLocationOnScreen();
66+
Rectangle rect = new Rectangle(pt1.x, pt1.y, 400, 400);
67+
capture = robot.createScreenCapture(rect);
68+
} catch (Exception e) {
69+
throw new RuntimeException("Problems handling Robot");
7070
}
71+
// Test pixels
72+
testRegion(capture, "green", 0, 0, 400, 10, 0xff00ff00);
73+
testRegion(capture, "original red", 0, 10, 50, 400, 0xffff0000);
74+
testRegion(capture, "background", 50, 10, 60, 400, 0xff000000);
75+
testRegion(capture, "in-between", 60, 10, 110, 20, 0xff000000);
76+
testRegion(capture, "copied red", 60, 20, 110, 400, 0xffff0000);
77+
testRegion(capture, "background", 110, 10, 400, 400, 0xff000000);
7178
}
7279

7380
public Dimension getPreferredSize() {
@@ -105,42 +112,11 @@ public static void main(String[] args) {
105112
frame.setLocationRelativeTo(null);
106113
frame.setVisible(true);
107114

108-
// Wait until the component's been painted
109-
synchronized (test) {
110-
while (!done) {
111-
try {
112-
test.wait();
113-
} catch (InterruptedException e) {
114-
throw new RuntimeException("Failed: Interrupted");
115-
}
116-
}
117-
}
118-
119115
try {
120-
Thread.sleep(2000);
116+
Thread.sleep(3000);
121117
} catch (InterruptedException ex) {}
122-
123-
// Grab the screen region
124-
BufferedImage capture = null;
125-
try {
126-
Robot robot = new Robot();
127-
Point pt1 = test.getLocationOnScreen();
128-
Rectangle rect = new Rectangle(pt1.x, pt1.y, 400, 400);
129-
capture = robot.createScreenCapture(rect);
130-
} catch (Exception e) {
131-
throw new RuntimeException("Problems creating Robot");
132-
} finally {
133-
if (!show) {
134-
frame.dispose();
135-
}
118+
if (!show) {
119+
frame.dispose();
136120
}
137-
138-
// Test pixels
139-
testRegion(capture, "green", 0, 0, 400, 10, 0xff00ff00);
140-
testRegion(capture, "original red", 0, 10, 50, 400, 0xffff0000);
141-
testRegion(capture, "background", 50, 10, 60, 400, 0xff000000);
142-
testRegion(capture, "in-between", 60, 10, 110, 20, 0xff000000);
143-
testRegion(capture, "copied red", 60, 20, 110, 400, 0xffff0000);
144-
testRegion(capture, "background", 110, 10, 400, 400, 0xff000000);
145121
}
146122
}

0 commit comments

Comments
 (0)