diff --git a/jdk/src/share/classes/java/awt/Robot.java b/jdk/src/share/classes/java/awt/Robot.java index b431e45bd9..600d2b0613 100644 --- a/jdk/src/share/classes/java/awt/Robot.java +++ b/jdk/src/share/classes/java/awt/Robot.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2023, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -61,6 +61,43 @@ *
* Applications that use Robot for purposes other than self-testing should * handle these error conditions gracefully. + *
+ * Platforms and desktop environments may impose restrictions or limitations + * on the access required to implement all functionality in the Robot class. + * For example: + *
+ * The mouse pointer may not visually move on some platforms, + * while the subsequent mousePress and mouseRelease can be + * delivered to the correct location + * * @param x X position * @param y Y position */ @@ -386,22 +428,50 @@ private void checkKeycodeArgument(int keycode) { /** * Returns the color of a pixel at the given screen coordinates. + *
+ * If the desktop environment requires that permissions be granted + * to capture screen content, and the required permissions are not granted, + * then a {@code SecurityException} may be thrown, + * or the content of the returned {@code Color} is undefined. + *
+ * @apiNote It is recommended to avoid calling this method on + * the AWT Event Dispatch Thread since screen capture may be a lengthy + * operation, particularly if acquiring permissions is needed and involves + * user interaction. + * * @param x X position of pixel * @param y Y position of pixel + * @throws SecurityException if {@code readDisplayPixels} permission + * is not granted, or access to the screen is denied + * by the desktop environment * @return Color of the pixel */ public synchronized Color getPixelColor(int x, int y) { + checkScreenCaptureAllowed(); Color color = new Color(peer.getRGBPixel(x, y)); return color; } /** - * Creates an image containing pixels read from the screen. This image does - * not include the mouse cursor. + * Creates an image containing pixels read from the screen. + *+ * If the desktop environment requires that permissions be granted + * to capture screen content, and the required permissions are not granted, + * then a {@code SecurityException} may be thrown, + * or the contents of the returned {@code BufferedImage} are undefined. + *
+ * @apiNote It is recommended to avoid calling this method on + * the AWT Event Dispatch Thread since screen capture may be a lengthy + * operation, particularly if acquiring permissions is needed and involves + * user interaction. + * * @param screenRect Rect to capture in screen coordinates * @return The captured image - * @throws IllegalArgumentException ifscreenRect width and height are not greater than zero
- * @throws SecurityException if readDisplayPixels permission is not granted
+ * @throws IllegalArgumentException if {@code screenRect} width and height
+ * are not greater than zero
+ * @throws SecurityException if {@code readDisplayPixels} permission
+ * is not granted, or access to the screen is denied
+ * by the desktop environment
* @see SecurityManager#checkPermission
* @see AWTPermission
*/