Cannot invoke method on null after upgrade

Hi.
I upgraded today from snapshot 1073 to 1104 and after that some things that worked before in rules don’t work any more.

I’ll start with pasting the entire rule:

import java.text.SimpleDateFormat
import java.util.Random

val SimpleDateFormat sdf = new SimpleDateFormat("HH:mm")

var String update_verandan = "länge"
var String update_uteplatsen = "länge"

val Random rand = new Random()

rule "Temp verandan changed"
when
	Item Utetemp_verandan changed
then
	if(Utetemp_verandan.state == NULL) {
		smstext.sendCommand("+46<replaced> Har inte fått något värde ifrån sensorn på verandan sedan " + update_verandan + "!")
	} else if(Utetemp_uteplatsen.state == NULL || Utetemp_verandan.state < Utetemp_uteplatsen.state) {
		Utetemperatur.postUpdate(Utetemp_verandan.state)
		update_verandan = sdf.format(now.millis)
	}
end

rule "Temp uteplatsen changed"
when
	Item Utetemp_uteplatsen changed
then
	if(Utetemp_uteplatsen.state == NULL) {
		smstext.sendCommand("+<replaced> Har inte fått något värde ifrån sensorn på uteplatsen sedan " + update_uteplatsen + "!")
	} else if(Utetemp_verandan.state == NULL || Utetemp_uteplatsen.state < Utetemp_verandan.state) {
		Utetemperatur.postUpdate(Utetemp_uteplatsen.state)
		update_uteplatsen = sdf.format(now.millis)
	}
end

rule "Utetemperatur changed"
when
	Item Utetemperatur changed or
    Time cron "0 5/20 * * * ? *"
then
	var float slumptemp = (Utetemperatur.state as DecimalType).doubleValue + rand.nextFloat()*0.04
	sendHttpGetRequest("http://www.temperatur.nu/rapportera.php?hash=<replaced>&t=" + slumptemp)
	logDebug("temprule", "Sending " + slumptemp + " to temperatur.nu") 
end

The point is when one of my sensors hasn’t been changed in a specific time (set to null by Expire) I’ll get a sms telling me the last time it was updated, so the string “update verandan” should contain a string representation of the last update time. The point with the rand stuff is that temperatur.nu (which I’m sending my readings to) things something is broken if my temperature doesn’t change in a long time, so I’m inventing decimals to send them so they’ll be happy :slight_smile:

Anyway, after reloading the rule now I get these errors:

2017-12-02 10:34:13.836 [WARN ] [me.internal.engine.RuleContextHelper] - Variable 'sdf' on rule file 'temp.rules' cannot be initialized with value 'org.eclipse.xtext.xbase.impl.XConstructorCallImplCustom@41d79c (invalidFeatureIssueCode: null, validFeature: false, explicitConstructorCall: true, anonymousClassConstructorCall: false)': An error occurred during the script execution: null
2017-12-02 10:34:13.862 [WARN ] [me.internal.engine.RuleContextHelper] - Variable 'rand' on rule file 'temp.rules' cannot be initialized with value 'org.eclipse.xtext.xbase.impl.XConstructorCallImplCustom@1dfe6af (invalidFeatureIssueCode: null, validFeature: false, explicitConstructorCall: true, anonymousClassConstructorCall: false)': An error occurred during the script execution: null
2017-12-02 10:34:20.503 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Utetemperatur changed': cannot invoke method public float java.util.Random.nextFloat() on null
2017-12-02 10:34:20.500 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Temp verandan changed': cannot invoke method public final java.lang.String java.text.Format.format(java.lang.Object) on null

and when the temperature changes I get this:

10:41:28.263 [INFO ] [smarthome.event.ItemStateChangedEvent] - Utetemp_verandan changed from -0.3 to -0.2
10:41:28.295 [ERROR] [untime.internal.engine.RuleEngineImpl] - Rule 'Temp verandan changed': cannot invoke method public final java.lang.String java.text.Format.format(java.lang.Object) on null

Anyone knows what’s going on? Something with my imports going wrong? The random stuff works, it’s sending the values to temperatur.nu right as it should, but the SimpleDateFormat thing doesn’t work at all, the string is never set.

Did you ever solve your problems with “invalidFeatureIssueCode” when initialising variables?

I’m running 2.2 stable and after I deleted the tmp and cache directories in a desperate attempt to solve another issue I’m now starting to see this issue on startup.

I can’t really remember what I finally did about this problem, but it seems to have disappeared. Can’t find any more instances of that warning in the log after 2017-12-02. But looking in that specific rules file, it is identical to the one I posted above so it doesn’t look like it was really an error in the rules. I’m also on 2.2 stable now.

Guess that doesn’t really help you :frowning: