Solved: JSR223 Jython script rule loading error in build 1071

Since i’ve updated Openhab2 to the latest build (1071 as of today), i’m getting errors on my Jython rules. Not a single rule is loads. When running the command automationManager.addRule(), the following error is shown:

Error during evaluation of script <script> : TypeError: Default constructor failed for Java superclass org.eclipse.smarthome.automation.module.script.rulesupport.shared.simple.SimpleRule in <script> at line number X

The hello world example works, so my Jython configuration is OK:

28-Oct-2017 21:46:59.780 [INFO ] [ript.rulesupport.internal.loader.ScriptFileWatcher] - Loading script 'zzz_test_hello_world.py'
28-Oct-2017 21:46:59.800 [INFO ] [org.eclipse.smarthome.automation.examples         ] - Hello world!
28-Oct-2017 21:46:59.802 [DEBUG] [ript.rulesupport.internal.loader.ScriptFileWatcher] - Script loaded: zzz_test_hello_world.py

However when i try to load a simple test rule:

scriptExtension.importPreset("RuleSupport")
scriptExtension.importPreset("RuleSimple")

class MyRuleTest(SimpleRule):
    def __init__(self):
        self.triggers = [
             Trigger("MyTrigger", "core.ItemStateUpdateTrigger", 
                    Configuration({ "itemName": "TestString1"}))
        ]     
    def execute(self, module, input):
        events.postUpdate("TestString2", "some data")
automationManager.addRule(MyRuleTest())

An error is shown in the openhab log:

28-Oct-2017 21:59:58.971 [INFO ] [cript.rulesupport.shared.ScriptedAutomationManager] - removeAll added handlers
28-Oct-2017 21:59:58.973 [INFO ] [ript.rulesupport.internal.loader.ScriptFileWatcher] - Loading script 'zzz_rule_standalone_test.py'
28-Oct-2017 21:59:59.056 [ERROR] [ion.module.script.internal.ScriptEngineManagerImpl] - Error during evaluation of script 'file:/opt/openhab2/conf/automation/jsr223/zzz_rule_standalone_test.py': TypeError: Default constructor failed for Java superclass org.eclipse.smarthome.automation.module.script.rulesupport.shared.simple.SimpleRule in <script> at line number 13
28-Oct-2017 21:59:59.057 [DEBUG] [ript.rulesupport.internal.loader.ScriptFileWatcher] - Script loaded: zzz_rule_standalone_test.py

The following rule related bundles are installed:

openhab> bundle:list | grep -i rule
131 │ Active   │  80 │ 0.9.0.201710240931     │ Eclipse SmartHome Rule Model
132 │ Active   │  80 │ 0.9.0.201710240931     │ Eclipse SmartHome Rule Runtime
198 │ Active   │  80 │ 0.9.0.201710240931     │ Eclipse SmartHome Automation Script RuleSupport

Is there anyone else who experiences these issues and have you found a way to fix it?

1 Like

It appears this may be a bug that was recently introduced in the SmartHome code. See…

I’ve added a comment to that pull request and have referenced this forum topic…

1 Like

I facing the same problem with build 1073. Fortunately, the bug is already solved in the Eclipse Smarthome Repository.

However, I do not know how I can pull & compile these changes manually.
Can anyone give me a hint?

Ýes, i hope the changes will be applied to the Openhab nightlies soon. I’ve transferred all my rules to Jython and Openhab is kind of useless without rules.

@Kai, have you got any idea when the fix for the Simplerule implementation will be merged?

It is merged in ESH, but not yet rolled out to openHAB. I plan to do a new ESH stable by the end of this week. I want to also include a Tradfri update, which is rather time critical. Watch the latest news category where I will announce as soon as a new build is available.

1 Like

i can confirm this issue has been resolved with the latest snapshot version. Thanks!

Thanks a lot! The problem is gone and my rules are working properly. But I get this error reported during startup:

[Build #1078]

Circular reference detected trying to get service {org.eclipse.smarthome.automation.handler.ModuleHandlerFactory}={component.name=org.eclipse.smarthome.automation.module.core.factory.basicmodulehandlerfactory, component.id=203, service.id=345, service.bundleid=190, service.scope=bundle}
stack of references: ServiceReference: {org.eclipse.smarthome.automation.handler.ModuleHandlerFactory}={component.name=org.eclipse.smarthome.automation.module.core.factory.basicmodulehandlerfactory, component.id=203, service.id=345, service.bundleid=190, service.scope=bundle}
ServiceReference: {org.eclipse.smarthome.automation.RuleRegistry}={rule.reinitialization.delay=500, component.name=org.eclipse.smarthome.automation.ruleregistry, component.id=213, service.id=344, service.bundleid=189, service.scope=bundle}

as well as this warning:

FrameworkEvent WARNING - org.eclipse.smarthome.automation.module.core
org.osgi.framework.ServiceException: org.apache.felix.scr.impl.manager.SingleComponentManager.getService() 
returned a null service object

Should I be worried?

Maybe at least a little bit :wink:
There are known issues with cyclic dependencies in the new rule engine and I would hope that we can solve them with Fixed circular service reference in automation component by adimova · Pull Request #4468 · eclipse-archived/smarthome · GitHub. Usually, restarting the runtime temporarily solves the issues as a workaround for know.

In build 1143, I can still observe the issue:

Error during evaluation of script ‘file:/etc/openhab2/automation/jsr223/owl.py’: NameError: name ‘SimpleRule’ is not defined in at line number 17

i use the same build, but do not experience this particular error. Are you sure it isn’t something else
causing this error ?