After 2.5.2-1 upgrade, start getting "cannot invoke method public abstract ... on null" errors for rule

If I downgrade to 2.5.1-2 ( sudo apt-get install openhab2=2.5.1-2 ) , it works fine again.

Here’s the error:

2020-02-21 20:38:00.207 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Lock: Update lock states after alarm_raw event': cannot invoke method public abstract java.lang.String org.eclipse.smarthome.core.items.Item.getName() on null

I’m using a common config for Yale-type locks for mapping JSON data

rule "Lock: Update lock states after alarm_raw event"
when
    Item Lock_SideGarage_Alarm_Raw changed
then
    val actionItem = gLock.members.findFirst[ item | item.name.toString == triggeringItem.name.toString.replace("_Alarm_Raw","") ]
    
    logInfo("Rules", "Lock: Alarm events: {}=[{}]",actionItem.name,triggeringItem.state.toString)

            switch (transform("JSONPATH", "$.type", triggeringItem.state.toString)) {
                case "0" : {
		    // do nothing
                }
                case "21" : {
                    actionItem.postUpdate(ON)
                    vGR_MA_Lock.postUpdate(ON)
                    logInfo("Rules", "Case 21 executed")
                }
                case "24" : {
                    actionItem.postUpdate(ON)
                    vGR_MA_Lock.postUpdate(ON)
                    logInfo("Rules", "Case 24 executed")
                }
    ....
    <snip>

I feel like the error is one of these three lines:
val actionItem = gLock.members.findFirst[ item | item.name.toString ==
triggeringItem.name.toString.replace("_Alarm_Raw","") ]
logInfo("Rules", "Lock: Alarm events: {}=[{}]",actionItem.name,triggeringItem.state.toString)

but I’m not sure what to do, since it works fine in 2.5.1-2 but only breaks when I upgrade to 2.5.2-1 and quite frankly I’m not sure how to debug that :frowning: or where to even start.

Seems like quite a few people are using this rule, so I figured I would post this since others will likely run into the same issue.

Hope someone can provide some pointers!

First I would stop OH and clean the cache. Next try touching the rule file and any items that are associated with it and see if that makes a difference.

If your search of gLock members comes up empty handed, then actionItem will be null and the following logInfo(), which tries to get its name, will fail.

There are reports that Items can be missed or late creation at load time - the cache clean exercise may help here.

I also have to restart a second time after clearing the cache, or Items are not available and I get similar errors. An issue was reported here…

1 Like

Strange… I ended up downgrading again but had issues with mail and upgraded to 2.5.3 and then got the same error.

When I commented out all my logInfo() items, I didn’t get that specific error any longer. I then got another error that:

The name ‘vGR_MA_Lock’ cannot be resolved to an item or type

I touched the items file that contains the virtual group (touch /etc/openhab2/items/lock.item) and then that error went away.

Seems strange that I would have to do something like that though.

Upgrading clears the cache, so restart a second time.

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.