Skip to content

javax.script.ScriptException: Could not cast DateTimeType #5323

@weymann

Description

@weymann

I'm on OH5.1.1 raspi system with rrd4j as default persistence.

Following rule is drawing my attention, Test_DateTime is a standalone DateTime item not connected to any channel.

rule "Date Time Test"
when
  Time cron "0,15,30,45 * * ? * *"  
then
    logInfo("DateTime Test", "####")
    if(Test_DateTime.state == NULL) {
      Test_DateTime.postUpdate(new DateTimeType())
    }
    // any logging here and the error will not occur (at least on my machine)
    val dateTime = (Test_DateTime.state as DateTimeType).getZonedDateTime(ZoneId.systemDefault())
    // set to NULL for the next cycle
    Test_DateTime.postUpdate(NULL)
end 

First:
I know the postUpdate is performed ansynchronous.
Sometimes it works, sometime not and I don't wonder to receive these errors Could not cast NULL

15:47:00.548 [ERROR] [l.handler.AbstractScriptModuleHandler] - Script execution of rule with UID 'datetime-1' failed: Could not cast NULL to org.openhab.core.library.types.DateTimeType; line 49, column 21, length 35 in datetime
javax.script.ScriptException: Could not cast NULL to org.openhab.core.library.types.DateTimeType; line 49, column 21, length 35 in datetime

But sometimes I receive this
Could not cast 2026-02-02T15:47:30.400405676+0100 to org.openhab.core.library.types.DateTimeType;

15:47:30.395 [INFO ] [enhab.core.model.script.DateTime Test] - ####
15:47:30.403 [ERROR] [l.handler.AbstractScriptModuleHandler] - Script execution of rule with UID 'datetime-1' failed: Could not cast 2026-02-02T15:47:30.400405676+0100 to org.openhab.core.library.types.DateTimeType; line 49, column 21, length 35 in datetime
javax.script.ScriptException: Could not cast 2026-02-02T15:47:30.400405676+0100 to org.openhab.core.library.types.DateTimeType; line 49, column 21, length 35 in datetime
        at org.openhab.core.model.script.runtime.internal.engine.DSLScriptEngine.eval(DSLScriptEngine.java:146) ~[?:?]
        at org.openhab.core.automation.module.script.internal.handler.AbstractScriptModuleHandler.eval(AbstractScriptModuleHandler.java:265) ~[?:?]
        at org.openhab.core.automation.module.script.internal.handler.ScriptActionHandler.lambda$0(ScriptActionHandler.java:99) ~[?:?]
        at java.util.Optional.ifPresent(Unknown Source) ~[?:?]
        at org.openhab.core.automation.module.script.internal.handler.ScriptActionHandler.execute(ScriptActionHandler.java:86) ~[?:?]
        at org.openhab.core.automation.internal.RuleEngineImpl.executeActions(RuleEngineImpl.java:1322) ~[?:?]
        at org.openhab.core.automation.internal.RuleEngineImpl.runRule(RuleEngineImpl.java:1078) ~[?:?]
        at org.openhab.core.automation.internal.TriggerHandlerCallbackImpl$TriggerData.run(TriggerHandlerCallbackImpl.java:86) ~[?:?]
        at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) ~[?:?]
        at java.util.concurrent.FutureTask.run(Unknown Source) ~[?:?]
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source) ~[?:?]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) ~[?:?]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) ~[?:?]
        at java.lang.Thread.run(Unknown Source) [?:?]

This looks now like a valid DateTimeType but cast fails which I cannot explain.

Maybe concurrent acces to item state while updating?
But this would worry me because this can then happen all the time in rules accessing states or am I wrong?

PS: I know this rule is really stupid but the error shouldn't happen.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugAn unexpected problem or unintended behavior of the Core

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions