sikuli-driver team mailing list archive
-
sikuli-driver team
-
Mailing list archive
-
Message #59495
[Bug 2060175] Re: Mouse location throws NullPointerException
Hi Peter,
I incorporated your suggestion in Pull Request 630:
https://github.com/RaiMan/SikuliX1/pull/630
We'll see if/when it gets merged in.
--
You received this bug notification because you are a member of Sikuli
Drivers, which is subscribed to SikuliX.
https://bugs.launchpad.net/bugs/2060175
Title:
Mouse location throws NullPointerException
Status in SikuliX:
New
Bug description:
1. The version of Sikuli you were using.
2.0.5
2. Your operating system, 32-bit or 64-bit, and its version.
MS Windows 11, 64-bit
3. The procedure to reproduce the bug.
Mouse.at().getPoint()
4. Any information that might help us to locate the bug.
See below :-)
I'm using Jython with Sikulix, and am trying to get information about the Mouse location with a call such as this:
mouse_off_scr = scr.getBounds().contains(Mouse.at().getPoint())
However, this frequently results in a NullPointerException being
thrown within the Java library, and (now sure why) I can't even catch
the error with a try/except BaseException. I did a bit of digging into
the Java code, and found the culprit within the Device class method
getLocation().
public Location getLocation() {
PointerInfo mp = MouseInfo.getPointerInfo();
if (mp != null) {
return new Location(MouseInfo.getPointerInfo().getLocation());
} else {
Debug.error("Mouse: not possible to get mouse position (PointerInfo == null)");
return null;
}
}
It looks like there is some code in place to avoid the NPE. Even
though it's checking for a null return value from
MouseInfo.getPointerInfo(), the method gets called a second time and
that's when the NPE occurs. I think the method should probably be
corrected as follows:
public Location getLocation() {
PointerInfo mp = MouseInfo.getPointerInfo();
if (mp != null) {
return new Location(mp.getLocation());
} else {
Debug.error("Mouse: not possible to get mouse position (PointerInfo == null)");
return null;
}
}
That may result is very slightly "outdated" mouse information, but at
least it would avoid crashing the program. :-)
To manage notifications about this bug go to:
https://bugs.launchpad.net/sikuli/+bug/2060175/+subscriptions
Follow ups
References