Okay, its weird but it started working. On its own. I dont know how. The only thing i did was (1) update by raspberry pi OS and (2) link the rule to trigger from an item instead of directly triggering from UI. And now it executs every time; even if i create a new scipt from UI.
Initially I thought it could be related to these (the JSR223 scripts still suffer from this) -
opened 06:51PM - 24 Oct 18 UTC
bug
Automation
EDIT: At first I thought this was recently introduced, but it was not. Steps to … reproduce [in this post](https://community.openhab.org/t/using-javascript-actions-in-paper-ui-created-rules/54580/5?u=5iver). The same occurs when using the REST API `/rules/{ruleUID}/runnow` (which is what Paper UI is sending).
> Try modifying the rule, doesn’t matter what you change… could be the name. Save the rule and DON"T execute from Paper UI. Trigger the rule though the Item. I use smarthome:send Test_Switch_1 ON from Karaf. No exception. Then try triggering the rule through Paper UI. No exception.
>
> To reproduce the exception, modify/save the rule, then execute through Paper UI. Exception. Trigger through Item. Exception.
>
> Seems the first trigger must not be through Paper UI, or you will get the exception. Once triggered from something other than Paper UI, you can then trigger through Paper UI. AND I have only seen the exception if the Rule Action contains Javascript with a Core Action.
If everything in the Action is commented out but the LoggerFactory import and the log statement, the exception does not occur. There looks to be an issue in the [getContext](https://github.com/eclipse/smarthome/blob/master/bundles/automation/org.eclipse.smarthome.automation.core/src/main/java/org/eclipse/smarthome/automation/core/internal/RuleEngineImpl.java#L1114) when the rule has not already been triggered by an event. Here is the JS Action:
```
'use strict';
var log = Java.type("org.slf4j.LoggerFactory").getLogger("org.eclipse.smarthome.model.script.Rules");
var Exec = Java.type("org.eclipse.smarthome.model.script.actions.Exec");
var test = Exec.executeCommandLine("echo hello world", 5000);
log.info("JSR223: JS: Test executeCommandLine [" + test + "]");
```
```
Rule saved in Paper UI:
2018-10-25 00:16:32.611 [TRACE] [ation.core.internal.RuleEventFactory] - creating ruleEvent of type: RuleUpdatedEvent
2018-10-25 00:16:32.612 [DEBUG] [pse.smarthome.automation.module.core] - ServiceEvent UNREGISTERING - {org.eclipse.smarthome.core.events.EventSubscriber}={service.id=445, service.bundleid=235, service.scope=singleton, event.topics=smarthome/items/Test_Switch_1/command} - org.eclipse.smarthome.automation.module.core
2018-10-25 00:16:32.614 [TRACE] [ation.core.internal.RuleEventFactory] - creating ruleEvent of type: RuleStatusInfoEvent
2018-10-25 00:16:32.614 [TRACE] [l.factory.ScriptModuleHandlerFactory] - create 2 -> script.ScriptAction
2018-10-25 00:16:32.615 [TRACE] [ore.factory.CoreModuleHandlerFactory] - create 1 -> core.ItemCommandTrigger : cd1cce1b-f559-48ef-a955-210d019586ad
2018-10-25 00:16:32.616 [DEBUG] [pse.smarthome.automation.module.core] - ServiceEvent REGISTERED - {org.eclipse.smarthome.core.events.EventSubscriber}={service.id=446, service.bundleid=235, service.scope=singleton, event.topics=smarthome/items/Test_Switch_1/command} - org.eclipse.smarthome.automation.module.core
2018-10-25 00:16:32.617 [TRACE] [ation.core.internal.RuleEventFactory] - creating ruleEvent of type: RuleStatusInfoEvent
Rule triggered through Item (successful):
2018-10-25 00:16:49.075 [TRACE] [re.handler.ItemCommandTriggerHandler] - ->FILTER: smarthome/items/Test_Switch_1/command:Test_Switch_1
2018-10-25 00:16:49.076 [TRACE] [re.handler.ItemCommandTriggerHandler] - Received Event: Source: null Topic: smarthome/items/Test_Switch_1/command Type: ItemCommandEvent Payload: {"type":"OnOff","value":"ON"}
2018-10-25 00:16:49.078 [DEBUG] [omation.core.internal.RuleEngineImpl] - The trigger '1' of rule 'cd1cce1b-f559-48ef-a955-210d019586ad' is triggered.
2018-10-25 00:16:49.079 [TRACE] [ation.core.internal.RuleEventFactory] - creating ruleEvent of type: RuleStatusInfoEvent
2018-10-25 00:16:49.153 [INFO ] [eclipse.smarthome.model.script.Rules] - JSR223: JS: Test executeCommandLine [hello world]
2018-10-25 00:16:49.153 [DEBUG] [omation.core.internal.RuleEngineImpl] - The rule 'cd1cce1b-f559-48ef-a955-210d019586ad' is executed.
2018-10-25 00:16:49.154 [TRACE] [ation.core.internal.RuleEventFactory] - creating ruleEvent of type: RuleStatusInfoEvent
Rule triggered through Paper UI (successful):
2018-10-25 00:17:02.827 [TRACE] [ation.core.internal.RuleEventFactory] - creating ruleEvent of type: RuleStatusInfoEvent
2018-10-25 00:17:02.880 [INFO ] [eclipse.smarthome.model.script.Rules] - JSR223: JS: Test executeCommandLine [hello world]
2018-10-25 00:17:02.881 [DEBUG] [omation.core.internal.RuleEngineImpl] - The rule 'cd1cce1b-f559-48ef-a955-210d019586ad' is executed.
2018-10-25 00:17:02.882 [TRACE] [ation.core.internal.RuleEventFactory] - creating ruleEvent of type: RuleStatusInfoEvent
Rule name changed and saved through Paper UI:
2018-10-25 00:18:10.884 [TRACE] [ation.core.internal.RuleEventFactory] - creating ruleEvent of type: RuleUpdatedEvent
2018-10-25 00:18:10.885 [DEBUG] [pse.smarthome.automation.module.core] - ServiceEvent UNREGISTERING - {org.eclipse.smarthome.core.events.EventSubscriber}={service.id=446, service.bundleid=235, service.scope=singleton, event.topics=smarthome/items/Test_Switch_1/command} - org.eclipse.smarthome.automation.module.core
2018-10-25 00:18:10.887 [TRACE] [l.factory.ScriptModuleHandlerFactory] - create 2 -> script.ScriptAction
2018-10-25 00:18:10.887 [TRACE] [ore.factory.CoreModuleHandlerFactory] - create 1 -> core.ItemCommandTrigger : cd1cce1b-f559-48ef-a955-210d019586ad
2018-10-25 00:18:10.889 [DEBUG] [pse.smarthome.automation.module.core] - ServiceEvent REGISTERED - {org.eclipse.smarthome.core.events.EventSubscriber}={service.id=447, service.bundleid=235, service.scope=singleton, event.topics=smarthome/items/Test_Switch_1/command} - org.eclipse.smarthome.automation.module.core
2018-10-25 00:18:10.891 [TRACE] [ation.core.internal.RuleEventFactory] - creating ruleEvent of type: RuleStatusInfoEvent
2018-10-25 00:18:10.892 [TRACE] [ation.core.internal.RuleEventFactory] - creating ruleEvent of type: RuleStatusInfoEvent
Rule triggered through Paper UI (exception):
2018-10-25 00:18:20.020 [TRACE] [ation.core.internal.RuleEventFactory] - creating ruleEvent of type: RuleStatusInfoEvent
2018-10-25 00:18:20.040 [WARN ] [omation.core.internal.RuleEngineImpl] - Fail to execute action: 2
java.lang.RuntimeException: java.lang.ClassNotFoundException: org.eclipse.smarthome.model.script.actions.Exec cannot be found by com.eclipsesource.jaxrs.publisher_5.3.1.201602281253
at jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:397) ~[?:?]
at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:449) ~[?:?]
at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:406) ~[?:?]
at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:402) ~[?:?]
at jdk.nashorn.api.scripting.NashornScriptEngine.eval(NashornScriptEngine.java:155) ~[?:?]
at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:264) ~[?:?]
at org.eclipse.smarthome.automation.module.script.internal.handler.ScriptActionHandler.lambda$0(ScriptActionHandler.java:60) ~[?:?]
at java.util.Optional.ifPresent(Optional.java:159) ~[?:?]
at org.eclipse.smarthome.automation.module.script.internal.handler.ScriptActionHandler.execute(ScriptActionHandler.java:57) ~[?:?]
at org.eclipse.smarthome.automation.core.internal.RuleEngineImpl.executeActions(RuleEngineImpl.java:1198) [234:org.eclipse.smarthome.automation.core:0.10.0.201810180807]
at org.eclipse.smarthome.automation.core.internal.RuleEngineImpl.runNow(RuleEngineImpl.java:1055) [234:org.eclipse.smarthome.automation.core:0.10.0.201810180807]
at org.eclipse.smarthome.automation.core.internal.RuleEngineImpl.runNow(RuleEngineImpl.java:1071) [234:org.eclipse.smarthome.automation.core:0.10.0.201810180807]
at org.eclipse.smarthome.automation.rest.internal.RuleResource.runNow(RuleResource.java:288) [243:org.eclipse.smarthome.automation.rest:0.10.0.201810180807]
at sun.reflect.GeneratedMethodAccessor32.invoke(Unknown Source) ~[?:?]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
at java.lang.reflect.Method.invoke(Method.java:498) ~[?:?]
at org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory$1.invoke(ResourceMethodInvocationHandlerFactory.java:81) [171:org.glassfish.jersey.core.jersey-server:2.22.2]
at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher$1.run(AbstractJavaResourceMethodDispatcher.java:144) [171:org.glassfish.jersey.core.jersey-server:2.22.2]
at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:161) [171:org.glassfish.jersey.core.jersey-server:2.22.2]
at org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$ResponseOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:160) [171:org.glassfish.jersey.core.jersey-server:2.22.2]
at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:99) [171:org.glassfish.jersey.core.jersey-server:2.22.2]
at org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:389) [171:org.glassfish.jersey.core.jersey-server:2.22.2]
at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:347) [171:org.glassfish.jersey.core.jersey-server:2.22.2]
at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:102) [171:org.glassfish.jersey.core.jersey-server:2.22.2]
at org.glassfish.jersey.server.ServerRuntime$2.run(ServerRuntime.java:326) [171:org.glassfish.jersey.core.jersey-server:2.22.2]
at org.glassfish.jersey.internal.Errors$1.call(Errors.java:271) [170:org.glassfish.jersey.core.jersey-common:2.22.2]
at org.glassfish.jersey.internal.Errors$1.call(Errors.java:267) [170:org.glassfish.jersey.core.jersey-common:2.22.2]
at org.glassfish.jersey.internal.Errors.process(Errors.java:315) [170:org.glassfish.jersey.core.jersey-common:2.22.2]
at org.glassfish.jersey.internal.Errors.process(Errors.java:297) [170:org.glassfish.jersey.core.jersey-common:2.22.2]
at org.glassfish.jersey.internal.Errors.process(Errors.java:267) [170:org.glassfish.jersey.core.jersey-common:2.22.2]
at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:317) [170:org.glassfish.jersey.core.jersey-common:2.22.2]
at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:305) [171:org.glassfish.jersey.core.jersey-server:2.22.2]
at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:1154) [171:org.glassfish.jersey.core.jersey-server:2.22.2]
at org.glassfish.jersey.servlet.WebComponent.serviceImpl(WebComponent.java:473) [168:org.glassfish.jersey.containers.jersey-container-servlet-core:2.22.2]
at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:427) [168:org.glassfish.jersey.containers.jersey-container-servlet-core:2.22.2]
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:388) [168:org.glassfish.jersey.containers.jersey-container-servlet-core:2.22.2]
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:341) [168:org.glassfish.jersey.containers.jersey-container-servlet-core:2.22.2]
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:228) [168:org.glassfish.jersey.containers.jersey-container-servlet-core:2.22.2]
at com.eclipsesource.jaxrs.publisher.internal.ServletContainerBridge.service(ServletContainerBridge.java:76) [20:com.eclipsesource.jaxrs.publisher:5.3.1.201602281253]
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:865) [85:org.eclipse.jetty.servlet:9.4.11.v20180605]
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:535) [85:org.eclipse.jetty.servlet:9.4.11.v20180605]
at org.ops4j.pax.web.service.jetty.internal.HttpServiceServletHandler.doHandle(HttpServiceServletHandler.java:71) [185:org.ops4j.pax.web.pax-web-jetty:7.2.3]
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:146) [84:org.eclipse.jetty.server:9.4.11.v20180605]
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:548) [82:org.eclipse.jetty.security:9.4.11.v20180605]
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132) [84:org.eclipse.jetty.server:9.4.11.v20180605]
at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:257) [84:org.eclipse.jetty.server:9.4.11.v20180605]
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1595) [84:org.eclipse.jetty.server:9.4.11.v20180605]
at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:255) [84:org.eclipse.jetty.server:9.4.11.v20180605]
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1317) [84:org.eclipse.jetty.server:9.4.11.v20180605]
at org.ops4j.pax.web.service.jetty.internal.HttpServiceContext.doHandle(HttpServiceContext.java:293) [185:org.ops4j.pax.web.pax-web-jetty:7.2.3]
at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:203) [84:org.eclipse.jetty.server:9.4.11.v20180605]
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:473) [85:org.eclipse.jetty.servlet:9.4.11.v20180605]
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1564) [84:org.eclipse.jetty.server:9.4.11.v20180605]
at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:201) [84:org.eclipse.jetty.server:9.4.11.v20180605]
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1219) [84:org.eclipse.jetty.server:9.4.11.v20180605]
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:144) [84:org.eclipse.jetty.server:9.4.11.v20180605]
at org.ops4j.pax.web.service.jetty.internal.JettyServerHandlerCollection.handle(JettyServerHandlerCollection.java:80) [185:org.ops4j.pax.web.pax-web-jetty:7.2.3]
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132) [84:org.eclipse.jetty.server:9.4.11.v20180605]
at org.eclipse.jetty.server.Server.handle(Server.java:531) [84:org.eclipse.jetty.server:9.4.11.v20180605]
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:352) [84:org.eclipse.jetty.server:9.4.11.v20180605]
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:260) [84:org.eclipse.jetty.server:9.4.11.v20180605]
at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:281) [75:org.eclipse.jetty.io:9.4.11.v20180605]
at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:102) [75:org.eclipse.jetty.io:9.4.11.v20180605]
at org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:118) [75:org.eclipse.jetty.io:9.4.11.v20180605]
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.runTask(EatWhatYouKill.java:333) [87:org.eclipse.jetty.util:9.4.11.v20180605]
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:310) [87:org.eclipse.jetty.util:9.4.11.v20180605]
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.tryProduce(EatWhatYouKill.java:168) [87:org.eclipse.jetty.util:9.4.11.v20180605]
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.run(EatWhatYouKill.java:126) [87:org.eclipse.jetty.util:9.4.11.v20180605]
at org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:366) [87:org.eclipse.jetty.util:9.4.11.v20180605]
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:762) [87:org.eclipse.jetty.util:9.4.11.v20180605]
at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:680) [87:org.eclipse.jetty.util:9.4.11.v20180605]
at java.lang.Thread.run(Thread.java:748) [?:?]
Caused by: java.lang.ClassNotFoundException: org.eclipse.smarthome.model.script.actions.Exec cannot be found by com.eclipsesource.jaxrs.publisher_5.3.1.201602281253
at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:484) ~[?:?]
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:395) ~[?:?]
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:387) ~[?:?]
at org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:150) ~[?:?]
at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[?:?]
at org.eclipse.osgi.internal.framework.EquinoxBundle.loadClass(EquinoxBundle.java:564) ~[?:?]
at org.ops4j.pax.swissbox.core.BundleClassLoader.findClass(BundleClassLoader.java:176) ~[185:org.ops4j.pax.web.pax-web-jetty:7.2.3]
at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[?:?]
at org.ops4j.pax.swissbox.core.BundleClassLoader.loadClass(BundleClassLoader.java:192) ~[185:org.ops4j.pax.web.pax-web-jetty:7.2.3]
at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[?:?]
at java.lang.Class.forName0(Native Method) ~[?:?]
at java.lang.Class.forName(Class.java:348) ~[?:?]
at jdk.nashorn.internal.runtime.Context.findClass(Context.java:1051) ~[?:?]
at jdk.nashorn.internal.objects.NativeJava.simpleType(NativeJava.java:498) ~[?:?]
at jdk.nashorn.internal.objects.NativeJava.type(NativeJava.java:322) ~[?:?]
at jdk.nashorn.internal.objects.NativeJava.type(NativeJava.java:314) ~[?:?]
at jdk.nashorn.internal.objects.NativeJava.type(NativeJava.java:310) ~[?:?]
at jdk.nashorn.internal.scripts.Script$68$\^eval\_.:program(<eval>:3) ~[?:?]
at jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:637) ~[?:?]
at jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:494) ~[?:?]
at jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:393) ~[?:?]
... 71 more
2018-10-25 00:18:20.043 [DEBUG] [omation.core.internal.RuleEngineImpl] - The rule 'cd1cce1b-f559-48ef-a955-210d019586ad' is executed.
2018-10-25 00:18:20.043 [TRACE] [ation.core.internal.RuleEventFactory] - creating ruleEvent of type: RuleStatusInfoEvent
```
A couple issues here then.
Where is/should this documented? Right now to indicate that the ERE rules and JSR223 Rules are the same. They are created differently (ERE uses PaperUI, JSR223 uses text files), stored differently (ERE Rules are stored in the JSONDB), and neither docs (unless I missed it) reference the other. As far as most users will be concerned, the PaperUI UI IS the ERE. As far as I was concerned, the JSON that gets saved to JSONDB for each Rule is the ERE (or at least the code…
But I just cant reproduce the issue now. Rule DSL scripts created from the UI are executing fine. I restarted the OS, re-created rules, wrote a new script etc., but it just seems to be working fine now. @ysc please check the behaviour at your end too. Maybe by creating a new Rule DSL from UI, triggering it from an item and then triggering again from UI.
1 Like