Timer exceptions when reloading a rule

I noticed that when updating a rule, I get exceptions because of stale timers (created with createTimer). I unsuccesfully attempted to prevent these exceptions:

  • Make a rule for “System shuts down” and cancel the timer. The rule is not triggered.
  • Adding NULL checks on the items in the rule, since I get a “java.lang.NullPointerException: null” in my log. That also does not work.

The exception is:

2020-10-23 11:48:23.922 [ERROR] [org.quartz.core.JobRunShell         ] - Job DEFAULT.Timer 12 2020-10-23T11:47:53.512+02:00: Proxy for org.eclipse.xtext.xbase.lib.Procedures$Procedure0: [ | {
  org.eclipse.xtext.xbase.impl.XIfExpressionImpl@720d8edc (conditionalExpression: false)
  org.eclipse.xtext.xbase.impl.XIfExpressionImpl@3f5c40eb (conditionalExpression: false)
} ] threw an unhandled Exception: 
java.lang.NullPointerException: null
	at org.eclipse.smarthome.model.script.engine.ScriptError.<init>(ScriptError.java:65) ~[?:?]
	at org.eclipse.smarthome.model.script.interpreter.ScriptInterpreter.invokeFeature(ScriptInterpreter.java:140) ~[?:?]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._doEvaluate(XbaseInterpreter.java:991) ~[?:?]
<etc>
2020-10-23 11:48:23.925 [ERROR] [org.quartz.core.ErrorLogger         ] - Job (DEFAULT.Timer 12 2020-10-23T11:47:53.512+02:00: Proxy for org.eclipse.xtext.xbase.lib.Procedures$Procedure0: [ | {
  org.eclipse.xtext.xbase.impl.XIfExpressionImpl@720d8edc (conditionalExpression: false)
  org.eclipse.xtext.xbase.impl.XIfExpressionImpl@3f5c40eb (conditionalExpression: false)
} ] threw an exception.
org.quartz.SchedulerException: Job threw an unhandled exception.
	at org.quartz.core.JobRunShell.run(JobRunShell.java:213) [bundleFile:?]
	at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573) [bundleFile:?]
Caused by: java.lang.NullPointerException
	at org.eclipse.smarthome.model.script.engine.ScriptError.<init>(ScriptError.java:65) ~[?:?]
	at org.eclipse.smarthome.model.script.interpreter.ScriptInterpreter.invokeFeature(ScriptInterpreter.java:140) ~[?:?]
<etc>

It is just a minor thing, but I would like to keep the log free of these exceptions.
Can it be done? Any suggestions?

I don’t think anything can be done in Rules DSL. In Jython rules you can define a function called scriptUnloaded() which gets called when the script is unloaded. You can cancel the Timers in that function. I don’t know about JSONDB rules or the other supported languages.

1 Like

Thanks. At least, I now know it cannot be done. Perhaps time to move to Jython.

I recommend Jython for now, but Kotlin is very interesting too. However, the scriptLoaded and scriptUnloaded functions are available through scripted automation. Meaning, this is not specific to Jython and they are available in all supported scripting languages.