Skip to content

Commit 497dca2

Browse files
committed
8378153: Robot.getPixelColor() may return stale pixels due to missing Toolkit.sync()
Reviewed-by: prr, azvegint
1 parent a35945a commit 497dca2

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/java.desktop/share/classes/java/awt/Robot.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1999, 2025, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1999, 2026, 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
@@ -459,6 +459,9 @@ private static void checkKeycodeArgument(int keycode) {
459459
* @return Color of the pixel
460460
*/
461461
public synchronized Color getPixelColor(int x, int y) {
462+
// need to sync the toolkit prior to grabbing the pixels since in some
463+
// cases rendering to the screen may be delayed
464+
Toolkit.getDefaultToolkit().sync();
462465
Point point = peer.useAbsoluteCoordinates() ? toDeviceSpaceAbs(x, y)
463466
: toDeviceSpace(x, y);
464467
return new Color(peer.getRGBPixel(point.x, point.y));

0 commit comments

Comments
 (0)