On Sat, 17 May 2025 00:03:23 GMT, Harshitha Onkar <hon...@openjdk.org> wrote:

> CopyAreaOOB.java was failing intermittently on some platforms on CI but 
> recently it started to fail more frequently on macos-aarch64 when the entire 
> test suite runs.
> 
> Test failure is not reproducible when the test is run individually (multiple 
> times) on CI.
> 
> Rewritten the test and added debug logs that will be helpful to figure out 
> the issue. 
> 
> - Added code to capture screenshot (entire screen as well as the frame) in 
> case of failure.
> - Since it tests multiple regions added a StringBuffer to consolidate the 
> error logs before throwing RuntimeException.

test/jdk/java/awt/Graphics2D/CopyAreaOOB.java line 67:

> 65:                 Point pt1 = frame.getLocationOnScreen();
> 66:                 Rectangle rect = new Rectangle(pt1.x, pt1.y, 400, 400);
> 67:                 captureImg = robot.createScreenCapture(rect);

~~The captured image includes the frame decorations.~~ I see the frame is not 
decorated. Yet, the suggestion still applies.

You can use the location and the size of the canvas itself as the area to 
capture. For simplicity, save the canvas instance into a static variable.

I'd avoid hard-coding the width and height like this; constants would be serve 
the purpose, and if either width or height, or both, changes, all the code 
automatically updates to use the new values.

test/jdk/java/awt/Graphics2D/CopyAreaOOB.java line 114:

> 112:         // destination surface
> 113:         g2d.copyArea(0, 10, 50, h - 10, 60, 10);
> 114:         g2d.dispose();

Why do you disposed of `g2d`? It's a parameter that's passed to you as argument 
to the `paint` method.

test/jdk/java/awt/Graphics2D/CopyAreaOOB.java line 147:

> 145:                 .getLocalGraphicsEnvironment().getDefaultScreenDevice()
> 146:                 .getDefaultConfiguration();
> 147:         BufferedImage screenCapture = 
> robot.createScreenCapture(ge.getBounds());

Using a multi-resolution screen capture could shed some light on failures… If 
Mac uses a Retina-like display, the captured image is scaled down, which 
affects the colors on the image.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/25279#discussion_r2112341094
PR Review Comment: https://git.openjdk.org/jdk/pull/25279#discussion_r2112326767
PR Review Comment: https://git.openjdk.org/jdk/pull/25279#discussion_r2112330528

Reply via email to