RFR: 8345538: Robot.mouseMove doesn't clamp bounds on macOS when trying to move mouse off screen [v3]

Phil Race prr at openjdk.org
Fri Dec 20 20:53:38 UTC 2024


On Fri, 20 Dec 2024 20:43:37 GMT, Alexey Ivanov <aivanov at openjdk.org> wrote:

>> In MouseInfo.getPointerInfo()
>> The point is updated here [fillPointWithCoords()](https://github.com/openjdk/jdk/blob/7ba969a576eb92446e40587fecf98e1e4aba8883/src/java.desktop/share/classes/java/awt/MouseInfo.java#L72) .
>> 
>> and what follows after
>> 
>> 
>> for (int i = 0; i < gds.length; i++) {
>>                 GraphicsConfiguration gc = gds[i].getDefaultConfiguration();
>>                 Rectangle bounds = gc.getBounds();
>>                 if (bounds.contains(point)) { 
>>                  // checks if the point updated by  fillPointWithCoords
>>                   // is within the bounds of any of the  screen device else it returns null
>>                     retval = new PointerInfo(gds[i], point);
>>                 }
>>             }
>
> I ran it on Windows, sorry I should've said it explicitly.

> Displays: 2 Placement: Side-by-side, with the bottom edge aligned as below
> 
> <img alt="image" width="478" src="https://private-user-images.githubusercontent.com/95945681/397856615-7ea5be69-989f-42b5-ac26-631d170d8db0.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzQ3Mjc0NjMsIm5iZiI6MTczNDcyNzE2MywicGF0aCI6Ii85NTk0NTY4MS8zOTc4NTY2MTUtN2VhNWJlNjktOTg5Zi00MmI1LWFjMjYtNjMxZDE3MGQ4ZGIwLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDEyMjAlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQxMjIwVDIwMzkyM1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWZhYWUzZWNkZWZjOGFiZTRjMWE4ODgxMjhhYjE3N2E4NWRkOTA2MmI0MzMyZWJmNmExYTJmODA0ZjgzZGJmMmUmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.vGpCyq1K_5DGxJ-rZPPp5PosfvP4Q90l-3hIAWb1E7M">
> Screen bounds: Win32GraphicsDevice[screen=0]:java.awt.Rectangle[x=-1920,y=363,width=1280,height=720] Win32GraphicsDevice[screen=1]:java.awt.Rectangle[x=0,y=0,width=2293,height=960]
> 
> Stack Trace: ----------System.err:(11/959)---------- java.lang.NullPointerException: Cannot invoke "java.awt.PointerInfo.getLocation()" because the return value of "java.awt.MouseInfo.getPointerInfo()" is null at MouseMoveOffScreen.main(MouseMoveOffScreen.java:57) at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104) at java.base/java.lang.reflect.Method.invoke(Method.java:565) at com.sun.javatest.regtest.agent.MainWrapper$MainTask.run(MainWrapper.java:138) at java.base/java.lang.Thread.run(Thread.java:1447)
> 
> JavaTest Message: Test threw exception: java.lang.NullPointerException: Cannot invoke "java.awt.PointerInfo.getLocation()" because the return value of "java.awt.MouseInfo.getPointerInfo()" is null JavaTest Message: shutting down test

The stack trace wasn't as revealing as I hoped. But the monitor config may tell us something.
(0, 200) is a location that is off the top of screen 1, so not within the virtual bounds.
But it is interesting that you get NPE before the fix as well .. perhaps the windows clamping isn't happening as Alisen said. I think we need to understand that as the next step.

After that , since it looks to me like the bounds of all screens need to be looked at to clamp because we can't rely on a single rectangle defining it even if there's a single virtual screen, and need to look at the union.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/22781#discussion_r1894379782


More information about the client-libs-dev mailing list