Cannot invoke method public abstract boolean

Hi,
Can someone help me please?
This is my rule, sometimes its working but other times i get this error and the rule not working : cannot invoke method public abstract boolean org.eclipse.smarthome.model.script.actions.Timer.hasTerminated() on null

rule "SleepingRoom Windows Open, Close Thermostat"
when
	Item SleepingRoom_Window changed 
then
	if(SleepingRoom_Window.state==OPEN) {
		if(windopen3===null) {
			windopen3 = createTimer(now.plusSeconds(10), [ |
			sendCommand(maxSetTempSleepingroom, 4.5)
			])
		}
	}		
end

rule "SleepingRoom restore thermostat"
when
	Item SleepingRoom_Window  changed
then
	if (SleepingRoom_Window.state==CLOSED) {
		if (windopen3.hasTerminated) {			//window open for longer than five minutes so thermostat is OFF
			windopen3=null
			sendCommand(maxSetTempSleepingroom, maxSetTempSleepingroom.previousState(true).state.toString )
			logInfo("windows.rules", "previousState(): " + maxSetTempSleepingroom.previousState(true).state.toString + " state: " + maxSetTempSleepingroom.state.toString)  
		}
	}
	if (SleepingRoom_Window.state==CLOSED) {
		if (windopen3 !==null ){						//window open less than five minutes, just cancel and clean up the timer
			windopen3.cancel
			windopen3=null
		}
	}
end

You’ve shown us two rules, but not said which one produces the error message. Help us to help you, we’re quite happy with a copy-paste from your log.

You can get into that code path when your timer handle windopen3 is null.
Like the message says, you can’t check null to see if it has terminated.
You can check for null, as you do elsewhere. I’m not sure what you want to happen in that case though … go on to do those commands or not.

Sorry you have right, i was not so clear.
the error on logfiles its coming from the second rule. when the window is opened for some hours and when i close the window the rule its not working and get this error :2020-03-27 12:06:17.890 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule ‘SleepingRoom restore thermostat’: cannot invoke method public abstract boolean org.eclipse.smarthome.model.script.actions.Timer.hasTerminated() on null
The code is copy paste from other post and a little bit from me, i am not good in programming but i am learning :slight_smile:

Thanks for your respond
Nikos

What happens if you add var Timer window3 = null to the top of your rules?

Here is an example rule of checking the condition of a timer and reset.

var Timer myTimer = null
rule "Motion OFF"
when
    Item Motion changed from OFF
then
    if (myTimer === null) {
        if  (Motion.state == ON) {
            myTimer = createTimer(now.plusSeconds(60), [ |
                if (Motion.state == ON){
                //do stuff
                }
            ])   
        }
    }
end

rule "BACK FROM ON"
when
    Item Motion changed from ON
then
    myTimer.cancel
    myTimer = null
end