Hi there,
since upgrading to openhab 3.x I have spotted a weird issue. Some of my rules which are using lambdas randomly fail with null access errors like this:
2021-07-27 19:05:00.253 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'tradfri-45' failed: null in tradfri
I have created some lambdas to reuse common code accross many triggers like this:
val Functions.Function4<GenericItem, OnOffType, Boolean, String, String> execStd = [ item, onOff, autoAwayMode, modeSuffix |
val loggroup = "tradfri.script"
if (item.type.equals("Switch")) {
val modeItemName = item.name + modeSuffix
logDebug(loggroup, "Search for modeItem: '"+ modeItemName + "'.")
val modeItem = gTradfri_Mode.members.filter[dt|dt.name == modeItemName].head as SwitchItem
if(modeItem !== null) {
logDebug(loggroup, "modeItem '"+ modeItem.label + "' found.")
if(modeItem.state == ON || (autoAwayMode && Max_Alarmanlage.state == ON)) {
logDebug(loggroup, "Schedule '"+ item.label + "' Auto - Mode")
item.sendCommand(onOff)
logDebug(loggroup, "Schedule '"+ item.label + "': " + onOff.toString)
} else {
logDebug(loggroup, "Schedule '"+ item.label + "' NOOP - Mode")
}
} else {
logWarn(loggroup, "Mode Item '" + modeItemName + "' could not be found in group 'gTradfri_Mode'")
}
} else {
logDebug(loggroup, "unsupported item type: " + item.type)
}
"done"
]
My triggers are rather simple then:
rule "Lampe Kind Garten Decke Abend ON"
when
Channel 'astro:sun:lampe_kz:set#event' triggered END
then
execStd.apply(TRADFRI_Lampe_Kind_Garten_Decke, ON, true, "_Mode_Abend")
end
My log now looks like this:
2021-07-27 19:05:00.244 [DEBUG] [hab.core.model.script.tradfri.script] - Search for modeItem: 'TRADFRI_Lampe_Kind_Strasse_Mode_Abend'.
2021-07-27 19:05:00.244 [DEBUG] [hab.core.model.script.tradfri.script] - Search for modeItem: 'TRADFRI_Lampe_Kind_Strasse_Decke_Mode_Abend'.
2021-07-27 19:05:00.244 [DEBUG] [hab.core.model.script.tradfri.script] - Search for modeItem: 'TRADFRI_Lampe_Kind_Garten_Decke_Mode_Abend'.
2021-07-27 19:05:00.253 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'tradfri-45' failed: null in tradfri
2021-07-27 19:05:00.266 [DEBUG] [hab.core.model.script.tradfri.script] - modeItem 'Lampe Kind Strasse (Auto Abend)' found.
...
2021-07-27 19:05:00.283 [DEBUG] [hab.core.model.script.tradfri.script] - modeItem 'Lampe Strasse Decke (Auto Abend)' found.
...
I assume that this is a concurrency issue because it always happens when multiple rules execute at the same time as in this example.
The failing statement most like is this one:
val modeItem = gTradfri_Mode.members.filter[dt|dt.name == modeItemName].head as SwitchItem
I do not understand why this can be null?
Maybe someone could help me to understand what I need to fix here. Thanks in advance!