JSR223 groovy rules fail to parse on system start

I have started to convert my rules to groovy. The rule itself works as long as the system is already up and running. But if I restart openHAB, I get

MissingPropertyException: No such property: itemRegistry

When I then touch the script file, it parses correctly. It looks like the scripting engine is not completely initialized when the rule is loaded. Is this a known problem, am I doing something wrong, or should I create an Issue?

Edit: just for reference, here is my rule file:


And this is the error message on startup:

2017-08-25 11:25:44.062 [ERROR] [ipt.internal.ScriptEngineManagerImpl] - Error during evaluation of script ‘file:/etc/openhab2/automation/jsr223/test.groovy’: javax.script.ScriptException: groovy.lang.MissingPropertyException: No such property: itemRegistry for class: Script2


I’d recommend it. I haven’t seen this issue with Jython but it looks like a bundle load ordering issue. I don’t know why it would be specific to Groovy though. If you submit an issue, be sure to include as many details as possible about your installation (versions, install methods, etc.).

Implementation hint:

The itemRegistry scope variable is created in the DefaultScriptScopeProvider component of the org.eclipse.smarthome.automation.module.script.defaultscope bundle.

Thanks for the reply, I have now created an issue.

Edit: if anybody else has the problem, a workaround is to add a normal rule with system startup trigger that then touches the groovy script file.

1 Like