Null error after upgrade

  • Platform information:
    • Hardware: x64/1GB Ram/32GB
    • OS: Ubuntu 16.04
    • Java Runtime Environment: OpenJDK 64-Bit Server VM (build 25.162-b12, mixed mode)
    • openHAB version: openhab2 2.2.0-1
  • Issue of the topic:
    I just moved a bunch of rules to a new openhab instance and some of the rules are not working right. They worked fine on the old instance so i’m assuming there was a change to the run time. I can’t figure out where the problem is however. The old instance was openhab2-offline 2.0.0~20170106124335.

On startup or if I touch the rule file everything works fine but after a little while I start seeing the error below in the logs and the rule stops working.

2018-04-25 22:25:00.012 [ERROR] [ntime.internal.engine.ExecuteRuleJob] - Error during the execution of rule 'Periodically check Kitchen Active Presence': null

I’ve checked all items references in the rule and none of them has a null value so I’m lost to where the problem is.

  • Please post configurations (if applicable):
rule "Periodically check Kitchen Active Presence"
when
    System started or
    Time cron "0 */5 * * * ?"
then
	logDebug("Kitchen", "Presence Check - Starting")
	if(KitchenPresenceOverride.state !== ON){
		logDebug("Kitchen", "Presence Check - Room Override OFF")
		if(!KitchenPresenceSwitch.state.toString.equals("Inactive") || !KitchenPresenceSwitch.state.toString.equals("Standby")){
			logDebug("Kitchen", "Presence Check - Room Active")
			logDebug("Kitchen", "Presence Check - Checking Room Sensors")
			if(KitchenPresenceGroup.members.filter(s | s.state == ON).size == 0) {
                logDebug("Kitchen", "Presence Check - Room Sensors OFF - Checking Persistence")
                if(KitchenPresenceGroup.members.filter(s | s.changedSince(now.minusMinutes((KitchenPresenceTimer.state as DecimalType).intValue))).size == 0){
					logDebug("Kitchen", "Presence Check - Room Sensors INACTIVE")
					logDebug("Kitchen", "Presence Check - Room set to INACTIVE")
                    sendCommand(KitchenPresenceSwitch, ("Inactive"))
				}
			}
		}
	}
end

Can someone please point me in the right direction?

Unfortunately, the Rules DSL throws a null exception for just about everything.

What line in that rule causes the error?

Hi Rich,

You were more help than you probably realize. You got me to stop looking at the rule and look else where instead.

TL:DR - Persistence strategy file was missing.

After your post I looked at the rule file and realized there’s another rule block that is exactly the same as the one I posted with different items (logic is all the same). However this rule was NOT throwing an error. Using rest, I checked those items and found one with a null value. After assigning it a value that rule block started throwing the same error as the one I posted. Even more confused that the null value was fine but an actual value was throwing a null error i started looking at the details to what each line was doing (closer than I was already doing).

The issue was with this line:

if(KitchenPresenceGroup.members.filter(s | s.changedSince(now.minusMinutes((KitchenPresenceTimer.state as DecimalType).intValue))).size == 0)

KitchenPresenceTimer is a numeric value representing minutes, If items in KitchenPresenceGroup has not changed within the set time the condition is true. As I’m analyzing this line i’m realizing that I’m not seeing the log messages for the DB writes when items change. That lead me to look at persistence, and that’s when I noticed I have not been logging item changes. So I guess the null error was that the historic state of KitchenPresenceGroup was unavailable. I copied the persistence file over to the new instance and now the rule is working and the error is gone.

As usual, Rich to the rescue! Thanks!!!

1 Like