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

Harshitha Onkar honkar at openjdk.org
Fri Dec 20 20:46:36 UTC 2024


On Fri, 20 Dec 2024 20:37:58 GMT, Phil Race <prr at openjdk.org> wrote:

>> Displays: 2 
>> Placement: Side-by-side, with the bottom edge aligned as below
>> 
>> <img width="478" alt="image" src="https://github.com/user-attachments/assets/7ea5be69-989f-42b5-ac26-631d170d8db0" />
>> 
>> 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
>
>> For me, the test _without the fix_ prints
>> 
>> ```
>> Current mouse location: java.awt.Point[x=0,y=200]
>> ```
>> 
>> The mouse cursor moves to 200, 200 and then to 0, 200 on the screen.
> 
> 
> What platform ? Alisen did say in the description that Windows & Linux clamp which presumably is either something elsewhere in the JDK implementation, or just how the platform works. I looked (briefly) at Linux and we just pass the values to XWarpPointer so I assumed it was the platform ..

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);
                }
            }

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

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


More information about the client-libs-dev mailing list