Mac: NullPointerException when running via ssh

Asked by Ilya Anshmidt

Sikuli versions: 1.1.2, 1.1.3
Mac OS: 10.13, 10.12, 10.10
Java versions: 1.8, 1.9

My sikuli script works fine when I run it from Sikuli IDE and from command line (without IDE).
But when I connect via ssh to the Mac where Sikuli is installed and run the same script, it fails with an error:
[error] script [ /Users/shareduser/<path-to-script>/click_button.sikuli ] stopped with error in line 1
[error] java.lang.NullPointerException ( java.lang.NullPointerException )

The script 'click_button.sikuli' itself is very simple:
click(<my image>)

How do I run the script from command line:
java -jar /Applications/SikuliX.app/Contents/Java/sikulix.jar -r /Users/shareduser/<path-to-script>/click_button.sikuli
(it works fine)

How do I run the same script when I connect via ssh (I run the following command on a different Mac to run the script on the Mac where Sikuli is installed):
ssh shareduser@192.168.1.224 'java -jar /Applications/SikuliX.app/Contents/Java/sikulix.jar -r /Users/shareduser/<path-to-script>/click_button.sikuli'
(it fails with NullPointerException, see full error text above)

I've tried different versions of Java, Mac OS and Sikuli, but the result is always the same.
I'm out of options now.

Any help will be highly appreciated.

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
Ilya Anshmidt
Solved:
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

should first be a question

Revision history for this message
RaiMan (raimund-hocke) said :
#2

If I understand right:
The machine where the script is run is always the same.
Only in the second case it is accessed via ssh from another machine.

please confirm.

Revision history for this message
RaiMan (raimund-hocke) said :
#3

please run with debug option so:
 'java -Dsikuli.Debug=3 -jar /Applications/SikuliX.app/Contents/Java/sikulix.jar -r /Users/shareduser/<path-to-script>/click_button.sikuli'

and use version 1.1.3 preferably on Java 8

Revision history for this message
Ilya Anshmidt (i.anshmidt) said :
#4

Regarding your first question:
I have Sikuli installed on 3 machines.
When I run the script directly on any of these machines, it works fine.

When I access and run the script on any of these machines from another (4th) machine via ssh, Sikuli fails with an error.

Revision history for this message
Ilya Anshmidt (i.anshmidt) said :
#5

Regarding your second comment:

Thank you, I've tried running with debug option, and looks like the issue is caused by Jython getting screen size incorrectly when running script via ssh.

Output when I run the script directly on the machine:

[error] RunTimeINIT: *** BE AWARE: Running on Java 8+ *** Please report problems ***
[debug] RunTimeINIT: loadOptions: check: /Users/shareduser/Downloads/RF_Mac_automation/scripts
[debug] RunTimeINIT: loadOptions: check: /Users/shareduser
[debug] RunTimeINIT: loadOptions: check: /Users/shareduser/Library/Application Support/Sikulix/SikulixStore
[debug] RunTimeINIT: global init: entering as: IDE
[debug] RunTimeINIT: Accessing: GraphicsEnvironment.getLocalGraphicsEnvironment()
[debug] RunTimeINIT: Accessing: GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices()
[debug] RunTimeINIT: ScreenDevice 0 has (0,0) --- will be primary Screen(0)
[debug] RunTimeINIT: Monitor 0: (0, 0) 1680 x 1050
[debug] RunTimeINIT: runs as sikulix.jar in: /Applications/SikuliX.app/Contents/Java
[debug] RunTimeINIT: exists libs folder at: /Users/shareduser/Library/Application Support/Sikulix/SikulixLibs_201804041055
***** show environment for IDE (build 201804041055)
user.home: /Users/shareduser
user.dir (work dir): /Users/shareduser/Downloads/RF_Mac_automation/scripts
user.name: shareduser
java.io.tmpdir: /var/folders/05/953xk3vn0k7_ds769f4fst800000gp/T
running 64Bit on Mac OSX (10.12.6) as application .app
java 9-64 version 9.0.4 vm 9.0.4+11 class 53.0 arch x86_64
app data folder: /Users/shareduser/Library/Application Support/Sikulix
libs folder: /Users/shareduser/Library/Application Support/Sikulix/SikulixLibs_201804041055
executing jar: /Applications/SikuliX.app/Contents/Java/sikulix.jar
[error] RunTimeIDE: *** Java 8+: skipped: dumpClassPath()
***** show environment end
[debug] RunTimeIDE: global init: leaving
[debug] RunTimeIDE: initIDEbefore: entering
[debug] RunTimeIDE: initIDEbefore: leaving
[debug] RunTimeIDE: initAPI: entering
[debug] RunTimeIDE: resourceList: enter
[debug] RunTimeIDE: resourceLocation: (class org.sikuli.ide.SikuliIDE) /Lib/sikuli
[debug] RunTimeIDE: resourceList: having jar: jar:file:/Applications/SikuliX.app/Contents/Java/sikulix.jar!/Lib/sikuli
[debug] RunTimeIDE: files exported: 7 from: Lib/sikuli to:
 /Users/shareduser/Library/Application Support/Sikulix/Lib/sikuli
[debug] RunTimeIDE: initAPI: leaving
[debug] IDE: Switching to ScriptRunner with option -r, -t or -i
[debug] Runner: commandline:
[debug] --- Sikuli parameters ---
[debug] 1: -r
[debug] 2: /Users/shareduser/PycharmProjects/RF_Mac_Tests/pages/editor/sikuli/click_safenotes.sikuli
[debug] ScriptingSupport: givenScriptName:
/Users/shareduser/PycharmProjects/RF_Mac_Tests/pages/editor/sikuli/click_safenotes.sikuli
[debug] ScriptingSupport: Trying to run script:
/Users/shareduser/PycharmProjects/RF_Mac_Tests/pages/editor/sikuli/click_safenotes.sikuli/click_safenotes.py
[debug] ScriptingSupport: initScriptingSupport: enter
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.python.core.PySystemState (file:/Applications/SikuliX.app/Contents/Java/sikulix.jar) to method java.io.Console.encoding()
WARNING: Please consider reporting this to the maintainers of org.python.core.PySystemState
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
[debug] JythonSupport: init: starting
[debug] JythonSupport: init: success
[debug] JythonSupport: added as Jython::sys.path[0]:
/Users/shareduser/Library/Application Support/Sikulix/Lib/site-packages
[debug] JythonSupport: ***** Jython sys.path
 0: /Users/shareduser/Library/Application Support/Sikulix/Lib/site-packages
 1: /Users/shareduser/Library/Application Support/Sikulix/Lib
 2: /Applications/SikuliX.app/Contents/Java/Lib
 3: /Applications/SikuliX.app/Contents/Java/sikulix.jar/Lib
 4: __classpath__
 5: __pyclasspath__/
[debug] JythonSupport: ***** Jython sys.path end
[debug] Jython: sikuli: Sikuli: starting init
[debug] RunTimeIDE: loadLib: libVisionProxy.dylib
[debug] Mouse: init start
[debug] Mouse: init end
[debug] RunTimeIDE: loadLib: libMacUtil.dylib
[debug] Jython: requested to use as default region: S(0)[0,0 1680x1050]
[debug] Jython: sikuli: Sikuli: ending init
[debug] JythonScriptRunner: running Jython 2.7.1
[debug] ScriptingSupport: initScriptingSupport: added: jython
[debug] ScriptingSupport: initScriptingSupport: added: JavaScript
[debug] ScriptingSupport: initScriptingSupport: exit with defaultrunner: jython (py)
[debug] ImagePath: new BundlePath:
/Users/shareduser/PycharmProjects/RF_Mac_Tests/pages/editor/sikuli/click_safenotes.sikuli/
[debug] Jython: requested to use as default region: S(0)[0,0 1680x1050]
[debug] JythonScriptRunner: runPython: running script:
/Users/shareduser/PycharmProjects/RF_Mac_Tests/pages/editor/sikuli/click_safenotes.sikuli
[debug] Image: loaded: 1522143552641.png (file:/Users/shareduser/PycharmProjects/RF_Mac_Tests/pages/editor/sikuli/click_safenotes.sikuli/1522143552641.png)
[debug] Image: cached: 1522143552641.png (6 KB) (# 1 KB 6 -- 0 % of 64 MB)
[debug] Region: wait: waiting 3.0 secs for 1522143552641.png to appear in S(0)[0,0 1680x1050]
[debug] Region: wait: 1522143552641.png appeared (M[45,316 108x20]@S(S(0)[0,0 1680x1050]) S:1.00 C:99,326 [992 msec])
[debug] Region: init: (0, 0, 5, 5)
[debug] CLICK on L(99,326)@S(0)[0,0 1680x1050] (1024 msec)
[debug] RunTimeIDE: final cleanup
[debug] FileManager: deleteFileOrFolder:
/var/folders/05/953xk3vn0k7_ds769f4fst800000gp/T/Sikulix_507924032

Output of the same script on the same machine, when I access and run it via ssh from another machine:

[debug] RunTimeINIT: loadOptions: check: /Users/shareduser
[debug] RunTimeINIT: loadOptions: check: /Users/shareduser
[debug] RunTimeINIT: loadOptions: check: /Users/shareduser/Library/Application Support/Sikulix/SikulixStore
[debug] RunTimeINIT: global init: entering as: IDE
[debug] RunTimeINIT: running in headless environment
[debug] RunTimeINIT: runs as sikulix.jar in: /Applications/SikuliX.app/Contents/Java
[debug] RunTimeINIT: exists libs folder at: /Users/shareduser/Library/Application Support/Sikulix/SikulixLibs_201803080837
***** show environment for IDE (build 201803080837)
user.home: /Users/shareduser
user.dir (work dir): /Users/shareduser
user.name: shareduser
java.io.tmpdir: /var/folders/31/srmmps8x0td7l97qp41d5_dw0000gp/T
running 64Bit on Mac OSX (10.10.5) as application .app
java 8-64 version 1.8.0_101-b13 vm 25.101-b13 class 52.0 arch x86_64
app data folder: /Users/shareduser/Library/Application Support/Sikulix
libs folder: /Users/shareduser/Library/Application Support/Sikulix/SikulixLibs_201803080837
executing jar: /Applications/SikuliX.app/Contents/Java/sikulix.jar
*** classpath dump sikulix
  0: /Applications/SikuliX.app/Contents/Java/sikulix.jar
*** classpath dump end
***** show environment end
[debug] RunTimeIDE: global init: leaving
[debug] RunTimeIDE: initIDEbefore: entering
[debug] RunTimeIDE: initIDEbefore: leaving
[debug] RunTimeIDE: initAPI: entering
[debug] RunTimeIDE: resourceList: enter
[debug] RunTimeIDE: resourceLocation: (class org.sikuli.ide.SikuliIDE) /Lib/sikuli
[debug] RunTimeIDE: resourceList: having jar: jar:file:/Applications/SikuliX.app/Contents/Java/sikulix.jar!/Lib/sikuli
[debug] RunTimeIDE: files exported: 7 from: Lib/sikuli to:
 /Users/shareduser/Library/Application Support/Sikulix/Lib/sikuli
[debug] RunTimeIDE: initAPI: leaving
[debug] IDE: Switching to ScriptRunner with option -r, -t or -i
[debug] Runner: commandline:
[debug] --- Sikuli parameters ---
[debug] 1: -r
[debug] 2: /Users/shareduser/PycharmProjects/RF_Mac_Tests/pages/editor/sikuli/click_safenotes.sikuli
[debug] ScriptingSupport: givenScriptName:
/Users/shareduser/PycharmProjects/RF_Mac_Tests/pages/editor/sikuli/click_safenotes.sikuli
[debug] ScriptingSupport: Trying to run script:
/Users/shareduser/PycharmProjects/RF_Mac_Tests/pages/editor/sikuli/click_safenotes.sikuli/click_safenotes.py
[debug] ScriptingSupport: initScriptingSupport: enter
[debug] JythonSupport: init: starting
[debug] JythonSupport: init: success
[debug] JythonSupport: ***** Jython sys.path
 0: /Users/shareduser/Library/Application Support/Sikulix/Lib
 1: /Applications/SikuliX.app/Contents/Java/Lib
 2: /Applications/SikuliX.app/Contents/Java/sikulix.jar/Lib
 3: __classpath__
 4: __pyclasspath__/
[debug] JythonSupport: ***** Jython sys.path end
[debug] Jython: sikuli: Sikuli: starting init
[debug] RunTimeIDE: loadLib: libVisionProxy.dylib
[debug] RunTimeIDE: loadLib: libMacUtil.dylib
[debug] Jython: requested to use as default region: S(0)[0,0 1x1]
[debug] Jython: sikuli: Sikuli: ending init
[debug] JythonScriptRunner: running Jython 2.7.1
[debug] ScriptingSupport: initScriptingSupport: added: jython
[debug] ScriptingSupport: initScriptingSupport: exit with defaultrunner: jython (py)
[debug] ImagePath: new BundlePath:
/Users/shareduser/PycharmProjects/RF_Mac_Tests/pages/editor/sikuli/click_safenotes.sikuli/
[debug] Jython: requested to use as default region: S(0)[0,0 1x1]
[debug] JythonScriptRunner: runPython: running script:
/Users/shareduser/PycharmProjects/RF_Mac_Tests/pages/editor/sikuli/click_safenotes.sikuli
[debug] Image: loaded: 1522143552641.png (file:/Users/shareduser/PycharmProjects/RF_Mac_Tests/pages/editor/sikuli/click_safenotes.sikuli/1522143552641.png)
[debug] Image: cached: 1522143552641.png (6 KB) (# 1 KB 6 -- 0 % of 64 MB)
[debug] Region: wait: waiting 3.0 secs for 1522143552641.png to appear in S(0)[0,0 1x1]
[error] script [ /Users/shareduser/PycharmProjects/RF_Mac_Tests/pages/editor/sikuli/click_safenotes.sikuli ] stopped with error in line 1
[error] java.lang.NullPointerException ( java.lang.NullPointerException )
[debug] RunTimeIDE: final cleanup
[debug] FileManager: deleteFileOrFolder:
/var/folders/31/srmmps8x0td7l97qp41d5_dw0000gp/T/Sikulix_839020385

Looks like the problem caused by Jython using default region: S(0)[0,0 1x1] when running via ssh (and when the script is run directly, the default region is correct: S(0)[0,0 1680x1050])

Revision history for this message
Ilya Anshmidt (i.anshmidt) said :
#6

OK, problem solved.

It was caused by me not using AWT_FORCE_HEADFUL env variable for running java application via ssh on Mac.

So when I run sikuli script via ssh with the following command it works correctly:
ssh shareduser@192.168.1.224 'AWT_FORCE_HEADFUL=true java -jar /Applications/SikuliX.app/Contents/Java/sikulix.jar -r /Users/shareduser/<path-to-script>/click_button.sikuli'

Revision history for this message
RaiMan (raimund-hocke) said :
#7

Super, thanks for the solution.

I will add a check for this situation (having a screen (0,0 1x1)) and terminate with an appropriate info.

For this I reopen your bug report.